mock_redis 0.36.0 → 0.37.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +1 -1
- data/lib/mock_redis/database.rb +1 -1
- data/lib/mock_redis/hash_methods.rb +1 -1
- data/lib/mock_redis/list_methods.rb +7 -2
- data/lib/mock_redis/multi_db_wrapper.rb +1 -1
- data/lib/mock_redis/pipelined_wrapper.rb +12 -14
- data/lib/mock_redis/set_methods.rb +6 -1
- data/lib/mock_redis/stream.rb +3 -3
- data/lib/mock_redis/string_methods.rb +3 -3
- data/lib/mock_redis/transaction_wrapper.rb +5 -7
- data/lib/mock_redis/utility_methods.rb +4 -2
- data/lib/mock_redis/version.rb +1 -1
- data/lib/mock_redis/zset.rb +4 -2
- data/lib/mock_redis/zset_methods.rb +3 -3
- data/lib/mock_redis.rb +1 -2
- metadata +19 -360
- data/.github/workflows/lint.yml +0 -31
- data/.github/workflows/tests.yml +0 -63
- data/.gitignore +0 -5
- data/.mailmap +0 -2
- data/.overcommit.yml +0 -21
- data/.rspec +0 -1
- data/.rubocop.yml +0 -148
- data/.rubocop_todo.yml +0 -35
- data/.simplecov +0 -4
- data/Gemfile +0 -13
- data/Rakefile +0 -2
- data/mock_redis.gemspec +0 -32
- data/spec/client_spec.rb +0 -36
- 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/blmove_spec.rb +0 -52
- data/spec/commands/blpop_spec.rb +0 -53
- data/spec/commands/brpop_spec.rb +0 -59
- data/spec/commands/brpoplpush_spec.rb +0 -52
- data/spec/commands/connected_spec.rb +0 -7
- data/spec/commands/connection_spec.rb +0 -15
- 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 -52
- data/spec/commands/disconnect_spec.rb +0 -7
- data/spec/commands/dump_spec.rb +0 -19
- 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 -43
- 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 -30
- data/spec/commands/geoadd_spec.rb +0 -58
- data/spec/commands/geodist_spec.rb +0 -118
- data/spec/commands/geohash_spec.rb +0 -52
- data/spec/commands/geopos_spec.rb +0 -55
- data/spec/commands/get_spec.rb +0 -31
- data/spec/commands/getbit_spec.rb +0 -34
- data/spec/commands/getdel.rb +0 -24
- data/spec/commands/getrange_spec.rb +0 -22
- data/spec/commands/getset_spec.rb +0 -23
- data/spec/commands/hdel_spec.rb +0 -77
- 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 -46
- data/spec/commands/hmset_spec.rb +0 -69
- data/spec/commands/hscan_each_spec.rb +0 -48
- data/spec/commands/hscan_spec.rb +0 -27
- data/spec/commands/hset_spec.rb +0 -42
- 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 -139
- 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/lmove_spec.rb +0 -72
- data/spec/commands/lpop_spec.rb +0 -35
- 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 -65
- data/spec/commands/move_spec.rb +0 -147
- data/spec/commands/mset_spec.rb +0 -43
- 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 -11
- data/spec/commands/pipelined_spec.rb +0 -114
- data/spec/commands/psetex_spec.rb +0 -44
- 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/restore_spec.rb +0 -47
- data/spec/commands/rpop_spec.rb +0 -35
- 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 -64
- 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 -134
- data/spec/commands/setbit_spec.rb +0 -55
- data/spec/commands/setex_spec.rb +0 -38
- 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/smismember_spec.rb +0 -34
- 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 -40
- data/spec/commands/srandmember_spec.rb +0 -49
- data/spec/commands/srem_spec.rb +0 -45
- 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 -21
- data/spec/commands/xadd_spec.rb +0 -122
- data/spec/commands/xlen_spec.rb +0 -22
- data/spec/commands/xrange_spec.rb +0 -164
- data/spec/commands/xread_spec.rb +0 -66
- data/spec/commands/xrevrange_spec.rb +0 -130
- data/spec/commands/xtrim_spec.rb +0 -36
- data/spec/commands/zadd_spec.rb +0 -129
- 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 -130
- data/spec/commands/zpopmax_spec.rb +0 -60
- data/spec/commands/zpopmin_spec.rb +0 -60
- 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 -50
- 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 -137
- data/spec/mock_redis_spec.rb +0 -93
- data/spec/spec_helper.rb +0 -74
- data/spec/support/redis_multiplexer.rb +0 -123
- data/spec/support/shared_examples/does_not_cleanup_empty_strings.rb +0 -14
- data/spec/support/shared_examples/only_operates_on_hashes.rb +0 -15
- data/spec/support/shared_examples/only_operates_on_lists.rb +0 -15
- data/spec/support/shared_examples/only_operates_on_sets.rb +0 -15
- data/spec/support/shared_examples/only_operates_on_strings.rb +0 -13
- data/spec/support/shared_examples/only_operates_on_zsets.rb +0 -59
- data/spec/support/shared_examples/sorts_enumerables.rb +0 -56
- data/spec/transactions_spec.rb +0 -163
data/spec/commands/ltrim_spec.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#ltrim(key, start, stop)' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:22310'
|
6
|
-
|
7
|
-
%w[v0 v1 v2 v3 v4].reverse_each { |v| @redises.lpush(@key, v) }
|
8
|
-
end
|
9
|
-
|
10
|
-
it "returns 'OK'" do
|
11
|
-
@redises.ltrim(@key, 1, 3).should == 'OK'
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'trims the list to include only the specified elements' do
|
15
|
-
@redises.ltrim(@key, 1, 3)
|
16
|
-
@redises.lrange(@key, 0, -1).should == %w[v1 v2 v3]
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'trims the list when start and stop are strings' do
|
20
|
-
@redises.ltrim(@key, '1', '3')
|
21
|
-
@redises.lrange(@key, 0, -1).should == %w[v1 v2 v3]
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'trims the list to include only the specified elements (negative indices)' do
|
25
|
-
@redises.ltrim(@key, -2, -1)
|
26
|
-
@redises.lrange(@key, 0, -1).should == %w[v3 v4]
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'trims the list to include only the specified elements (out of range negative indices)' do
|
30
|
-
@redises.ltrim(@key, -10, -2)
|
31
|
-
@redises.lrange(@key, 0, -1).should == %w[v0 v1 v2 v3]
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'does not crash on overly-large indices' do
|
35
|
-
@redises.ltrim(@key, 100, 200)
|
36
|
-
@redises.lrange(@key, 0, -1).should == %w[]
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'removes empty lists' do
|
40
|
-
@redises.ltrim(@key, 1, 0)
|
41
|
-
@redises.get(@key).should be_nil
|
42
|
-
end
|
43
|
-
|
44
|
-
it_should_behave_like 'a list-only command'
|
45
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#mapped_hmget(key, *fields)' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:mapped_hmget'
|
6
|
-
@redises.hmset(@key, 'k1', 'v1', 'k2', 'v2')
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'returns values stored at key' do
|
10
|
-
@redises.mapped_hmget(@key, 'k1', 'k2').should == { 'k1' => 'v1', 'k2' => 'v2' }
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'returns nils for missing fields' do
|
14
|
-
@redises.mapped_hmget(@key, 'k1', 'mock-redis-test:nonesuch').
|
15
|
-
should == { 'k1' => 'v1', 'mock-redis-test:nonesuch' => nil }
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'treats an array as the first key' do
|
19
|
-
@redises.mapped_hmget(@key, %w[k1 k2]).should == { %w[k1 k2] => 'v1' }
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'raises an error if given no fields' do
|
23
|
-
lambda do
|
24
|
-
@redises.mapped_hmget(@key)
|
25
|
-
end.should raise_error(Redis::CommandError)
|
26
|
-
end
|
27
|
-
|
28
|
-
it_should_behave_like 'a hash-only command'
|
29
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#mapped_hmset(key, hash={})' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:mapped_hmset'
|
6
|
-
end
|
7
|
-
|
8
|
-
it "returns 'OK'" do
|
9
|
-
@redises.mapped_hmset(@key, 'k1' => 'v1', 'k2' => 'v2').should == 'OK'
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'sets the values' do
|
13
|
-
@redises.mapped_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.hmset(@key, 'foo', 'bar')
|
19
|
-
@redises.mapped_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.mapped_hmset(@key, 'one' => 1)
|
27
|
-
@redises.hget(@key, 'one').should == '1'
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'raises an error if given no hash' do
|
31
|
-
lambda do
|
32
|
-
@redises.mapped_hmset(@key)
|
33
|
-
end.should raise_error(ArgumentError)
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'raises an error if given a an odd length array' do
|
37
|
-
lambda do
|
38
|
-
@redises.mapped_hmset(@key, [1])
|
39
|
-
end.should raise_error(Redis::CommandError)
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'raises an error if given a non-hash value' do
|
43
|
-
lambda do
|
44
|
-
@redises.mapped_hmset(@key, 1)
|
45
|
-
end.should raise_error(NoMethodError)
|
46
|
-
end
|
47
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#mapped_mget(*keys)' do
|
4
|
-
before do
|
5
|
-
@key1 = 'mock-redis-test:a'
|
6
|
-
@key2 = 'mock-redis-test:b'
|
7
|
-
@key3 = 'mock-redis-test:c'
|
8
|
-
|
9
|
-
@redises.set(@key1, '1')
|
10
|
-
@redises.set(@key2, '2')
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'returns a hash' do
|
14
|
-
@redises.mapped_mget(@key1, @key2, @key3).should eq(@key1 => '1',
|
15
|
-
@key2 => '2',
|
16
|
-
@key3 => nil)
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'returns a hash even when no matches' do
|
20
|
-
@redises.mapped_mget('qwer').should eq('qwer' => nil)
|
21
|
-
end
|
22
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#mapped_mset(hash)' do
|
4
|
-
before do
|
5
|
-
@key1 = 'mock-redis-test:a'
|
6
|
-
@key2 = 'mock-redis-test:b'
|
7
|
-
@key3 = 'mock-redis-test:c'
|
8
|
-
|
9
|
-
@redises.set(@key1, '1')
|
10
|
-
@redises.set(@key2, '2')
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'sets the values properly' do
|
14
|
-
@redises.mapped_mset(@key1 => 'one', @key3 => 'three').should eq('OK')
|
15
|
-
@redises.get(@key1).should eq('one')
|
16
|
-
@redises.get(@key2).should eq('2') # left alone
|
17
|
-
@redises.get(@key3).should eq('three')
|
18
|
-
end
|
19
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#mapped_msetnx(hash)' do
|
4
|
-
before do
|
5
|
-
@key1 = 'mock-redis-test:a'
|
6
|
-
@key2 = 'mock-redis-test:b'
|
7
|
-
@key3 = 'mock-redis-test:c'
|
8
|
-
|
9
|
-
@redises.set(@key1, '1')
|
10
|
-
@redises.set(@key2, '2')
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'sets properly when none collide' do
|
14
|
-
@redises.mapped_msetnx(@key3 => 'three').should eq(true)
|
15
|
-
@redises.get(@key1).should eq('1') # existed; untouched
|
16
|
-
@redises.get(@key2).should eq('2') # existed; untouched
|
17
|
-
@redises.get(@key3).should eq('three')
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'does not set any when any collide' do
|
21
|
-
@redises.mapped_msetnx(@key1 => 'one', @key3 => 'three').should eq(false)
|
22
|
-
@redises.get(@key1).should eq('1') # existed; untouched
|
23
|
-
@redises.get(@key2).should eq('2') # existed; untouched
|
24
|
-
@redises.get(@key3).should be_nil
|
25
|
-
end
|
26
|
-
end
|
data/spec/commands/mget_spec.rb
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#mget(key [, key, ...])' do
|
4
|
-
before do
|
5
|
-
@key1 = 'mock-redis-test:mget1'
|
6
|
-
@key2 = 'mock-redis-test:mget2'
|
7
|
-
|
8
|
-
@redises.set(@key1, 1)
|
9
|
-
@redises.set(@key2, 2)
|
10
|
-
end
|
11
|
-
|
12
|
-
context 'emulate param array' do
|
13
|
-
it 'returns an array of values' do
|
14
|
-
@redises.mget([@key1, @key2]).should == %w[1 2]
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'returns an array of values' do
|
18
|
-
@redises.mget([@key1, @key2]).should == %w[1 2]
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'returns nil for non-string keys' do
|
22
|
-
list = 'mock-redis-test:mget-list'
|
23
|
-
|
24
|
-
@redises.lpush(list, 'bork bork bork')
|
25
|
-
|
26
|
-
@redises.mget([@key1, @key2, list]).should == ['1', '2', nil]
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
context 'emulate params strings' do
|
31
|
-
it 'returns an array of values' do
|
32
|
-
@redises.mget(@key1, @key2).should == %w[1 2]
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'returns nil for missing keys' do
|
36
|
-
@redises.mget(@key1, 'mock-redis-test:not-found', @key2).should == ['1', nil, '2']
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'returns nil for non-string keys' do
|
40
|
-
list = 'mock-redis-test:mget-list'
|
41
|
-
|
42
|
-
@redises.lpush(list, 'bork bork bork')
|
43
|
-
|
44
|
-
@redises.mget(@key1, @key2, list).should == ['1', '2', nil]
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'raises an error if you pass it 0 arguments' do
|
48
|
-
lambda do
|
49
|
-
@redises.mget
|
50
|
-
end.should raise_error(Redis::CommandError)
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'raises an error if you pass it empty array' do
|
54
|
-
lambda do
|
55
|
-
@redises.mget([])
|
56
|
-
end.should raise_error(Redis::CommandError)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
context 'emulate block' do
|
61
|
-
it 'returns an array of values' do
|
62
|
-
@redises.mget(@key1, @key2) { |values| values.map(&:to_i) }.should == [1, 2]
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
data/spec/commands/move_spec.rb
DELETED
@@ -1,147 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#move(key, db)' do
|
4
|
-
before do
|
5
|
-
@srcdb = 0
|
6
|
-
@destdb = 1
|
7
|
-
|
8
|
-
@key = 'mock-redis-test:move'
|
9
|
-
end
|
10
|
-
|
11
|
-
context 'when key exists in destdb' do
|
12
|
-
before do
|
13
|
-
@redises.set(@key, 'srcvalue')
|
14
|
-
@redises.select(@destdb)
|
15
|
-
@redises.set(@key, 'destvalue')
|
16
|
-
@redises.select(@srcdb)
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'returns false' do
|
20
|
-
@redises.move(@key, @destdb).should == false
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'leaves destdb/key alone' do
|
24
|
-
@redises.select(@destdb)
|
25
|
-
@redises.get(@key).should == 'destvalue'
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'leaves srcdb/key alone' do
|
29
|
-
@redises.get(@key).should == 'srcvalue'
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
context 'when key does not exist in srcdb' do
|
34
|
-
before do
|
35
|
-
@redises.select(@destdb)
|
36
|
-
@redises.set(@key, 'destvalue')
|
37
|
-
@redises.select(@srcdb)
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'returns false' do
|
41
|
-
@redises.move(@key, @destdb).should == false
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'leaves destdb/key alone' do
|
45
|
-
@redises.select(@destdb)
|
46
|
-
@redises.get(@key).should == 'destvalue'
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
context 'when key exists in the currently-selected DB and not in db' do
|
51
|
-
before do
|
52
|
-
@redises.set(@key, 'value')
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'returns true' do
|
56
|
-
@redises.move(@key, @destdb).should == true
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
context 'on a string' do
|
61
|
-
before do
|
62
|
-
@redises.set(@key, 'value')
|
63
|
-
@redises.move(@key, @destdb)
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'removes key from srcdb' do
|
67
|
-
@redises.exists?(@key).should == false
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'copies key to destdb' do
|
71
|
-
@redises.select(@destdb)
|
72
|
-
@redises.get(@key).should == 'value'
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
context 'on a list' do
|
77
|
-
before do
|
78
|
-
@redises.rpush(@key, 'bert')
|
79
|
-
@redises.rpush(@key, 'ernie')
|
80
|
-
@redises.move(@key, @destdb)
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'removes key from srcdb' do
|
84
|
-
@redises.exists?(@key).should == false
|
85
|
-
end
|
86
|
-
|
87
|
-
it 'copies key to destdb' do
|
88
|
-
@redises.select(@destdb)
|
89
|
-
@redises.lrange(@key, 0, -1).should == %w[bert ernie]
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
context 'on a hash' do
|
94
|
-
before do
|
95
|
-
@redises.hset(@key, 'a', 1)
|
96
|
-
@redises.hset(@key, 'b', 2)
|
97
|
-
|
98
|
-
@redises.move(@key, @destdb)
|
99
|
-
end
|
100
|
-
|
101
|
-
it 'removes key from srcdb' do
|
102
|
-
@redises.exists?(@key).should == false
|
103
|
-
end
|
104
|
-
|
105
|
-
it 'copies key to destdb' do
|
106
|
-
@redises.select(@destdb)
|
107
|
-
@redises.hgetall(@key).should == { 'a' => '1', 'b' => '2' }
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
context 'on a set' do
|
112
|
-
before do
|
113
|
-
@redises.sadd(@key, 'beer')
|
114
|
-
@redises.sadd(@key, 'wine')
|
115
|
-
|
116
|
-
@redises.move(@key, @destdb)
|
117
|
-
end
|
118
|
-
|
119
|
-
it 'removes key from srcdb' do
|
120
|
-
@redises.exists?(@key).should == false
|
121
|
-
end
|
122
|
-
|
123
|
-
it 'copies key to destdb' do
|
124
|
-
@redises.select(@destdb)
|
125
|
-
@redises.smembers(@key).should == %w[wine beer]
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
context 'on a zset' do
|
130
|
-
before do
|
131
|
-
@redises.zadd(@key, 1, 'beer')
|
132
|
-
@redises.zadd(@key, 2, 'wine')
|
133
|
-
|
134
|
-
@redises.move(@key, @destdb)
|
135
|
-
end
|
136
|
-
|
137
|
-
it 'removes key from srcdb' do
|
138
|
-
@redises.exists?(@key).should == false
|
139
|
-
end
|
140
|
-
|
141
|
-
it 'copies key to destdb' do
|
142
|
-
@redises.select(@destdb)
|
143
|
-
@redises.zrange(@key, 0, -1, :with_scores => true).should ==
|
144
|
-
[['beer', 1.0], ['wine', 2.0]]
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|
data/spec/commands/mset_spec.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#mset(key, value [, key, value, ...])' do
|
4
|
-
before do
|
5
|
-
@key1 = 'mock-redis-test:mset1'
|
6
|
-
@key2 = 'mock-redis-test:mset2'
|
7
|
-
end
|
8
|
-
|
9
|
-
it "responds with 'OK'" do
|
10
|
-
@redises.mset(@key1, 1).should == 'OK'
|
11
|
-
end
|
12
|
-
|
13
|
-
it "responds with 'OK' for passed Array with 1 item" do
|
14
|
-
@redises.mset([@key1, 1]).should == 'OK'
|
15
|
-
end
|
16
|
-
|
17
|
-
it "responds with 'OK' for passed Array with 2 items" do
|
18
|
-
@redises.mset([@key1, 1, @key2, 2]).should == 'OK'
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'sets the values' do
|
22
|
-
@redises.mset(@key1, 'value1', @key2, 'value2')
|
23
|
-
@redises.mget(@key1, @key2).should == %w[value1 value2]
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'raises an error if given an odd number of arguments' do
|
27
|
-
lambda do
|
28
|
-
@redises.mset(@key1, 'value1', @key2)
|
29
|
-
end.should raise_error(Redis::CommandError)
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'raises an error if given 0 arguments' do
|
33
|
-
lambda do
|
34
|
-
@redises.mset
|
35
|
-
end.should raise_error(Redis::CommandError)
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'raises an error if given odd-sized array' do
|
39
|
-
lambda do
|
40
|
-
@redises.mset([@key1, 1, @key2])
|
41
|
-
end.should raise_error(Redis::CommandError)
|
42
|
-
end
|
43
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#msetnx(key, value [, key, value, ...])' do
|
4
|
-
before do
|
5
|
-
@key1 = 'mock-redis-test:msetnx1'
|
6
|
-
@key2 = 'mock-redis-test:msetnx2'
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'responds with 1 if any keys were set' do
|
10
|
-
@redises.msetnx(@key1, 1).should == true
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'sets the values' do
|
14
|
-
@redises.msetnx(@key1, 'value1', @key2, 'value2')
|
15
|
-
@redises.mget(@key1, @key2).should == %w[value1 value2]
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'does nothing if any value is already set' do
|
19
|
-
@redises.set(@key1, 'old1')
|
20
|
-
@redises.msetnx(@key1, 'value1', @key2, 'value2')
|
21
|
-
@redises.mget(@key1, @key2).should == ['old1', nil]
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'responds with 0 if any value is already set' do
|
25
|
-
@redises.set(@key1, 'old1')
|
26
|
-
@redises.msetnx(@key1, 'value1', @key2, 'value2').should == false
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'raises an error if given an odd number of arguments' do
|
30
|
-
lambda do
|
31
|
-
@redises.msetnx(@key1, 'value1', @key2)
|
32
|
-
end.should raise_error(Redis::CommandError)
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'raises an error if given 0 arguments' do
|
36
|
-
lambda do
|
37
|
-
@redises.msetnx
|
38
|
-
end.should raise_error(Redis::CommandError)
|
39
|
-
end
|
40
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#persist(key)' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:persist'
|
6
|
-
@redises.set(@key, 'spork')
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'returns true for a key with a timeout' do
|
10
|
-
@redises.expire(@key, 10_000)
|
11
|
-
@redises.persist(@key).should == true
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'returns false for a key with no timeout' do
|
15
|
-
@redises.persist(@key).should == false
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'returns false for a key that does not exist' do
|
19
|
-
@redises.persist('mock-redis-test:nonesuch').should == false
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'removes the timeout' do
|
23
|
-
@redises.expire(@key, 10_000)
|
24
|
-
@redises.persist(@key)
|
25
|
-
@redises.persist(@key).should == false
|
26
|
-
end
|
27
|
-
|
28
|
-
context '[mock only]' do
|
29
|
-
# These are mock-only since we can't actually manipulate time in
|
30
|
-
# the real Redis.
|
31
|
-
|
32
|
-
before(:all) do
|
33
|
-
@mock = @redises.mock
|
34
|
-
end
|
35
|
-
|
36
|
-
before do
|
37
|
-
@now = Time.now
|
38
|
-
Time.stub(:now).and_return(@now)
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'makes keys stay around' do
|
42
|
-
@mock.expire(@key, 5)
|
43
|
-
@mock.persist(@key)
|
44
|
-
Time.stub(:now).and_return(@now + 5)
|
45
|
-
@mock.get(@key).should_not be_nil
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,86 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#pexpire(key, ms)' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:pexpire'
|
6
|
-
@redises.set(@key, 'spork')
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'returns true for a key that exists' do
|
10
|
-
@redises.pexpire(@key, 1).should == true
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'returns false for a key that does not exist' do
|
14
|
-
@redises.pexpire('mock-redis-test:nonesuch', 1).should == false
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'removes a key immediately when ms==0' do
|
18
|
-
@redises.pexpire(@key, 0)
|
19
|
-
@redises.get(@key).should be_nil
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'raises an error if ms is bogus' do
|
23
|
-
lambda do
|
24
|
-
@redises.pexpire(@key, 'a couple minutes or so')
|
25
|
-
end.should raise_error(Redis::CommandError)
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'stringifies key' do
|
29
|
-
@redises.pexpire(@key.to_sym, 9).should == true
|
30
|
-
end
|
31
|
-
|
32
|
-
context '[mock only]' do
|
33
|
-
# These are mock-only since we can't actually manipulate time in
|
34
|
-
# the real Redis.
|
35
|
-
|
36
|
-
before(:all) do
|
37
|
-
@mock = @redises.mock
|
38
|
-
end
|
39
|
-
|
40
|
-
before do
|
41
|
-
@now = Time.now.round
|
42
|
-
Time.stub(:now).and_return(@now)
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'removes keys after enough time has passed' do
|
46
|
-
@mock.pexpire(@key, 5)
|
47
|
-
Time.stub(:now).and_return(@now + Rational(6, 1000))
|
48
|
-
@mock.get(@key).should be_nil
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'updates an existing pexpire time' do
|
52
|
-
@mock.pexpire(@key, 5)
|
53
|
-
@mock.pexpire(@key, 6)
|
54
|
-
|
55
|
-
Time.stub(:now).and_return(@now + Rational(5, 1000))
|
56
|
-
@mock.get(@key).should_not be_nil
|
57
|
-
end
|
58
|
-
|
59
|
-
context 'expirations on a deleted key' do
|
60
|
-
before { @mock.del(@key) }
|
61
|
-
|
62
|
-
it 'cleans up the expiration once the key is gone (string)' do
|
63
|
-
@mock.set(@key, 'string')
|
64
|
-
@mock.pexpire(@key, 2)
|
65
|
-
@mock.del(@key)
|
66
|
-
@mock.set(@key, 'string')
|
67
|
-
|
68
|
-
Time.stub(:now).and_return(@now + 0.003)
|
69
|
-
|
70
|
-
@mock.get(@key).should_not be_nil
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'cleans up the expiration once the key is gone (list)' do
|
74
|
-
@mock.rpush(@key, 'coconuts')
|
75
|
-
@mock.pexpire(@key, 2)
|
76
|
-
@mock.rpop(@key)
|
77
|
-
|
78
|
-
@mock.rpush(@key, 'coconuts')
|
79
|
-
|
80
|
-
Time.stub(:now).and_return(@now + 0.003)
|
81
|
-
|
82
|
-
@mock.lindex(@key, 0).should_not be_nil
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#pexpireat(key, timestamp_ms)' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:pexpireat'
|
6
|
-
@redises.set(@key, 'spork')
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'returns true for a key that exists' do
|
10
|
-
@redises.pexpireat(@key, (Time.now.to_f * 1000).to_i + 1).should == true
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'returns false for a key that does not exist' do
|
14
|
-
@redises.pexpireat('mock-redis-test:nonesuch',
|
15
|
-
(Time.now.to_f * 1000).to_i + 1).should == false
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'removes a key immediately when timestamp is now' do
|
19
|
-
@redises.pexpireat(@key, (Time.now.to_f * 1000).to_i)
|
20
|
-
@redises.get(@key).should be_nil
|
21
|
-
end
|
22
|
-
|
23
|
-
it "raises an error if you don't give it a Unix timestamp" do
|
24
|
-
lambda do
|
25
|
-
@redises.pexpireat(@key, Time.now) # oops, forgot .to_i
|
26
|
-
end.should raise_error(Redis::CommandError)
|
27
|
-
end
|
28
|
-
|
29
|
-
context '[mock only]' do
|
30
|
-
# These are mock-only since we can't actually manipulate time in
|
31
|
-
# the real Redis.
|
32
|
-
|
33
|
-
before(:all) do
|
34
|
-
@mock = @redises.mock
|
35
|
-
end
|
36
|
-
|
37
|
-
before do
|
38
|
-
@now = Time.now
|
39
|
-
Time.stub(:now).and_return(@now)
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'removes keys after enough time has passed' do
|
43
|
-
@mock.pexpireat(@key, (@now.to_f * 1000).to_i + 5)
|
44
|
-
Time.stub(:now).and_return(@now + 0.006)
|
45
|
-
@mock.get(@key).should be_nil
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|