mock_redis 0.36.0 → 0.37.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 +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
@@ -1,114 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#pipelined' do
|
4
|
-
it 'yields to its block' do
|
5
|
-
res = false
|
6
|
-
@redises.pipelined do
|
7
|
-
res = true
|
8
|
-
end
|
9
|
-
res.should == true
|
10
|
-
end
|
11
|
-
|
12
|
-
context 'with a few added data' do
|
13
|
-
let(:key1) { 'hello' }
|
14
|
-
let(:key2) { 'world' }
|
15
|
-
let(:value1) { 'foo' }
|
16
|
-
let(:value2) { 'bar' }
|
17
|
-
|
18
|
-
before do
|
19
|
-
@redises.set key1, value1
|
20
|
-
@redises.set key2, value2
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'returns results of pipelined operations' do
|
24
|
-
results = @redises.pipelined do |redis|
|
25
|
-
redis.get key1
|
26
|
-
redis.get key2
|
27
|
-
end
|
28
|
-
|
29
|
-
results.should == [value1, value2]
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'returns futures' do
|
33
|
-
future = nil
|
34
|
-
|
35
|
-
@redises.mock.pipelined do |redis|
|
36
|
-
future = redis.get key1
|
37
|
-
end
|
38
|
-
|
39
|
-
future.class.should be MockRedis::Future
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
context 'with pipelined operations returning array replies' do
|
44
|
-
let(:key1) { 'colors' }
|
45
|
-
let(:key2) { 'seasons' }
|
46
|
-
let(:value1) { %w[blue yellow] }
|
47
|
-
let(:value2) { %w[summer winter] }
|
48
|
-
|
49
|
-
before do
|
50
|
-
@redises.rpush(key1, value1)
|
51
|
-
@redises.rpush(key2, value2)
|
52
|
-
end
|
53
|
-
|
54
|
-
after do
|
55
|
-
@redises.del key1
|
56
|
-
@redises.del key2
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'returns an array of the array replies' do
|
60
|
-
results = @redises.pipelined do |_redis|
|
61
|
-
@redises.lrange(key1, 0, -1)
|
62
|
-
@redises.lrange(key2, 0, -1)
|
63
|
-
end
|
64
|
-
|
65
|
-
results.should == [value1, value2]
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
context 'with redis time return value' do
|
70
|
-
let(:time_stub) { double 'Time', :now => Time.new(2019, 1, 2, 3, 4, 6, '+00:00') }
|
71
|
-
let(:options) { { :time_class => time_stub } }
|
72
|
-
|
73
|
-
subject { MockRedis.new(options) }
|
74
|
-
|
75
|
-
it 'returns the time value' do
|
76
|
-
subject.set('foo', 'bar')
|
77
|
-
|
78
|
-
results = subject.pipelined do
|
79
|
-
subject.get('foo')
|
80
|
-
subject.host # defined on MockRedis, so not captured
|
81
|
-
subject.time
|
82
|
-
subject.echo('baz')
|
83
|
-
end
|
84
|
-
|
85
|
-
expect(results).to eq(['bar', [1_546_398_246, 0], 'baz'])
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
context 'with nested pipelines' do
|
90
|
-
let(:key1) { 'hello' }
|
91
|
-
let(:key2) { 'world' }
|
92
|
-
let(:value1) { 'foo' }
|
93
|
-
let(:value2) { 'bar' }
|
94
|
-
|
95
|
-
before do
|
96
|
-
@redises.set key1, value1
|
97
|
-
@redises.set key2, value2
|
98
|
-
end
|
99
|
-
|
100
|
-
it 'returns results of the nested pipelines' do
|
101
|
-
results = @redises.pipelined do |pr1|
|
102
|
-
pr1.pipelined do |pr2|
|
103
|
-
pr2.get key1
|
104
|
-
end
|
105
|
-
|
106
|
-
pr1.pipelined do |pr2|
|
107
|
-
pr2.get key2
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
results.should == [value1, value2]
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#psetex(key, miliseconds, value)' do
|
4
|
-
before { @key = 'mock-redis-test:setex' }
|
5
|
-
|
6
|
-
it "responds with 'OK'" do
|
7
|
-
@redises.psetex(@key, 10, 'value').should == 'OK'
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'sets the value' do
|
11
|
-
@redises.psetex(@key, 10_000, 'value')
|
12
|
-
@redises.get(@key).should == 'value'
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'sets the expiration time' do
|
16
|
-
@redises.psetex(@key, 10_000, 'value')
|
17
|
-
|
18
|
-
# no guarantee these are the same
|
19
|
-
@redises.real.ttl(@key).should > 0
|
20
|
-
@redises.mock.ttl(@key).should > 0
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'converts time correctly' do
|
24
|
-
@redises.psetex(@key, 10_000_000, 'value')
|
25
|
-
|
26
|
-
@redises.mock.ttl(@key).should > 9_000
|
27
|
-
end
|
28
|
-
|
29
|
-
context 'when expiration time is zero' do
|
30
|
-
it 'raises Redis::CommandError' do
|
31
|
-
expect do
|
32
|
-
@redises.psetex(@key, 0, 'value')
|
33
|
-
end.to raise_error(Redis::CommandError, 'ERR invalid expire time in psetex')
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
context 'when expiration time is negative' do
|
38
|
-
it 'raises Redis::CommandError' do
|
39
|
-
expect do
|
40
|
-
@redises.psetex(@key, -2, 'value')
|
41
|
-
end.to raise_error(Redis::CommandError, 'ERR invalid expire time in psetex')
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
data/spec/commands/pttl_spec.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#pttl(key)' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:persist'
|
6
|
-
@redises.set(@key, 'spork')
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'returns -1 for a key with no expiration' do
|
10
|
-
@redises.pttl(@key).should == -1
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'returns -2 for a key that does not exist' do
|
14
|
-
@redises.pttl('mock-redis-test:nonesuch').should == -2
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'stringifies key' do
|
18
|
-
@redises.expire(@key, 8)
|
19
|
-
# Don't check against Redis since millisecond timing differences are likely
|
20
|
-
@redises.send_without_checking(:pttl, @key.to_sym).should > 0
|
21
|
-
end
|
22
|
-
|
23
|
-
context '[mock only]' do
|
24
|
-
# These are mock-only since we can't actually manipulate time in
|
25
|
-
# the real Redis.
|
26
|
-
|
27
|
-
before(:all) do
|
28
|
-
@mock = @redises.mock
|
29
|
-
end
|
30
|
-
|
31
|
-
before do
|
32
|
-
@now = Time.now.round
|
33
|
-
Time.stub(:now).and_return(@now)
|
34
|
-
end
|
35
|
-
|
36
|
-
it "gives you the key's remaining lifespan in milliseconds" do
|
37
|
-
@mock.expire(@key, 5)
|
38
|
-
@mock.pttl(@key).should == 5000
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
data/spec/commands/quit_spec.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#randomkey [mock only]' do
|
4
|
-
before { @mock = @redises.mock }
|
5
|
-
|
6
|
-
it 'finds a random key' do
|
7
|
-
@keys = ['mock-redis-test:1', 'mock-redis-test:2', 'mock-redis-test:3']
|
8
|
-
|
9
|
-
@keys.each do |k|
|
10
|
-
@mock.set(k, 1)
|
11
|
-
end
|
12
|
-
|
13
|
-
@keys.should include(@mock.randomkey)
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'returns nil when there are no keys' do
|
17
|
-
@mock.keys('*').each { |k| @mock.del(k) }
|
18
|
-
@mock.randomkey.should be_nil
|
19
|
-
end
|
20
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#rename(key, newkey)' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:rename:key'
|
6
|
-
@newkey = 'mock-redis-test:rename:newkey'
|
7
|
-
|
8
|
-
@redises.set(@key, 'oof')
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'responds with "OK"' do
|
12
|
-
@redises.rename(@key, @newkey).should == 'OK'
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'moves the data' do
|
16
|
-
@redises.rename(@key, @newkey)
|
17
|
-
@redises.get(@newkey).should == 'oof'
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'raises an error when the source key is nonexistant' do
|
21
|
-
@redises.del(@key)
|
22
|
-
lambda do
|
23
|
-
@redises.rename(@key, @newkey)
|
24
|
-
end.should raise_error(Redis::CommandError)
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'responds with "OK" when key == newkey' do
|
28
|
-
@redises.rename(@key, @key).should == 'OK'
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'overwrites any existing value at newkey' do
|
32
|
-
@redises.set(@newkey, 'rab')
|
33
|
-
@redises.rename(@key, @newkey)
|
34
|
-
@redises.get(@newkey).should == 'oof'
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'keeps expiration' do
|
38
|
-
@redises.expire(@key, 1000)
|
39
|
-
@redises.rename(@key, @newkey)
|
40
|
-
@redises.ttl(@newkey).should be > 0
|
41
|
-
end
|
42
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#renamenx(key, newkey)' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:renamenx:key'
|
6
|
-
@newkey = 'mock-redis-test:renamenx:newkey'
|
7
|
-
|
8
|
-
@redises.set(@key, 'oof')
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'responds with true when newkey does not exist' do
|
12
|
-
@redises.renamenx(@key, @newkey).should == true
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'responds with false when newkey exists' do
|
16
|
-
@redises.set(@newkey, 'monkey')
|
17
|
-
@redises.renamenx(@key, @newkey).should == false
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'moves the data' do
|
21
|
-
@redises.renamenx(@key, @newkey)
|
22
|
-
@redises.get(@newkey).should == 'oof'
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'raises an error when the source key is nonexistant' do
|
26
|
-
@redises.del(@key)
|
27
|
-
lambda do
|
28
|
-
@redises.rename(@key, @newkey)
|
29
|
-
end.should raise_error(Redis::CommandError)
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'returns false when key == newkey' do
|
33
|
-
@redises.renamenx(@key, @key).should == false
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'leaves any existing value at newkey alone' do
|
37
|
-
@redises.set(@newkey, 'rab')
|
38
|
-
@redises.renamenx(@key, @newkey)
|
39
|
-
@redises.get(@newkey).should == 'rab'
|
40
|
-
end
|
41
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#restore(key, ttl, value)' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:45794'
|
6
|
-
@src = MockRedis.new
|
7
|
-
@src.set(@key, '123')
|
8
|
-
@dumped_value = @src.dump(@key)
|
9
|
-
@dst = MockRedis.new
|
10
|
-
@now = Time.now.round
|
11
|
-
Time.stub(:now).and_return(@now)
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'allows dump/restoring values between two redis instances' do
|
15
|
-
expect(@dst.restore(@key, 0, @dumped_value)).to eq('OK')
|
16
|
-
expect(@dst.get(@key)).to eq('123')
|
17
|
-
expect(@dst.pttl(@key)).to eq(-1)
|
18
|
-
end
|
19
|
-
|
20
|
-
context 'when the key being restored to already exists' do
|
21
|
-
before do
|
22
|
-
@dst.set(@key, '456')
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'raises an error by default' do
|
26
|
-
expect { @dst.restore(@key, 0, @dumped_value) }.to raise_error(Redis::CommandError)
|
27
|
-
expect(@dst.get(@key)).to eq('456')
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'allows replacing the key if replace==true' do
|
31
|
-
expect(@dst.restore(@key, 0, @dumped_value, replace: true)).to eq('OK')
|
32
|
-
expect(@dst.get(@key)).to eq('123')
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'sets ttl in ms' do
|
37
|
-
@dst.restore(@key, 500, @dumped_value)
|
38
|
-
expect(@dst.pttl(@key)).to eq(500)
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'can dump/restore more complex data types' do
|
42
|
-
key = 'a_hash'
|
43
|
-
@src.mapped_hmset(key, foo: 'bar')
|
44
|
-
@dst.restore(key, 0, @src.dump(key))
|
45
|
-
expect(@dst.hgetall(key)).to eq('foo' => 'bar')
|
46
|
-
end
|
47
|
-
end
|
data/spec/commands/rpop_spec.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#rpop(key)' do
|
4
|
-
before { @key = 'mock-redis-test:43093' }
|
5
|
-
|
6
|
-
it 'returns and removes the first element of a list' do
|
7
|
-
@redises.lpush(@key, 1)
|
8
|
-
@redises.lpush(@key, 2)
|
9
|
-
|
10
|
-
@redises.rpop(@key).should == '1'
|
11
|
-
|
12
|
-
@redises.llen(@key).should == 1
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'returns nil if the list is empty' do
|
16
|
-
@redises.lpush(@key, 'foo')
|
17
|
-
@redises.rpop(@key)
|
18
|
-
|
19
|
-
@redises.rpop(@key).should be_nil
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'returns nil for nonexistent values' do
|
23
|
-
@redises.rpop(@key).should be_nil
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'removes empty lists' do
|
27
|
-
@redises.lpush(@key, 'foo')
|
28
|
-
@redises.rpop(@key)
|
29
|
-
|
30
|
-
@redises.get(@key).should be_nil
|
31
|
-
end
|
32
|
-
|
33
|
-
let(:default_error) { RedisMultiplexer::MismatchedResponse }
|
34
|
-
it_should_behave_like 'a list-only command'
|
35
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#rpoplpush(source, destination)' do
|
4
|
-
before do
|
5
|
-
@list1 = 'mock-redis-test:rpoplpush-list1'
|
6
|
-
@list2 = 'mock-redis-test:rpoplpush-list2'
|
7
|
-
|
8
|
-
@redises.lpush(@list1, 'b')
|
9
|
-
@redises.lpush(@list1, 'a')
|
10
|
-
|
11
|
-
@redises.lpush(@list2, 'y')
|
12
|
-
@redises.lpush(@list2, 'x')
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'returns the value moved' do
|
16
|
-
@redises.rpoplpush(@list1, @list2).should == 'b'
|
17
|
-
end
|
18
|
-
|
19
|
-
it "returns false and doesn't append if source empty" do
|
20
|
-
@redises.rpoplpush('empty', @list1).should be_nil
|
21
|
-
@redises.lrange(@list1, 0, -1).should == %w[a b]
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'takes the last element of destination and prepends it to source' do
|
25
|
-
@redises.rpoplpush(@list1, @list2)
|
26
|
-
|
27
|
-
@redises.lrange(@list1, 0, -1).should == %w[a]
|
28
|
-
@redises.lrange(@list2, 0, -1).should == %w[b x y]
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'rotates a list when source and destination are the same' do
|
32
|
-
@redises.rpoplpush(@list1, @list1)
|
33
|
-
@redises.lrange(@list1, 0, -1).should == %w[b a]
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'removes empty lists' do
|
37
|
-
@redises.llen(@list1).times { @redises.rpoplpush(@list1, @list2) }
|
38
|
-
@redises.get(@list1).should be_nil
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'raises an error for non-list source value' do
|
42
|
-
@redises.set(@list1, 'string value')
|
43
|
-
|
44
|
-
lambda do
|
45
|
-
@redises.rpoplpush(@list1, @list2)
|
46
|
-
end.should raise_error(Redis::CommandError)
|
47
|
-
end
|
48
|
-
|
49
|
-
it_should_behave_like 'a list-only command'
|
50
|
-
end
|
data/spec/commands/rpush_spec.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#rpush(key)' do
|
4
|
-
before { @key = "mock-redis-test:#{__FILE__}" }
|
5
|
-
|
6
|
-
it 'returns the new size of the list' do
|
7
|
-
@redises.rpush(@key, 'X').should == 1
|
8
|
-
@redises.rpush(@key, 'X').should == 2
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'creates a new list when run against a nonexistent key' do
|
12
|
-
@redises.rpush(@key, 'value')
|
13
|
-
@redises.llen(@key).should == 1
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'appends items to the list' do
|
17
|
-
@redises.rpush(@key, 'bert')
|
18
|
-
@redises.rpush(@key, 'ernie')
|
19
|
-
|
20
|
-
@redises.lindex(@key, 0).should == 'bert'
|
21
|
-
@redises.lindex(@key, 1).should == 'ernie'
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'stores values as strings' do
|
25
|
-
@redises.rpush(@key, 1)
|
26
|
-
@redises.lindex(@key, 0).should == '1'
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'supports a variable number of arguments' do
|
30
|
-
@redises.rpush(@key, [1, 2, 3]).should == 3
|
31
|
-
@redises.lindex(@key, 0).should == '1'
|
32
|
-
@redises.lindex(@key, 1).should == '2'
|
33
|
-
@redises.lindex(@key, 2).should == '3'
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'raises an error if an empty array is given' do
|
37
|
-
lambda do
|
38
|
-
@redises.rpush(@key, [])
|
39
|
-
end.should raise_error(Redis::CommandError)
|
40
|
-
end
|
41
|
-
|
42
|
-
it_should_behave_like 'a list-only command'
|
43
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#rpushx(key, value)' do
|
4
|
-
before { @key = 'mock-redis-test:92925' }
|
5
|
-
|
6
|
-
it 'returns the new size of the list' do
|
7
|
-
@redises.lpush(@key, 'X')
|
8
|
-
|
9
|
-
@redises.rpushx(@key, 'X').should == 2
|
10
|
-
@redises.rpushx(@key, 'X').should == 3
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'does nothing when run against a nonexistent key' do
|
14
|
-
@redises.rpushx(@key, 'value')
|
15
|
-
@redises.get(@key).should be_nil
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'appends items to the list' do
|
19
|
-
@redises.lpush(@key, 'bert')
|
20
|
-
@redises.rpushx(@key, 'ernie')
|
21
|
-
|
22
|
-
@redises.lindex(@key, 0).should == 'bert'
|
23
|
-
@redises.lindex(@key, 1).should == 'ernie'
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'stores values as strings' do
|
27
|
-
@redises.rpush(@key, 1)
|
28
|
-
@redises.rpushx(@key, 2)
|
29
|
-
@redises.lindex(@key, 1).should == '2'
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'raises an error if an empty array is given' do
|
33
|
-
@redises.lpush(@key, 'X')
|
34
|
-
lambda do
|
35
|
-
@redises.rpushx(@key, [])
|
36
|
-
end.should raise_error(Redis::CommandError)
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'stores multiple items if an array of more than one item is given' do
|
40
|
-
@redises.lpush(@key, 'X')
|
41
|
-
@redises.rpushx(@key, [1, 2]).should == 3
|
42
|
-
@redises.lrange(@key, 0, -1).should == %w[X 1 2]
|
43
|
-
end
|
44
|
-
|
45
|
-
it_should_behave_like 'a list-only command'
|
46
|
-
end
|
data/spec/commands/sadd_spec.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#sadd(key, member)' do
|
4
|
-
before { @key = 'mock-redis-test:sadd' }
|
5
|
-
|
6
|
-
it 'returns true if the set did not already contain member' do
|
7
|
-
@redises.sadd(@key, 1).should == true
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'returns false if the set did already contain member' do
|
11
|
-
@redises.sadd(@key, 1)
|
12
|
-
@redises.sadd(@key, 1).should == false
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'adds member to the set' do
|
16
|
-
@redises.sadd(@key, 1)
|
17
|
-
@redises.sadd(@key, 2)
|
18
|
-
@redises.smembers(@key).should == %w[2 1]
|
19
|
-
end
|
20
|
-
|
21
|
-
describe 'adding multiple members at once' do
|
22
|
-
it 'returns the amount of added members' do
|
23
|
-
@redises.sadd(@key, [1, 2, 3]).should == 3
|
24
|
-
@redises.sadd(@key, [1, 2, 3, 4]).should == 1
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'returns 0 if the set did already contain all members' do
|
28
|
-
@redises.sadd(@key, [1, 2, 3])
|
29
|
-
@redises.sadd(@key, [1, 2, 3]).should == 0
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'adds the members to the set' do
|
33
|
-
@redises.sadd(@key, [1, 2, 3])
|
34
|
-
@redises.smembers(@key).should == %w[1 2 3]
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'raises an error if an empty array is given' do
|
38
|
-
lambda do
|
39
|
-
@redises.sadd(@key, [])
|
40
|
-
end.should raise_error(Redis::CommandError)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
it_should_behave_like 'a set-only command'
|
45
|
-
end
|
data/spec/commands/save_spec.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#scan_each' do
|
4
|
-
subject { MockRedis::Database.new(self) }
|
5
|
-
|
6
|
-
let(:match) { '*' }
|
7
|
-
|
8
|
-
before do
|
9
|
-
allow(subject).to receive_message_chain(:data, :keys).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
|
-
expect(subject.scan_each.to_a).to be_empty
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
context 'when keys are found' do
|
21
|
-
context 'when no match filter is supplied' do
|
22
|
-
let(:collection) { Array.new(20) { |i| "mock:key#{i}" } }
|
23
|
-
|
24
|
-
it 'iterates over each item in the collection' do
|
25
|
-
expect(subject.scan_each.to_a).to match_array(collection)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
context 'when giving a custom match filter' do
|
30
|
-
let(:match) { 'mock:key*' }
|
31
|
-
let(:collection) { %w[mock:key mock:key2 mock:otherkey] }
|
32
|
-
let(:expected) { %w[mock:key mock:key2] }
|
33
|
-
|
34
|
-
it 'iterates over each item in the filtered collection' do
|
35
|
-
expect(subject.scan_each(match: match).to_a).to match_array(expected)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|