mock_redis 0.19.0 → 0.44.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +161 -0
- data/LICENSE.md +21 -0
- data/README.md +41 -17
- data/lib/mock_redis/connection_method.rb +13 -0
- data/lib/mock_redis/database.rb +116 -41
- data/lib/mock_redis/expire_wrapper.rb +1 -1
- data/lib/mock_redis/future.rb +1 -1
- data/lib/mock_redis/geospatial_methods.rb +13 -21
- data/lib/mock_redis/hash_methods.rb +34 -15
- data/lib/mock_redis/indifferent_hash.rb +0 -8
- data/lib/mock_redis/info_method.rb +2 -2
- data/lib/mock_redis/list_methods.rb +39 -4
- data/lib/mock_redis/memory_method.rb +11 -0
- data/lib/mock_redis/multi_db_wrapper.rb +4 -4
- data/lib/mock_redis/pipelined_wrapper.rb +32 -15
- data/lib/mock_redis/set_methods.rb +34 -6
- data/lib/mock_redis/stream/id.rb +58 -0
- data/lib/mock_redis/stream.rb +88 -0
- data/lib/mock_redis/stream_methods.rb +102 -0
- data/lib/mock_redis/string_methods.rb +81 -30
- data/lib/mock_redis/transaction_wrapper.rb +32 -21
- data/lib/mock_redis/utility_methods.rb +9 -4
- data/lib/mock_redis/version.rb +1 -1
- data/lib/mock_redis/zset.rb +5 -8
- data/lib/mock_redis/zset_methods.rb +64 -12
- data/lib/mock_redis.rb +38 -10
- metadata +40 -336
- data/.gitignore +0 -5
- data/.mailmap +0 -2
- data/.overcommit.yml +0 -21
- data/.rspec +0 -1
- data/.rubocop.yml +0 -121
- data/.rubocop_todo.yml +0 -35
- data/.simplecov +0 -4
- data/.travis.yml +0 -33
- data/Gemfile +0 -12
- data/LICENSE +0 -19
- data/Rakefile +0 -2
- data/mock_redis.gemspec +0 -30
- data/spec/client_spec.rb +0 -17
- data/spec/cloning_spec.rb +0 -95
- data/spec/commands/append_spec.rb +0 -24
- data/spec/commands/auth_spec.rb +0 -7
- data/spec/commands/bgrewriteaof_spec.rb +0 -7
- data/spec/commands/bgsave_spec.rb +0 -7
- data/spec/commands/bitcount_spec.rb +0 -25
- data/spec/commands/bitfield_spec.rb +0 -169
- data/spec/commands/blpop_spec.rb +0 -59
- data/spec/commands/brpop_spec.rb +0 -58
- data/spec/commands/brpoplpush_spec.rb +0 -52
- data/spec/commands/connected_spec.rb +0 -7
- data/spec/commands/dbsize_spec.rb +0 -18
- data/spec/commands/decr_spec.rb +0 -34
- data/spec/commands/decrby_spec.rb +0 -34
- data/spec/commands/del_spec.rb +0 -35
- data/spec/commands/disconnect_spec.rb +0 -7
- data/spec/commands/echo_spec.rb +0 -11
- data/spec/commands/eval_spec.rb +0 -7
- data/spec/commands/evalsha_spec.rb +0 -10
- data/spec/commands/exists_spec.rb +0 -14
- data/spec/commands/expire_spec.rb +0 -111
- data/spec/commands/expireat_spec.rb +0 -47
- data/spec/commands/flushall_spec.rb +0 -38
- data/spec/commands/flushdb_spec.rb +0 -38
- data/spec/commands/future_spec.rb +0 -20
- data/spec/commands/geoadd_spec.rb +0 -58
- data/spec/commands/geodist_spec.rb +0 -114
- data/spec/commands/geohash_spec.rb +0 -52
- data/spec/commands/geopos_spec.rb +0 -55
- data/spec/commands/get_spec.rb +0 -30
- data/spec/commands/getbit_spec.rb +0 -34
- data/spec/commands/getrange_spec.rb +0 -22
- data/spec/commands/getset_spec.rb +0 -23
- data/spec/commands/hash_operator_spec.rb +0 -21
- data/spec/commands/hdel_spec.rb +0 -54
- data/spec/commands/hexists_spec.rb +0 -27
- data/spec/commands/hget_spec.rb +0 -28
- data/spec/commands/hgetall_spec.rb +0 -32
- data/spec/commands/hincrby_spec.rb +0 -58
- data/spec/commands/hincrbyfloat_spec.rb +0 -58
- data/spec/commands/hkeys_spec.rb +0 -19
- data/spec/commands/hlen_spec.rb +0 -19
- data/spec/commands/hmget_spec.rb +0 -40
- data/spec/commands/hmset_spec.rb +0 -43
- data/spec/commands/hscan_each_spec.rb +0 -48
- data/spec/commands/hscan_spec.rb +0 -27
- data/spec/commands/hset_spec.rb +0 -38
- data/spec/commands/hsetnx_spec.rb +0 -44
- data/spec/commands/hvals_spec.rb +0 -19
- data/spec/commands/incr_spec.rb +0 -34
- data/spec/commands/incrby_spec.rb +0 -44
- data/spec/commands/incrbyfloat_spec.rb +0 -44
- data/spec/commands/info_spec.rb +0 -62
- data/spec/commands/keys_spec.rb +0 -122
- data/spec/commands/lastsave_spec.rb +0 -8
- data/spec/commands/lindex_spec.rb +0 -49
- data/spec/commands/linsert_spec.rb +0 -68
- data/spec/commands/llen_spec.rb +0 -16
- data/spec/commands/lpop_spec.rb +0 -34
- data/spec/commands/lpush_spec.rb +0 -43
- data/spec/commands/lpushx_spec.rb +0 -46
- data/spec/commands/lrange_spec.rb +0 -51
- data/spec/commands/lrem_spec.rb +0 -80
- data/spec/commands/lset_spec.rb +0 -43
- data/spec/commands/ltrim_spec.rb +0 -45
- data/spec/commands/mapped_hmget_spec.rb +0 -29
- data/spec/commands/mapped_hmset_spec.rb +0 -47
- data/spec/commands/mapped_mget_spec.rb +0 -22
- data/spec/commands/mapped_mset_spec.rb +0 -19
- data/spec/commands/mapped_msetnx_spec.rb +0 -26
- data/spec/commands/mget_spec.rb +0 -34
- data/spec/commands/move_spec.rb +0 -147
- data/spec/commands/mset_spec.rb +0 -29
- data/spec/commands/msetnx_spec.rb +0 -40
- data/spec/commands/persist_spec.rb +0 -48
- data/spec/commands/pexpire_spec.rb +0 -86
- data/spec/commands/pexpireat_spec.rb +0 -48
- data/spec/commands/ping_spec.rb +0 -7
- data/spec/commands/pipelined_spec.rb +0 -42
- data/spec/commands/pttl_spec.rb +0 -41
- data/spec/commands/quit_spec.rb +0 -7
- data/spec/commands/randomkey_spec.rb +0 -20
- data/spec/commands/rename_spec.rb +0 -42
- data/spec/commands/renamenx_spec.rb +0 -41
- data/spec/commands/rpop_spec.rb +0 -34
- data/spec/commands/rpoplpush_spec.rb +0 -50
- data/spec/commands/rpush_spec.rb +0 -43
- data/spec/commands/rpushx_spec.rb +0 -46
- data/spec/commands/sadd_spec.rb +0 -45
- data/spec/commands/save_spec.rb +0 -7
- data/spec/commands/scan_each_spec.rb +0 -39
- data/spec/commands/scan_spec.rb +0 -55
- data/spec/commands/scard_spec.rb +0 -18
- data/spec/commands/script_spec.rb +0 -9
- data/spec/commands/sdiff_spec.rb +0 -47
- data/spec/commands/sdiffstore_spec.rb +0 -58
- data/spec/commands/select_spec.rb +0 -61
- data/spec/commands/set_spec.rb +0 -63
- data/spec/commands/setbit_spec.rb +0 -54
- data/spec/commands/setex_spec.rb +0 -22
- data/spec/commands/setnx_spec.rb +0 -25
- data/spec/commands/setrange_spec.rb +0 -30
- data/spec/commands/sinter_spec.rb +0 -39
- data/spec/commands/sinterstore_spec.rb +0 -53
- data/spec/commands/sismember_spec.rb +0 -29
- data/spec/commands/smembers_spec.rb +0 -28
- data/spec/commands/smove_spec.rb +0 -41
- data/spec/commands/sort_list_spec.rb +0 -21
- data/spec/commands/sort_set_spec.rb +0 -21
- data/spec/commands/sort_zset_spec.rb +0 -21
- data/spec/commands/spop_spec.rb +0 -25
- data/spec/commands/srandmember_spec.rb +0 -49
- data/spec/commands/srem_spec.rb +0 -40
- data/spec/commands/sscan_each_spec.rb +0 -48
- data/spec/commands/sscan_spec.rb +0 -39
- data/spec/commands/strlen_spec.rb +0 -18
- data/spec/commands/sunion_spec.rb +0 -42
- data/spec/commands/sunionstore_spec.rb +0 -59
- data/spec/commands/ttl_spec.rb +0 -40
- data/spec/commands/type_spec.rb +0 -36
- data/spec/commands/unwatch_spec.rb +0 -7
- data/spec/commands/watch_spec.rb +0 -16
- data/spec/commands/zadd_spec.rb +0 -123
- data/spec/commands/zcard_spec.rb +0 -19
- data/spec/commands/zcount_spec.rb +0 -39
- data/spec/commands/zincrby_spec.rb +0 -31
- data/spec/commands/zinterstore_spec.rb +0 -96
- data/spec/commands/zrange_spec.rb +0 -80
- data/spec/commands/zrangebyscore_spec.rb +0 -83
- data/spec/commands/zrank_spec.rb +0 -29
- data/spec/commands/zrem_spec.rb +0 -43
- data/spec/commands/zremrangebyrank_spec.rb +0 -27
- data/spec/commands/zremrangebyscore_spec.rb +0 -35
- data/spec/commands/zrevrange_spec.rb +0 -56
- data/spec/commands/zrevrangebyscore_spec.rb +0 -58
- data/spec/commands/zrevrank_spec.rb +0 -29
- data/spec/commands/zscan_each_spec.rb +0 -48
- data/spec/commands/zscan_spec.rb +0 -26
- data/spec/commands/zscore_spec.rb +0 -22
- data/spec/commands/zunionstore_spec.rb +0 -104
- data/spec/mock_redis_spec.rb +0 -86
- data/spec/spec_helper.rb +0 -63
- data/spec/support/redis_multiplexer.rb +0 -106
- data/spec/support/shared_examples/only_operates_on_hashes.rb +0 -13
- data/spec/support/shared_examples/only_operates_on_lists.rb +0 -13
- data/spec/support/shared_examples/only_operates_on_sets.rb +0 -13
- data/spec/support/shared_examples/only_operates_on_strings.rb +0 -13
- data/spec/support/shared_examples/only_operates_on_zsets.rb +0 -57
- data/spec/support/shared_examples/sorts_enumerables.rb +0 -56
- data/spec/transactions_spec.rb +0 -159
data/spec/commands/hmget_spec.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#hmget(key, field [, field, ...])' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:hmget'
|
6
|
-
@redises.hset(@key, 'k1', 'v1')
|
7
|
-
@redises.hset(@key, 'k2', 'v2')
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'returns the values for those keys' do
|
11
|
-
@redises.hmget(@key, 'k1', 'k2').sort.should == %w[v1 v2]
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'treats an array as multiple keys' do
|
15
|
-
@redises.hmget(@key, %w[k1 k2]).sort.should == %w[v1 v2]
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'treats the fielsd as strings' do
|
19
|
-
@redises.hset(@key, 1, 'one')
|
20
|
-
@redises.hset(@key, 2, 'two')
|
21
|
-
@redises.hmget(@key, 1, 2).sort.should == %w[one two]
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'returns nils when there are no such fields' do
|
25
|
-
@redises.hmget(@key, 'k1', 'mock-redis-test:nonesuch').
|
26
|
-
should == ['v1', nil]
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'returns nils when there is no such key' do
|
30
|
-
@redises.hmget(@key, 'mock-redis-test:nonesuch').should == [nil]
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'raises an error if given no fields' do
|
34
|
-
lambda do
|
35
|
-
@redises.hmget(@key)
|
36
|
-
end.should raise_error(Redis::CommandError)
|
37
|
-
end
|
38
|
-
|
39
|
-
it_should_behave_like 'a hash-only command'
|
40
|
-
end
|
data/spec/commands/hmset_spec.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#hmset(key, field, value [, field, value ...])' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:hmset'
|
6
|
-
end
|
7
|
-
|
8
|
-
it "returns 'OK'" do
|
9
|
-
@redises.hmset(@key, 'k1', 'v1', 'k2', 'v2').should == 'OK'
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'sets the values' do
|
13
|
-
@redises.hmset(@key, 'k1', 'v1', 'k2', 'v2')
|
14
|
-
@redises.hmget(@key, 'k1', 'k2').should == %w[v1 v2]
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'updates an existing hash' do
|
18
|
-
@redises.hset(@key, 'foo', 'bar')
|
19
|
-
@redises.hmset(@key, 'bert', 'ernie', 'diet', 'coke')
|
20
|
-
|
21
|
-
@redises.hmget(@key, 'foo', 'bert', 'diet').
|
22
|
-
should == %w[bar ernie coke]
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'stores the values as strings' do
|
26
|
-
@redises.hmset(@key, 'one', 1)
|
27
|
-
@redises.hget(@key, 'one').should == '1'
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'raises an error if given no fields or values' do
|
31
|
-
lambda do
|
32
|
-
@redises.hmset(@key)
|
33
|
-
end.should raise_error(Redis::CommandError)
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'raises an error if given an odd number of fields+values' do
|
37
|
-
lambda do
|
38
|
-
@redises.hmset(@key, 'k1', 1, 'k2')
|
39
|
-
end.should raise_error(Redis::CommandError)
|
40
|
-
end
|
41
|
-
|
42
|
-
it_should_behave_like 'a hash-only command'
|
43
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#hscan_each' do
|
4
|
-
subject { MockRedis::Database.new(self) }
|
5
|
-
|
6
|
-
let(:key) { 'mock-redis-test:hscan_each' }
|
7
|
-
|
8
|
-
before do
|
9
|
-
allow(subject).to receive(:hgetall).and_return(collection)
|
10
|
-
end
|
11
|
-
|
12
|
-
context 'when no keys are found' do
|
13
|
-
let(:collection) { [] }
|
14
|
-
|
15
|
-
it 'does not iterate over any elements' do
|
16
|
-
results = subject.hscan_each(key).map do |k, v|
|
17
|
-
[k, v]
|
18
|
-
end
|
19
|
-
expect(results).to match_array(collection)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context 'when keys are found' do
|
24
|
-
context 'when no match filter is supplied' do
|
25
|
-
let(:collection) { Array.new(20) { |i| ["k#{i}", "v#{i}"] } }
|
26
|
-
|
27
|
-
it 'iterates over each item in the collection' do
|
28
|
-
results = subject.hscan_each(key).map do |k, v|
|
29
|
-
[k, v]
|
30
|
-
end
|
31
|
-
expect(results).to match_array(collection)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context 'when giving a custom match filter' do
|
36
|
-
let(:match) { 'k1*' }
|
37
|
-
let(:collection) { Array.new(12) { |i| ["k#{i}", "v#{i}"] } }
|
38
|
-
let(:expected) { [%w[k1 v1], %w[k10 v10], %w[k11 v11]] }
|
39
|
-
|
40
|
-
it 'iterates over each item in the filtered collection' do
|
41
|
-
results = subject.hscan_each(key, match: match).map do |k, v|
|
42
|
-
[k, v]
|
43
|
-
end
|
44
|
-
expect(results).to match_array(expected)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
data/spec/commands/hscan_spec.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#hscan' do
|
4
|
-
let(:count) { 10 }
|
5
|
-
let(:match) { '*' }
|
6
|
-
let(:key) { 'mock-redis-test:hscan' }
|
7
|
-
|
8
|
-
context 'when the hash does not exist' do
|
9
|
-
it 'returns a 0 cursor and an empty collection' do
|
10
|
-
expect(@redises.hscan(key, 0, count: count, match: match)).to eq(['0', []])
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
context 'when the hash exists' do
|
15
|
-
before do
|
16
|
-
@redises.hset(key, 'k1', 'v1')
|
17
|
-
@redises.hset(key, 'k2', 'v2')
|
18
|
-
@redises.hset(key, 'k3', 'v3')
|
19
|
-
end
|
20
|
-
|
21
|
-
let(:expected) { ['0', [%w[k1 v1], %w[k2 v2], %w[k3 v3]]] }
|
22
|
-
|
23
|
-
it 'returns a 0 cursor and the collection' do
|
24
|
-
expect(@redises.hscan(key, 0, count: 10)).to eq(expected)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
data/spec/commands/hset_spec.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#hset(key, field)' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:hset'
|
6
|
-
end
|
7
|
-
|
8
|
-
it 'returns true if the key does not exist' do
|
9
|
-
@redises.hset(@key, 'k1', 'v1').should == true
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'returns true if the key exists but the field does not' do
|
13
|
-
@redises.hset(@key, 'k1', 'v1')
|
14
|
-
@redises.hset(@key, 'k2', 'v2').should == true
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'returns false if the field already exists' do
|
18
|
-
@redises.hset(@key, 'k1', 'v1')
|
19
|
-
@redises.hset(@key, 'k1', 'v1').should == false
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'creates a hash there is no such field' do
|
23
|
-
@redises.hset(@key, 'k1', 'v1')
|
24
|
-
@redises.hget(@key, 'k1').should == 'v1'
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'stores values as strings' do
|
28
|
-
@redises.hset(@key, 'num', 1)
|
29
|
-
@redises.hget(@key, 'num').should == '1'
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'stores fields as strings' do
|
33
|
-
@redises.hset(@key, 1, 'one')
|
34
|
-
@redises.hget(@key, '1').should == 'one'
|
35
|
-
end
|
36
|
-
|
37
|
-
it_should_behave_like 'a hash-only command'
|
38
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#hsetnx(key, field)' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:hsetnx'
|
6
|
-
end
|
7
|
-
|
8
|
-
it 'returns true if the field is absent' do
|
9
|
-
@redises.hsetnx(@key, 'field', 'val').should == true
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'returns 0 if the field is present' do
|
13
|
-
@redises.hset(@key, 'field', 'val')
|
14
|
-
@redises.hsetnx(@key, 'field', 'val').should == false
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'leaves the field unchanged if the field is present' do
|
18
|
-
@redises.hset(@key, 'field', 'old')
|
19
|
-
@redises.hsetnx(@key, 'field', 'new')
|
20
|
-
@redises.hget(@key, 'field').should == 'old'
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'sets the field if the field is absent' do
|
24
|
-
@redises.hsetnx(@key, 'field', 'new')
|
25
|
-
@redises.hget(@key, 'field').should == 'new'
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'creates a hash if there is no such field' do
|
29
|
-
@redises.hsetnx(@key, 'field', 'val')
|
30
|
-
@redises.hget(@key, 'field').should == 'val'
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'stores values as strings' do
|
34
|
-
@redises.hsetnx(@key, 'num', 1)
|
35
|
-
@redises.hget(@key, 'num').should == '1'
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'stores fields as strings' do
|
39
|
-
@redises.hsetnx(@key, 1, 'one')
|
40
|
-
@redises.hget(@key, '1').should == 'one'
|
41
|
-
end
|
42
|
-
|
43
|
-
it_should_behave_like 'a hash-only command'
|
44
|
-
end
|
data/spec/commands/hvals_spec.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#hvals(key)' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:hvals'
|
6
|
-
@redises.hset(@key, 'k1', 'v1')
|
7
|
-
@redises.hset(@key, 'k2', 'v2')
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'returns the values stored in the hash' do
|
11
|
-
@redises.hvals(@key).sort.should == %w[v1 v2]
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'returns [] when there is no such key' do
|
15
|
-
@redises.hvals('mock-redis-test:nonesuch').should == []
|
16
|
-
end
|
17
|
-
|
18
|
-
it_should_behave_like 'a hash-only command'
|
19
|
-
end
|
data/spec/commands/incr_spec.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#incr(key)' do
|
4
|
-
before { @key = 'mock-redis-test:33888' }
|
5
|
-
|
6
|
-
it 'returns the value after the increment' do
|
7
|
-
@redises.set(@key, 1)
|
8
|
-
@redises.incr(@key).should == 2
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'treats a missing key like 0' do
|
12
|
-
@redises.incr(@key).should == 1
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'increments negative numbers' do
|
16
|
-
@redises.set(@key, -10)
|
17
|
-
@redises.incr(@key).should == -9
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'works multiple times' do
|
21
|
-
@redises.incr(@key).should == 1
|
22
|
-
@redises.incr(@key).should == 2
|
23
|
-
@redises.incr(@key).should == 3
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'raises an error if the value does not look like an integer' do
|
27
|
-
@redises.set(@key, 'one')
|
28
|
-
lambda do
|
29
|
-
@redises.incr(@key)
|
30
|
-
end.should raise_error(Redis::CommandError)
|
31
|
-
end
|
32
|
-
|
33
|
-
it_should_behave_like 'a string-only command'
|
34
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#incrby(key, increment)' do
|
4
|
-
before { @key = 'mock-redis-test:65374' }
|
5
|
-
|
6
|
-
it 'returns the value after the increment' do
|
7
|
-
@redises.set(@key, 2)
|
8
|
-
@redises.incrby(@key, 2).should == 4
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'treats a missing key like 0' do
|
12
|
-
@redises.incrby(@key, 1).should == 1
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'increments negative numbers' do
|
16
|
-
@redises.set(@key, -10)
|
17
|
-
@redises.incrby(@key, 2).should == -8
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'works multiple times' do
|
21
|
-
@redises.incrby(@key, 2).should == 2
|
22
|
-
@redises.incrby(@key, 2).should == 4
|
23
|
-
@redises.incrby(@key, 2).should == 6
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'accepts an integer-ish string' do
|
27
|
-
@redises.incrby(@key, '2').should == 2
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'raises an error if the value does not look like an integer' do
|
31
|
-
@redises.set(@key, 'one')
|
32
|
-
lambda do
|
33
|
-
@redises.incrby(@key, 1)
|
34
|
-
end.should raise_error(Redis::CommandError)
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'raises an error if the delta does not look like an integer' do
|
38
|
-
lambda do
|
39
|
-
@redises.incrby(@key, 'foo')
|
40
|
-
end.should raise_error(Redis::CommandError)
|
41
|
-
end
|
42
|
-
|
43
|
-
it_should_behave_like 'a string-only command'
|
44
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#incrbyfloat(key, increment)' do
|
4
|
-
before { @key = 'mock-redis-test:65374' }
|
5
|
-
|
6
|
-
it 'returns the value after the increment' do
|
7
|
-
@redises.set(@key, 2.0)
|
8
|
-
@redises.incrbyfloat(@key, 2.1).should be_within(0.0001).of(4.1)
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'treats a missing key like 0' do
|
12
|
-
@redises.incrbyfloat(@key, 1.2).should be_within(0.0001).of(1.2)
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'increments negative numbers' do
|
16
|
-
@redises.set(@key, -10.4)
|
17
|
-
@redises.incrbyfloat(@key, 2.3).should be_within(0.0001).of(-8.1)
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'works multiple times' do
|
21
|
-
@redises.incrbyfloat(@key, 2.1).should be_within(0.0001).of(2.1)
|
22
|
-
@redises.incrbyfloat(@key, 2.2).should be_within(0.0001).of(4.3)
|
23
|
-
@redises.incrbyfloat(@key, 2.3).should be_within(0.0001).of(6.6)
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'accepts an float-ish string' do
|
27
|
-
@redises.incrbyfloat(@key, '2.2').should be_within(0.0001).of(2.2)
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'raises an error if the value does not look like an float' do
|
31
|
-
@redises.set(@key, 'one.two')
|
32
|
-
lambda do
|
33
|
-
@redises.incrbyfloat(@key, 1)
|
34
|
-
end.should raise_error(Redis::CommandError)
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'raises an error if the delta does not look like an float' do
|
38
|
-
lambda do
|
39
|
-
@redises.incrbyfloat(@key, 'foobar.baz')
|
40
|
-
end.should raise_error(Redis::CommandError)
|
41
|
-
end
|
42
|
-
|
43
|
-
it_should_behave_like 'a string-only command'
|
44
|
-
end
|
data/spec/commands/info_spec.rb
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#info [mock only]' do
|
4
|
-
let(:redis) { @redises.mock }
|
5
|
-
|
6
|
-
it 'responds with a config hash' do
|
7
|
-
redis.info.should be_a(Hash)
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'gets default set of info' do
|
11
|
-
info = redis.info
|
12
|
-
info['arch_bits'].should be_a(String)
|
13
|
-
info['connected_clients'].should be_a(String)
|
14
|
-
info['aof_rewrite_scheduled'].should be_a(String)
|
15
|
-
info['used_cpu_sys'].should be_a(String)
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'gets all info' do
|
19
|
-
info = redis.info(:all)
|
20
|
-
info['arch_bits'].should be_a(String)
|
21
|
-
info['connected_clients'].should be_a(String)
|
22
|
-
info['aof_rewrite_scheduled'].should be_a(String)
|
23
|
-
info['used_cpu_sys'].should be_a(String)
|
24
|
-
info['cmdstat_slowlog'].should be_a(String)
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'gets server info' do
|
28
|
-
redis.info(:server)['arch_bits'].should be_a(String)
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'gets clients info' do
|
32
|
-
redis.info(:clients)['connected_clients'].should be_a(String)
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'gets memory info' do
|
36
|
-
redis.info(:memory)['used_memory'].should be_a(String)
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'gets persistence info' do
|
40
|
-
redis.info(:persistence)['aof_rewrite_scheduled'].should be_a(String)
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'gets stats info' do
|
44
|
-
redis.info(:stats)['keyspace_hits'].should be_a(String)
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'gets replication info' do
|
48
|
-
redis.info(:replication)['role'].should be_a(String)
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'gets cpu info' do
|
52
|
-
redis.info(:cpu)['used_cpu_sys'].should be_a(String)
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'gets keyspace info' do
|
56
|
-
redis.info(:keyspace)['db0'].should be_a(String)
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'gets commandstats info' do
|
60
|
-
redis.info(:commandstats)['sunionstore']['usec'].should be_a(String)
|
61
|
-
end
|
62
|
-
end
|
data/spec/commands/keys_spec.rb
DELETED
@@ -1,122 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#keys()' do
|
4
|
-
it 'returns [] when no keys are found (no regex characters)' do
|
5
|
-
@redises.keys('mock-redis-test:29016').should == []
|
6
|
-
end
|
7
|
-
|
8
|
-
it 'returns [] when no keys are found (some regex characters)' do
|
9
|
-
@redises.keys('mock-redis-test:29016*').should == []
|
10
|
-
end
|
11
|
-
|
12
|
-
describe 'with pattern matching' do
|
13
|
-
before do
|
14
|
-
@redises.set('mock-redis-test:key', 0)
|
15
|
-
@redises.set('mock-redis-test:key1', 1)
|
16
|
-
@redises.set('mock-redis-test:key2', 2)
|
17
|
-
@redises.set('mock-redis-test:key3', 3)
|
18
|
-
@redises.set('mock-redis-test:key10', 10)
|
19
|
-
@redises.set('mock-redis-test:key20', 20)
|
20
|
-
@redises.set('mock-redis-test:key30', 30)
|
21
|
-
|
22
|
-
@redises.set('mock-redis-test:regexp-key(1|22)', 40)
|
23
|
-
@redises.set('mock-redis-test:regexp-key3+', 40)
|
24
|
-
@redises.set('mock-redis-test:regexp-key33', 40)
|
25
|
-
@redises.set('mock-redis-test:regexp-key4a', 40)
|
26
|
-
@redises.set('mock-redis-test:regexp-key4-', 40)
|
27
|
-
@redises.set('mock-redis-test:regexp-key4b', 40)
|
28
|
-
@redises.set('mock-redis-test:regexp-key4c', 40)
|
29
|
-
|
30
|
-
@redises.set('mock-redis-test:special-key?', 'true')
|
31
|
-
@redises.set('mock-redis-test:special-key*', 'true')
|
32
|
-
end
|
33
|
-
|
34
|
-
describe 'the ? character' do
|
35
|
-
it 'is treated as a single character (at the end of the pattern)' do
|
36
|
-
@redises.keys('mock-redis-test:key?').sort.should == [
|
37
|
-
'mock-redis-test:key1',
|
38
|
-
'mock-redis-test:key2',
|
39
|
-
'mock-redis-test:key3',
|
40
|
-
]
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'is treated as a single character (in the middle of the pattern)' do
|
44
|
-
@redises.keys('mock-redis-test:key?0').sort.should == [
|
45
|
-
'mock-redis-test:key10',
|
46
|
-
'mock-redis-test:key20',
|
47
|
-
'mock-redis-test:key30',
|
48
|
-
]
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'treats \\? as a literal ?' do
|
52
|
-
@redises.keys('mock-redis-test:special-key\?').sort.should == [
|
53
|
-
'mock-redis-test:special-key?',
|
54
|
-
]
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
describe 'the * character' do
|
59
|
-
it 'is treated as 0 or more characters' do
|
60
|
-
@redises.keys('mock-redis-test:key*').sort.should == [
|
61
|
-
'mock-redis-test:key',
|
62
|
-
'mock-redis-test:key1',
|
63
|
-
'mock-redis-test:key10',
|
64
|
-
'mock-redis-test:key2',
|
65
|
-
'mock-redis-test:key20',
|
66
|
-
'mock-redis-test:key3',
|
67
|
-
'mock-redis-test:key30',
|
68
|
-
]
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'treats \\* as a literal *' do
|
72
|
-
@redises.keys('mock-redis-test:special-key\*').sort.should == [
|
73
|
-
'mock-redis-test:special-key*',
|
74
|
-
]
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
describe 'character classes ([abcde])' do
|
79
|
-
it 'matches any one of those characters' do
|
80
|
-
@redises.keys('mock-redis-test:key[12]').sort.should == [
|
81
|
-
'mock-redis-test:key1',
|
82
|
-
'mock-redis-test:key2',
|
83
|
-
]
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
describe 'the | character' do
|
88
|
-
it "is treated as literal (not 'or')" do
|
89
|
-
@redises.keys('mock-redis-test:regexp-key(1|22)').sort.should == [
|
90
|
-
'mock-redis-test:regexp-key(1|22)',
|
91
|
-
]
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
describe 'the + character' do
|
96
|
-
it "is treated as literal (not 'one or more' quantifier)" do
|
97
|
-
@redises.keys('mock-redis-test:regexp-key3+').sort.should == [
|
98
|
-
'mock-redis-test:regexp-key3+',
|
99
|
-
]
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
describe 'character classes ([a-c])' do
|
104
|
-
it 'specifies a range which matches any lowercase letter from "a" to "c"' do
|
105
|
-
@redises.keys('mock-redis-test:regexp-key4[a-c]').sort.should == [
|
106
|
-
'mock-redis-test:regexp-key4a',
|
107
|
-
'mock-redis-test:regexp-key4b',
|
108
|
-
'mock-redis-test:regexp-key4c',
|
109
|
-
]
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
describe 'combining metacharacters' do
|
114
|
-
it 'works with different metacharacters simultaneously' do
|
115
|
-
@redises.keys('mock-redis-test:k*[12]?').sort.should == [
|
116
|
-
'mock-redis-test:key10',
|
117
|
-
'mock-redis-test:key20',
|
118
|
-
]
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#lindex(key, index)' do
|
4
|
-
before { @key = 'mock-redis-test:69312' }
|
5
|
-
|
6
|
-
it 'gets an element from the list by its index' do
|
7
|
-
@redises.lpush(@key, 20)
|
8
|
-
@redises.lpush(@key, 10)
|
9
|
-
|
10
|
-
@redises.lindex(@key, 0).should == '10'
|
11
|
-
@redises.lindex(@key, 1).should == '20'
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'treats negative indices as coming from the right' do
|
15
|
-
@redises.lpush(@key, 20)
|
16
|
-
@redises.lpush(@key, 10)
|
17
|
-
|
18
|
-
@redises.lindex(@key, -1).should == '20'
|
19
|
-
@redises.lindex(@key, -2).should == '10'
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'gets an element from the list by its index when index is a string' do
|
23
|
-
@redises.lpush(@key, 20)
|
24
|
-
@redises.lpush(@key, 10)
|
25
|
-
|
26
|
-
@redises.lindex(@key, '0').should == '10'
|
27
|
-
@redises.lindex(@key, '1').should == '20'
|
28
|
-
@redises.lindex(@key, '-1').should == '20'
|
29
|
-
@redises.lindex(@key, '-2').should == '10'
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'returns nil if the index is too large (and positive)' do
|
33
|
-
@redises.lpush(@key, 20)
|
34
|
-
|
35
|
-
@redises.lindex(@key, 100).should be_nil
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'returns nil if the index is too large (and negative)' do
|
39
|
-
@redises.lpush(@key, 20)
|
40
|
-
|
41
|
-
@redises.lindex(@key, -100).should be_nil
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'returns nil for nonexistent values' do
|
45
|
-
@redises.lindex(@key, 0).should be_nil
|
46
|
-
end
|
47
|
-
|
48
|
-
it_should_behave_like 'a list-only command'
|
49
|
-
end
|