mock_redis 0.35.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 +15 -0
- data/README.md +3 -3
- data/lib/mock_redis/database.rb +1 -1
- data/lib/mock_redis/hash_methods.rb +1 -1
- data/lib/mock_redis/list_methods.rb +37 -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 +12 -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 +4 -4
- data/lib/mock_redis.rb +1 -2
- metadata +19 -354
- 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/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/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/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 -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 -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/brpop_spec.rb
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#brpop(key [, key, ...,], timeout)' do
|
4
|
-
before do
|
5
|
-
@list1 = 'mock-redis-test:brpop1'
|
6
|
-
@list2 = 'mock-redis-test:brpop2'
|
7
|
-
|
8
|
-
@redises.rpush(@list1, 'one')
|
9
|
-
@redises.rpush(@list1, 'two')
|
10
|
-
|
11
|
-
@redises.rpush(@list2, 'ten')
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'returns [first-nonempty-list, popped-value]' do
|
15
|
-
@redises.brpop(@list1, @list2).should == [@list1, 'two']
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'pops that value off the list' do
|
19
|
-
@redises.brpop(@list1, @list2)
|
20
|
-
@redises.brpop(@list1, @list2)
|
21
|
-
@redises.brpop(@list1, @list2).should == [@list2, 'ten']
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'ignores empty keys' do
|
25
|
-
@redises.brpop('mock-redis-test:not-here', @list1).should ==
|
26
|
-
[@list1, 'two']
|
27
|
-
end
|
28
|
-
|
29
|
-
# TODO: Not sure how redis-rb is handling this but they're not raising an error
|
30
|
-
# it 'raises an error on subsecond timeouts' do
|
31
|
-
# lambda do
|
32
|
-
# @redises.brpop(@list1, @list2, :timeout => 0.5)
|
33
|
-
# end.should raise_error(Redis::CommandError)
|
34
|
-
# end
|
35
|
-
|
36
|
-
it 'raises an error on negative timeout' do
|
37
|
-
lambda do
|
38
|
-
@redises.brpop(@list1, @list2, :timeout => -1)
|
39
|
-
end.should raise_error(Redis::CommandError)
|
40
|
-
end
|
41
|
-
|
42
|
-
it_should_behave_like 'a list-only command'
|
43
|
-
|
44
|
-
context '[mock only]' do
|
45
|
-
it 'ignores positive timeouts and returns nil' do
|
46
|
-
@redises.mock.brpop('mock-redis-test:not-here', :timeout => 1).should be_nil
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'ignores positive legacy timeouts and returns nil' do
|
50
|
-
@redises.mock.brpop('mock-redis-test:not-here', 1).should be_nil
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'raises WouldBlock on zero timeout (no blocking in the mock)' do
|
54
|
-
lambda do
|
55
|
-
@redises.mock.brpop('mock-redis-test:not-here', :timeout => 0)
|
56
|
-
end.should raise_error(MockRedis::WouldBlock)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe '#brpoplpush(source, destination, timeout)' do
|
6
|
-
before do
|
7
|
-
@list1 = 'mock-redis-test:brpoplpush1'
|
8
|
-
@list2 = 'mock-redis-test:brpoplpush2'
|
9
|
-
|
10
|
-
@redises.rpush(@list1, 'A')
|
11
|
-
@redises.rpush(@list1, 'B')
|
12
|
-
|
13
|
-
@redises.rpush(@list2, 'alpha')
|
14
|
-
@redises.rpush(@list2, 'beta')
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'takes the last element of source and prepends it to destination' do
|
18
|
-
@redises.brpoplpush(@list1, @list2)
|
19
|
-
@redises.lrange(@list1, 0, -1).should == %w[A]
|
20
|
-
@redises.lrange(@list2, 0, -1).should == %w[B alpha beta]
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'returns the moved element' do
|
24
|
-
@redises.brpoplpush(@list1, @list2).should == 'B'
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'raises an error on negative timeout' do
|
28
|
-
lambda do
|
29
|
-
@redises.brpoplpush(@list1, @list2, :timeout => -1)
|
30
|
-
end.should raise_error(Redis::CommandError)
|
31
|
-
end
|
32
|
-
|
33
|
-
it_should_behave_like 'a list-only command'
|
34
|
-
|
35
|
-
context '[mock only]' do
|
36
|
-
it 'ignores positive timeouts and returns nil' do
|
37
|
-
@redises.mock.brpoplpush('mock-redis-test:not-here', @list1, :timeout => 1).
|
38
|
-
should be_nil
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'ignores positive legacy timeouts and returns nil' do
|
42
|
-
@redises.mock.brpoplpush('mock-redis-test:not-here', @list1, 1).
|
43
|
-
should be_nil
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'raises WouldBlock on zero timeout (no blocking in the mock)' do
|
47
|
-
lambda do
|
48
|
-
@redises.mock.brpoplpush('mock-redis-test:not-here', @list1, :timeout => 0)
|
49
|
-
end.should raise_error(MockRedis::WouldBlock)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#connection' do
|
4
|
-
let(:redis) { @redises.mock }
|
5
|
-
|
6
|
-
it 'returns the correct values' do
|
7
|
-
redis.connection.should == {
|
8
|
-
:host => '127.0.0.1',
|
9
|
-
:port => 6379,
|
10
|
-
:db => 0,
|
11
|
-
:id => 'redis://127.0.0.1:6379/0',
|
12
|
-
:location => '127.0.0.1:6379'
|
13
|
-
}
|
14
|
-
end
|
15
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#dbsize [mock only]' do
|
4
|
-
# mock only since we can't guarantee that the real Redis is empty
|
5
|
-
before { @mock = @redises.mock }
|
6
|
-
|
7
|
-
it 'returns 0 for an empty DB' do
|
8
|
-
@mock.dbsize.should == 0
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'returns the number of keys in the DB' do
|
12
|
-
@mock.set('foo', 1)
|
13
|
-
@mock.lpush('bar', 2)
|
14
|
-
@mock.hset('baz', 3, 4)
|
15
|
-
|
16
|
-
@mock.dbsize.should == 3
|
17
|
-
end
|
18
|
-
end
|
data/spec/commands/decr_spec.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#decr(key)' do
|
4
|
-
before { @key = 'mock-redis-test:46895' }
|
5
|
-
|
6
|
-
it 'returns the value after the decrement' do
|
7
|
-
@redises.set(@key, 2)
|
8
|
-
@redises.decr(@key).should == 1
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'treats a missing key like 0' do
|
12
|
-
@redises.decr(@key).should == -1
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'decrements negative numbers' do
|
16
|
-
@redises.set(@key, -10)
|
17
|
-
@redises.decr(@key).should == -11
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'works multiple times' do
|
21
|
-
@redises.decr(@key).should == -1
|
22
|
-
@redises.decr(@key).should == -2
|
23
|
-
@redises.decr(@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, 'minus one')
|
28
|
-
lambda do
|
29
|
-
@redises.decr(@key)
|
30
|
-
end.should raise_error(Redis::CommandError)
|
31
|
-
end
|
32
|
-
|
33
|
-
it_should_behave_like 'a string-only command'
|
34
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#decrby(key, decrement)' do
|
4
|
-
before { @key = 'mock-redis-test:43650' }
|
5
|
-
|
6
|
-
it 'returns the value after the decrement' do
|
7
|
-
@redises.set(@key, 4)
|
8
|
-
@redises.decrby(@key, 2).should == 2
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'treats a missing key like 0' do
|
12
|
-
@redises.decrby(@key, 2).should == -2
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'decrements negative numbers' do
|
16
|
-
@redises.set(@key, -10)
|
17
|
-
@redises.decrby(@key, 2).should == -12
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'works multiple times' do
|
21
|
-
@redises.decrby(@key, 2).should == -2
|
22
|
-
@redises.decrby(@key, 2).should == -4
|
23
|
-
@redises.decrby(@key, 2).should == -6
|
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.decrby(@key, 1)
|
30
|
-
end.should raise_error(Redis::CommandError)
|
31
|
-
end
|
32
|
-
|
33
|
-
it_should_behave_like 'a string-only command'
|
34
|
-
end
|
data/spec/commands/del_spec.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#del(key [, key, ...])' do
|
4
|
-
before :all do
|
5
|
-
sleep 1 - (Time.now.to_f % 1)
|
6
|
-
end
|
7
|
-
|
8
|
-
before :each do
|
9
|
-
# TODO: Redis appears to be returning a timestamp a few seconds in the future
|
10
|
-
# so we're ignoring the last 5 digits (time in milliseconds)
|
11
|
-
@redises._gsub(/\d{5}-\d/, '...-.')
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'returns the number of keys deleted' do
|
15
|
-
@redises.set('mock-redis-test:1', 1)
|
16
|
-
@redises.set('mock-redis-test:2', 1)
|
17
|
-
|
18
|
-
@redises.del(
|
19
|
-
'mock-redis-test:1',
|
20
|
-
'mock-redis-test:2',
|
21
|
-
'mock-redis-test:other'
|
22
|
-
).should == 2
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'actually removes the key' do
|
26
|
-
@redises.set('mock-redis-test:1', 1)
|
27
|
-
@redises.del('mock-redis-test:1')
|
28
|
-
|
29
|
-
@redises.get('mock-redis-test:1').should be_nil
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'accepts an array of keys' do
|
33
|
-
@redises.set('mock-redis-test:1', 1)
|
34
|
-
@redises.set('mock-redis-test:2', 2)
|
35
|
-
|
36
|
-
@redises.del(%w[mock-redis-test:1 mock-redis-test:2])
|
37
|
-
|
38
|
-
@redises.get('mock-redis-test:1').should be_nil
|
39
|
-
@redises.get('mock-redis-test:2').should be_nil
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'raises an error if an empty array is given' do
|
43
|
-
expect { @redises.del [] }.not_to raise_error Redis::CommandError
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'removes a stream key' do
|
47
|
-
@redises.xadd('mock-redis-stream', { key: 'value' }, maxlen: 0)
|
48
|
-
expect(@redises.exists?('mock-redis-stream')).to eq true
|
49
|
-
@redises.del('mock-redis-stream')
|
50
|
-
expect(@redises.exists?('mock-redis-stream')).to eq false
|
51
|
-
end
|
52
|
-
end
|
data/spec/commands/dump_spec.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#dump(key)' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:45794'
|
6
|
-
# These are mock-only, since our dump/restore implementations
|
7
|
-
# aren't compatible with real redis.
|
8
|
-
@mock = @redises.mock
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'returns nil for keys that do not exist' do
|
12
|
-
@mock.dump(@key).should be_nil
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'returns a serialized value for keys that do exist' do
|
16
|
-
@mock.set(@key, '2')
|
17
|
-
@mock.dump(@key).should == Marshal.dump('2')
|
18
|
-
end
|
19
|
-
end
|
data/spec/commands/echo_spec.rb
DELETED
data/spec/commands/eval_spec.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#exists(*keys)' do
|
4
|
-
before { @key1 = 'mock-redis-test:exists1' }
|
5
|
-
before { @key2 = 'mock-redis-test:exists2' }
|
6
|
-
|
7
|
-
it 'returns 0 for keys that do not exist' do
|
8
|
-
@redises.exists(@key1).should == 0
|
9
|
-
@redises.exists(@key1, @key2).should == 0
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'returns 1 for keys that do exist' do
|
13
|
-
@redises.set(@key1, 1)
|
14
|
-
@redises.exists(@key1).should == 1
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'returns the count of all keys that exist' do
|
18
|
-
@redises.set(@key1, 1)
|
19
|
-
@redises.set(@key2, 1)
|
20
|
-
@redises.exists(@key1, @key2).should == 2
|
21
|
-
@redises.exists(@key1, @key2, 'does-not-exist').should == 2
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe '#exists?(*keys)' do
|
26
|
-
before { @key1 = 'mock-redis-test:exists1' }
|
27
|
-
before { @key2 = 'mock-redis-test:exists2' }
|
28
|
-
|
29
|
-
it 'returns false for keys that do not exist' do
|
30
|
-
@redises.exists?(@key1).should == false
|
31
|
-
@redises.exists?(@key1, @key2).should == false
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'returns true for keys that do exist' do
|
35
|
-
@redises.set(@key1, 1)
|
36
|
-
@redises.exists?(@key1).should == true
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'returns true if any keys exist' do
|
40
|
-
@redises.set(@key2, 1)
|
41
|
-
@redises.exists?(@key1, @key2).should == true
|
42
|
-
end
|
43
|
-
end
|
@@ -1,111 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#expire(key, seconds)' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:expire'
|
6
|
-
@redises.set(@key, 'spork')
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'returns true for a key that exists' do
|
10
|
-
@redises.expire(@key, 1).should == true
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'returns false for a key that does not exist' do
|
14
|
-
@redises.expire('mock-redis-test:nonesuch', 1).should == false
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'removes a key immediately when seconds==0' do
|
18
|
-
@redises.expire(@key, 0)
|
19
|
-
@redises.get(@key).should be_nil
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'raises an error if seconds is bogus' do
|
23
|
-
lambda do
|
24
|
-
@redises.expire(@key, 'a couple minutes or so')
|
25
|
-
end.should raise_error(Redis::CommandError)
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'stringifies key' do
|
29
|
-
@redises.expire(@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
|
42
|
-
Time.stub(:now).and_return(@now)
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'removes keys after enough time has passed' do
|
46
|
-
@mock.expire(@key, 5)
|
47
|
-
Time.stub(:now).and_return(@now + 5)
|
48
|
-
@mock.get(@key).should be_nil
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'updates an existing expire time' do
|
52
|
-
@mock.expire(@key, 5)
|
53
|
-
@mock.expire(@key, 6)
|
54
|
-
|
55
|
-
Time.stub(:now).and_return(@now + 5)
|
56
|
-
@mock.get(@key).should_not be_nil
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'has millisecond precision' do
|
60
|
-
@now = Time.at(@now.to_i + 0.5)
|
61
|
-
Time.stub(:now).and_return(@now)
|
62
|
-
@mock.expire(@key, 5)
|
63
|
-
Time.stub(:now).and_return(@now + 4.9)
|
64
|
-
@mock.get(@key).should_not be_nil
|
65
|
-
end
|
66
|
-
|
67
|
-
context 'expirations on a deleted key' do
|
68
|
-
before { @mock.del(@key) }
|
69
|
-
|
70
|
-
it 'cleans up the expiration once the key is gone (string)' do
|
71
|
-
@mock.set(@key, 'string')
|
72
|
-
@mock.expire(@key, 2)
|
73
|
-
@mock.del(@key)
|
74
|
-
@mock.set(@key, 'string')
|
75
|
-
|
76
|
-
Time.stub(:now).and_return(@now + 2)
|
77
|
-
|
78
|
-
@mock.get(@key).should_not be_nil
|
79
|
-
end
|
80
|
-
|
81
|
-
it 'cleans up the expiration once the key is gone (list)' do
|
82
|
-
@mock.rpush(@key, 'coconuts')
|
83
|
-
@mock.expire(@key, 2)
|
84
|
-
@mock.rpop(@key)
|
85
|
-
|
86
|
-
@mock.rpush(@key, 'coconuts')
|
87
|
-
|
88
|
-
Time.stub(:now).and_return(@now + 2)
|
89
|
-
|
90
|
-
@mock.lindex(@key, 0).should_not be_nil
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
context 'with two key expirations' do
|
95
|
-
let(:other_key) { 'mock-redis-test:expire-other' }
|
96
|
-
|
97
|
-
before { @redises.set(other_key, 'spork-other') }
|
98
|
-
|
99
|
-
it 'removes keys after enough time has passed' do
|
100
|
-
@mock.expire(@key, 5)
|
101
|
-
@mock.expire(other_key, 10)
|
102
|
-
|
103
|
-
Time.stub(:now).and_return(@now + 5)
|
104
|
-
@mock.get(@key).should be_nil
|
105
|
-
|
106
|
-
Time.stub(:now).and_return(@now + 10)
|
107
|
-
@mock.get(other_key).should be_nil
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#expireat(key, timestamp)' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:expireat'
|
6
|
-
@redises.set(@key, 'spork')
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'returns true for a key that exists' do
|
10
|
-
@redises.expireat(@key, Time.now.to_i + 1).should == true
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'returns false for a key that does not exist' do
|
14
|
-
@redises.expireat('mock-redis-test:nonesuch', Time.now.to_i + 1).should == false
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'removes a key immediately when timestamp is now' do
|
18
|
-
@redises.expireat(@key, Time.now.to_i)
|
19
|
-
@redises.get(@key).should be_nil
|
20
|
-
end
|
21
|
-
|
22
|
-
it "raises an error if you don't give it a Unix timestamp" do
|
23
|
-
lambda do
|
24
|
-
@redises.expireat(@key, Time.now) # oops, forgot .to_i
|
25
|
-
end.should raise_error(Redis::CommandError)
|
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 'removes keys after enough time has passed' do
|
42
|
-
@mock.expireat(@key, @now.to_i + 5)
|
43
|
-
Time.stub(:now).and_return(@now + 5)
|
44
|
-
@mock.get(@key).should be_nil
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#flushall [mock only]' do
|
4
|
-
# don't want to hurt things in the real redis that are outside our
|
5
|
-
# namespace.
|
6
|
-
before { @mock = @redises.mock }
|
7
|
-
before { @key = 'mock-redis-test:select' }
|
8
|
-
|
9
|
-
it "returns 'OK'" do
|
10
|
-
@mock.flushall.should == 'OK'
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'removes all keys in the current DB' do
|
14
|
-
@mock.set('k1', 'v1')
|
15
|
-
@mock.lpush('k2', 'v2')
|
16
|
-
|
17
|
-
@mock.flushall
|
18
|
-
@mock.keys('*').should == []
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'removes all keys in other DBs, too' do
|
22
|
-
@mock.set('k1', 'v1')
|
23
|
-
|
24
|
-
@mock.select(1)
|
25
|
-
@mock.flushall
|
26
|
-
@mock.select(0)
|
27
|
-
|
28
|
-
@mock.get('k1').should be_nil
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'removes expiration times' do
|
32
|
-
@mock.set('k1', 'v1')
|
33
|
-
@mock.expire('k1', 360_000)
|
34
|
-
@mock.flushall
|
35
|
-
@mock.set('k1', 'v1')
|
36
|
-
@mock.ttl('k1').should == -1
|
37
|
-
end
|
38
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#flushdb [mock only]' do
|
4
|
-
# don't want to hurt things in the real redis that are outside our
|
5
|
-
# namespace.
|
6
|
-
before { @mock = @redises.mock }
|
7
|
-
before { @key = 'mock-redis-test:select' }
|
8
|
-
|
9
|
-
it "returns 'OK'" do
|
10
|
-
@mock.flushdb.should == 'OK'
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'removes all keys in the current DB' do
|
14
|
-
@mock.set('k1', 'v1')
|
15
|
-
@mock.lpush('k2', 'v2')
|
16
|
-
|
17
|
-
@mock.flushdb
|
18
|
-
@mock.keys('*').should == []
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'leaves other databases alone' do
|
22
|
-
@mock.set('k1', 'v1')
|
23
|
-
|
24
|
-
@mock.select(1)
|
25
|
-
@mock.flushdb
|
26
|
-
@mock.select(0)
|
27
|
-
|
28
|
-
@mock.get('k1').should == 'v1'
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'removes expiration times' do
|
32
|
-
@mock.set('k1', 'v1')
|
33
|
-
@mock.expire('k1', 360_000)
|
34
|
-
@mock.flushdb
|
35
|
-
@mock.set('k1', 'v1')
|
36
|
-
@mock.ttl('k1').should == -1
|
37
|
-
end
|
38
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe MockRedis::Future do
|
4
|
-
let(:command) { [:get, 'foo'] }
|
5
|
-
let(:result) { 'bar' }
|
6
|
-
let(:block) { ->(value) { value.upcase } }
|
7
|
-
|
8
|
-
before do
|
9
|
-
@future = MockRedis::Future.new(command)
|
10
|
-
@future2 = MockRedis::Future.new(command, block)
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'remembers the command' do
|
14
|
-
@future.command.should eq(command)
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'raises an error if the value is requested before the result is set' do
|
18
|
-
expect { @future.value }.to raise_error(MockRedis::FutureNotReady)
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'returns the value after the result has been set' do
|
22
|
-
@future.store_result(result)
|
23
|
-
@future.value.should eq(result)
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'executes the block on the value if block is passed in' do
|
27
|
-
@future2.store_result(result)
|
28
|
-
@future2.value.should eq('BAR')
|
29
|
-
end
|
30
|
-
end
|