mock_redis 0.32.0 → 0.44.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 +59 -0
- data/README.md +4 -4
- data/lib/mock_redis/database.rb +42 -13
- data/lib/mock_redis/geospatial_methods.rb +2 -2
- data/lib/mock_redis/hash_methods.rb +1 -1
- data/lib/mock_redis/list_methods.rb +37 -2
- data/lib/mock_redis/memory_method.rb +11 -0
- 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 +18 -2
- data/lib/mock_redis/stream.rb +3 -3
- data/lib/mock_redis/string_methods.rb +33 -6
- 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 +13 -4
- data/lib/mock_redis.rb +5 -6
- metadata +20 -352
- 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 -29
- 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/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 -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 -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 -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 -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 -119
- 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 -71
- 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/set_spec.rb
DELETED
@@ -1,119 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#set(key, value)' do
|
4
|
-
let(:key) { 'mock-redis-test' }
|
5
|
-
|
6
|
-
it "responds with 'OK'" do
|
7
|
-
@redises.set('mock-redis-test', 1).should == 'OK'
|
8
|
-
end
|
9
|
-
|
10
|
-
context 'options' do
|
11
|
-
it 'raises an error for EX seconds = 0' do
|
12
|
-
expect do
|
13
|
-
@redises.set('mock-redis-test', 1, ex: 0)
|
14
|
-
end.to raise_error(Redis::CommandError, 'ERR invalid expire time in set')
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'raises an error for PX milliseconds = 0' do
|
18
|
-
expect do
|
19
|
-
@redises.set('mock-redis-test', 1, px: 0)
|
20
|
-
end.to raise_error(Redis::CommandError, 'ERR invalid expire time in set')
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'accepts NX' do
|
24
|
-
@redises.del(key)
|
25
|
-
@redises.set(key, 1, nx: true).should == true
|
26
|
-
@redises.set(key, 1, nx: true).should == false
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'accepts XX' do
|
30
|
-
@redises.del(key)
|
31
|
-
@redises.set(key, 1, xx: true).should == false
|
32
|
-
@redises.set(key, 1).should == 'OK'
|
33
|
-
@redises.set(key, 1, xx: true).should == true
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'sets the ttl to -1' do
|
37
|
-
@redises.set(key, 1)
|
38
|
-
expect(@redises.ttl(key)).to eq(-1)
|
39
|
-
end
|
40
|
-
|
41
|
-
context 'with an expiry time' do
|
42
|
-
before :each do
|
43
|
-
Timecop.freeze
|
44
|
-
@redises.set(key, 1, ex: 90)
|
45
|
-
end
|
46
|
-
|
47
|
-
after :each do
|
48
|
-
@redises.del(key)
|
49
|
-
Timecop.return
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'has the TTL set' do
|
53
|
-
expect(@redises.ttl(key)).to eq 90
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'resets the TTL without keepttl' do
|
57
|
-
expect do
|
58
|
-
@redises.set(key, 2)
|
59
|
-
end.to change { @redises.ttl(key) }.from(90).to(-1)
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'does not change the TTL with keepttl: true' do
|
63
|
-
expect do
|
64
|
-
@redises.set(key, 2, keepttl: true)
|
65
|
-
end.not_to change { @redises.ttl(key) }.from(90)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'accepts KEEPTTL' do
|
70
|
-
expect(@redises.set(key, 1, keepttl: true)).to eq 'OK'
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'does not set TTL without ex' do
|
74
|
-
@redises.set(key, 1)
|
75
|
-
expect(@redises.ttl(key)).to eq(-1)
|
76
|
-
end
|
77
|
-
|
78
|
-
it 'sets the TTL' do
|
79
|
-
Timecop.freeze do
|
80
|
-
@redises.set(key, 1, ex: 90)
|
81
|
-
expect(@redises.ttl(key)).to eq 90
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
it 'raises on unknown options' do
|
86
|
-
@redises.del(key)
|
87
|
-
expect do
|
88
|
-
@redises.set(key, 1, logger: :something)
|
89
|
-
end.to raise_error(ArgumentError, /unknown keyword/)
|
90
|
-
end
|
91
|
-
|
92
|
-
context '[mock only]' do
|
93
|
-
before(:all) do
|
94
|
-
@mock = @redises.mock
|
95
|
-
end
|
96
|
-
|
97
|
-
before do
|
98
|
-
@now = Time.now
|
99
|
-
Time.stub(:now).and_return(@now)
|
100
|
-
end
|
101
|
-
|
102
|
-
it 'accepts EX seconds' do
|
103
|
-
@mock.set(key, 1, ex: 1).should == 'OK'
|
104
|
-
@mock.get(key).should_not be_nil
|
105
|
-
Time.stub(:now).and_return(@now + 2)
|
106
|
-
@mock.get(key).should be_nil
|
107
|
-
end
|
108
|
-
|
109
|
-
it 'accepts PX milliseconds' do
|
110
|
-
@mock.set(key, 1, px: 500).should == 'OK'
|
111
|
-
@mock.get(key).should_not be_nil
|
112
|
-
Time.stub(:now).and_return(@now + 300 / 1000.to_f)
|
113
|
-
@mock.get(key).should_not be_nil
|
114
|
-
Time.stub(:now).and_return(@now + 600 / 1000.to_f)
|
115
|
-
@mock.get(key).should be_nil
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#setbit(key, offset)' do
|
4
|
-
before do
|
5
|
-
Encoding.default_external = 'UTF-8'
|
6
|
-
@key = 'mock-redis-test:setbit'
|
7
|
-
@redises.set(@key, 'h') # ASCII 0x68
|
8
|
-
end
|
9
|
-
|
10
|
-
it "returns the original stored bit's value" do
|
11
|
-
@redises.setbit(@key, 0, 1).should == 0
|
12
|
-
@redises.setbit(@key, 1, 1).should == 1
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'sets the bit within the string' do
|
16
|
-
@redises.setbit(@key, 7, 1)
|
17
|
-
@redises.get(@key).should == 'i' # ASCII 0x69
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'unsets the bit within the string' do
|
21
|
-
@redises.setbit(@key, 1, 0)
|
22
|
-
@redises.get(@key).should == '(' # ASCII 0x28
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'does the right thing with multibyte characters' do
|
26
|
-
@redises.set(@key, '€99.94') # the euro sign is 3 bytes wide in UTF-8
|
27
|
-
@redises.setbit(@key, 63, 1).should == 0
|
28
|
-
@redises.get(@key).should == '€99.95'
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'expands the string if necessary' do
|
32
|
-
@redises.setbit(@key, 9, 1)
|
33
|
-
@redises.get(@key).should == 'h@'
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'sets added bits to 0' do
|
37
|
-
@redises.setbit(@key, 17, 1)
|
38
|
-
@redises.get(@key).should == "h\000@"
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'treats missing keys as empty strings' do
|
42
|
-
@redises.del(@key)
|
43
|
-
@redises.setbit(@key, 1, 1)
|
44
|
-
@redises.get(@key).should == '@'
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'sets and retrieves bits' do
|
48
|
-
@redises.setbit(@key, 22, 1)
|
49
|
-
@redises.getbit(@key, 22).should == 1
|
50
|
-
@redises.setbit(@key, 23, 0)
|
51
|
-
@redises.getbit(@key, 23).should == 0
|
52
|
-
end
|
53
|
-
|
54
|
-
it_should_behave_like 'a string-only command'
|
55
|
-
end
|
data/spec/commands/setex_spec.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#setex(key, seconds, value)' do
|
4
|
-
before { @key = 'mock-redis-test:setex' }
|
5
|
-
|
6
|
-
it "responds with 'OK'" do
|
7
|
-
@redises.setex(@key, 10, 'value').should == 'OK'
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'sets the value' do
|
11
|
-
@redises.setex(@key, 10_000, 'value')
|
12
|
-
@redises.get(@key).should == 'value'
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'sets the expiration time' do
|
16
|
-
@redises.setex(@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
|
-
context 'when expiration time is zero' do
|
24
|
-
it 'raises Redis::CommandError' do
|
25
|
-
expect do
|
26
|
-
@redises.setex(@key, 0, 'value')
|
27
|
-
end.to raise_error(Redis::CommandError, 'ERR invalid expire time in setex')
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
context 'when expiration time is negative' do
|
32
|
-
it 'raises Redis::CommandError' do
|
33
|
-
expect do
|
34
|
-
@redises.setex(@key, -2, 'value')
|
35
|
-
end.to raise_error(Redis::CommandError, 'ERR invalid expire time in setex')
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
data/spec/commands/setnx_spec.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#setnx(key, value)' do
|
4
|
-
before { @key = 'mock-redis-test:setnx' }
|
5
|
-
|
6
|
-
it 'returns true if the key was absent' do
|
7
|
-
@redises.setnx(@key, 1).should == true
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'returns false if the key was present' do
|
11
|
-
@redises.set(@key, 2)
|
12
|
-
@redises.setnx(@key, 1).should == false
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'sets the value if missing' do
|
16
|
-
@redises.setnx(@key, 'value')
|
17
|
-
@redises.get(@key).should == 'value'
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'does nothing if the value is present' do
|
21
|
-
@redises.set(@key, 'old')
|
22
|
-
@redises.setnx(@key, 'new')
|
23
|
-
@redises.get(@key).should == 'old'
|
24
|
-
end
|
25
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#setrange(key, offset, value)' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:setrange'
|
6
|
-
@redises.set(@key, 'This is a string')
|
7
|
-
end
|
8
|
-
|
9
|
-
it "returns the string's new length" do
|
10
|
-
@redises.setrange(@key, 0, 'That').should == 16
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'updates part of the string' do
|
14
|
-
@redises.setrange(@key, 0, 'That')
|
15
|
-
@redises.get(@key).should == 'That is a string'
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'zero-pads the string if necessary' do
|
19
|
-
@redises.setrange(@key, 20, 'X')
|
20
|
-
@redises.get(@key).should == "This is a string\000\000\000\000X"
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'stores things as strings' do
|
24
|
-
other_key = 'mock-redis-test:setrange-other-key'
|
25
|
-
@redises.setrange(other_key, 0, 1)
|
26
|
-
@redises.get(other_key).should == '1'
|
27
|
-
end
|
28
|
-
|
29
|
-
it_should_behave_like 'a string-only command'
|
30
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#sinter(key [, key, ...])' do
|
4
|
-
before do
|
5
|
-
@numbers = 'mock-redis-test:sinter:numbers'
|
6
|
-
@evens = 'mock-redis-test:sinter:evens'
|
7
|
-
@primes = 'mock-redis-test:sinter:primes'
|
8
|
-
|
9
|
-
(1..10).each { |i| @redises.sadd(@numbers, i) }
|
10
|
-
[2, 4, 6, 8, 10].each { |i| @redises.sadd(@evens, i) }
|
11
|
-
[2, 3, 5, 7].each { |i| @redises.sadd(@primes, i) }
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'returns the elements in the resulting set' do
|
15
|
-
@redises.sinter(@evens, @primes).should == ['2']
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'treats missing keys as empty sets' do
|
19
|
-
@redises.sinter(@destination, 'mock-redis-test:nonesuch').should == []
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'raises an error if given 0 sets' do
|
23
|
-
lambda do
|
24
|
-
@redises.sinter
|
25
|
-
end.should raise_error(Redis::CommandError)
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'raises an error if any argument is not a a set' do
|
29
|
-
@redises.set('mock-redis-test:notset', 1)
|
30
|
-
|
31
|
-
lambda do
|
32
|
-
@redises.sinter(@numbers, 'mock-redis-test:notset')
|
33
|
-
end.should raise_error(Redis::CommandError)
|
34
|
-
|
35
|
-
lambda do
|
36
|
-
@redises.sinter('mock-redis-test:notset', @numbers)
|
37
|
-
end.should raise_error(Redis::CommandError)
|
38
|
-
end
|
39
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#sinterstore(destination, key [, key, ...])' do
|
4
|
-
before do
|
5
|
-
@numbers = 'mock-redis-test:sinterstore:numbers'
|
6
|
-
@evens = 'mock-redis-test:sinterstore:evens'
|
7
|
-
@primes = 'mock-redis-test:sinterstore:primes'
|
8
|
-
@destination = 'mock-redis-test:sinterstore:destination'
|
9
|
-
|
10
|
-
(1..10).each { |i| @redises.sadd(@numbers, i) }
|
11
|
-
[2, 4, 6, 8, 10].each { |i| @redises.sadd(@evens, i) }
|
12
|
-
[2, 3, 5, 7].each { |i| @redises.sadd(@primes, i) }
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'returns the number of elements in the resulting set' do
|
16
|
-
@redises.sinterstore(@destination, @numbers, @evens).should == 5
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'stores the resulting set' do
|
20
|
-
@redises.sinterstore(@destination, @numbers, @evens)
|
21
|
-
@redises.smembers(@destination).should == %w[10 8 6 4 2]
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'does not store empty sets' do
|
25
|
-
@redises.sinterstore(@destination, 'mock-redis-test:nonesuch', @numbers).should == 0
|
26
|
-
@redises.get(@destination).should be_nil
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'removes existing elements in destination' do
|
30
|
-
@redises.sadd(@destination, 42)
|
31
|
-
|
32
|
-
@redises.sinterstore(@destination, @primes)
|
33
|
-
@redises.smembers(@destination).should == %w[7 5 3 2]
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'raises an error if given 0 sets' do
|
37
|
-
lambda do
|
38
|
-
@redises.sinterstore(@destination)
|
39
|
-
end.should raise_error(Redis::CommandError)
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'raises an error if any argument is not a a set' do
|
43
|
-
@redises.set('mock-redis-test:notset', 1)
|
44
|
-
|
45
|
-
lambda do
|
46
|
-
@redises.sinterstore(@destination, @numbers, 'mock-redis-test:notset')
|
47
|
-
end.should raise_error(Redis::CommandError)
|
48
|
-
|
49
|
-
lambda do
|
50
|
-
@redises.sinterstore(@destination, 'mock-redis-test:notset', @numbers)
|
51
|
-
end.should raise_error(Redis::CommandError)
|
52
|
-
end
|
53
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#sismember(key, member)' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:sismember'
|
6
|
-
@redises.sadd(@key, 'whiskey')
|
7
|
-
@redises.sadd(@key, 'beer')
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'returns true if member is in set' do
|
11
|
-
@redises.sismember(@key, 'whiskey').should == true
|
12
|
-
@redises.sismember(@key, 'beer').should == true
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'returns false if member is not in set' do
|
16
|
-
@redises.sismember(@key, 'cola').should == false
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'stringifies member' do
|
20
|
-
@redises.sadd(@key, '1')
|
21
|
-
@redises.sismember(@key, 1).should == true
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'treats a nonexistent value as an empty set' do
|
25
|
-
@redises.sismember('mock-redis-test:nonesuch', 'beer').should == false
|
26
|
-
end
|
27
|
-
|
28
|
-
it_should_behave_like 'a set-only command'
|
29
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#smembers(key)' do
|
4
|
-
before { @key = 'mock-redis-test:smembers' }
|
5
|
-
|
6
|
-
it 'returns [] for an empty set' do
|
7
|
-
@redises.smembers(@key).should == []
|
8
|
-
end
|
9
|
-
|
10
|
-
it "returns the set's members" do
|
11
|
-
@redises.sadd(@key, 'Hello')
|
12
|
-
@redises.sadd(@key, 'World')
|
13
|
-
@redises.sadd(@key, 'Test')
|
14
|
-
@redises.smembers(@key).should == %w[Test World Hello]
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'returns unfrozen copies of the input' do
|
18
|
-
input = 'a string'
|
19
|
-
@redises.sadd(@key, input)
|
20
|
-
output = @redises.smembers(@key).first
|
21
|
-
|
22
|
-
expect(output).to eq input
|
23
|
-
expect(output).to_not equal input
|
24
|
-
expect(output).to_not be_frozen
|
25
|
-
end
|
26
|
-
|
27
|
-
it_should_behave_like 'a set-only command'
|
28
|
-
end
|
data/spec/commands/smove_spec.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#smove(source, destination, member)' do
|
4
|
-
before do
|
5
|
-
@src = 'mock-redis-test:smove-source'
|
6
|
-
@dest = 'mock-redis-test:smove-destination'
|
7
|
-
|
8
|
-
@redises.sadd(@src, 1)
|
9
|
-
@redises.sadd(@dest, 2)
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'returns true if the member exists in src' do
|
13
|
-
@redises.smove(@src, @dest, 1).should == true
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'returns false if the member exists in src' do
|
17
|
-
@redises.smove(@src, @dest, 'nope').should == false
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'returns true if the member exists in src and dest' do
|
21
|
-
@redises.sadd(@dest, 1)
|
22
|
-
@redises.smove(@src, @dest, 1).should == true
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'moves member from source to destination' do
|
26
|
-
@redises.smove(@src, @dest, 1)
|
27
|
-
@redises.sismember(@dest, 1).should == true
|
28
|
-
@redises.sismember(@src, 1).should == false
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'cleans up empty sets' do
|
32
|
-
@redises.smove(@src, @dest, 1)
|
33
|
-
@redises.get(@src).should be_nil
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'treats a nonexistent value as an empty set' do
|
37
|
-
@redises.smove('mock-redis-test:nonesuch', @dest, 1).should == false
|
38
|
-
end
|
39
|
-
|
40
|
-
it_should_behave_like 'a set-only command'
|
41
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#sort(key, options)' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:list_sort'
|
6
|
-
|
7
|
-
@redises.rpush(@key, '1')
|
8
|
-
@redises.rpush(@key, '2')
|
9
|
-
|
10
|
-
@redises.set('mock-redis-test:values_1', 'a')
|
11
|
-
@redises.set('mock-redis-test:values_2', 'b')
|
12
|
-
|
13
|
-
@redises.set('mock-redis-test:weight_1', '2')
|
14
|
-
@redises.set('mock-redis-test:weight_2', '1')
|
15
|
-
|
16
|
-
@redises.hset('mock-redis-test:hash_1', 'key', 'x')
|
17
|
-
@redises.hset('mock-redis-test:hash_2', 'key', 'y')
|
18
|
-
end
|
19
|
-
|
20
|
-
it_should_behave_like 'a sortable'
|
21
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#sort(key, options)' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:set_sort'
|
6
|
-
|
7
|
-
@redises.sadd(@key, '1')
|
8
|
-
@redises.sadd(@key, '2')
|
9
|
-
|
10
|
-
@redises.set('mock-redis-test:values_1', 'a')
|
11
|
-
@redises.set('mock-redis-test:values_2', 'b')
|
12
|
-
|
13
|
-
@redises.set('mock-redis-test:weight_1', '2')
|
14
|
-
@redises.set('mock-redis-test:weight_2', '1')
|
15
|
-
|
16
|
-
@redises.hset('mock-redis-test:hash_1', 'key', 'x')
|
17
|
-
@redises.hset('mock-redis-test:hash_2', 'key', 'y')
|
18
|
-
end
|
19
|
-
|
20
|
-
it_should_behave_like 'a sortable'
|
21
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#sort(key, options)' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:zset_sort'
|
6
|
-
|
7
|
-
@redises.zadd(@key, 100, '1')
|
8
|
-
@redises.zadd(@key, 99, '2')
|
9
|
-
|
10
|
-
@redises.set('mock-redis-test:values_1', 'a')
|
11
|
-
@redises.set('mock-redis-test:values_2', 'b')
|
12
|
-
|
13
|
-
@redises.set('mock-redis-test:weight_1', '2')
|
14
|
-
@redises.set('mock-redis-test:weight_2', '1')
|
15
|
-
|
16
|
-
@redises.hset('mock-redis-test:hash_1', 'key', 'x')
|
17
|
-
@redises.hset('mock-redis-test:hash_2', 'key', 'y')
|
18
|
-
end
|
19
|
-
|
20
|
-
it_should_behave_like 'a sortable'
|
21
|
-
end
|
data/spec/commands/spop_spec.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#spop(key)' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:spop'
|
6
|
-
|
7
|
-
@redises.sadd(@key, 'value')
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'returns a member of the set' do
|
11
|
-
@redises.spop(@key).should == 'value'
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'removes a member of the set' do
|
15
|
-
@redises.spop(@key)
|
16
|
-
@redises.smembers(@key).should == []
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'returns nil if the set is empty' do
|
20
|
-
@redises.spop(@key)
|
21
|
-
@redises.spop(@key).should be_nil
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'returns an array if count is not nil' do
|
25
|
-
@redises.sadd(@key, 'value2')
|
26
|
-
@redises.spop(@key, 2).should == %w[value value2]
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'returns only whats in the set' do
|
30
|
-
@redises.spop(@key, 2).should == ['value']
|
31
|
-
@redises.smembers(@key).should == []
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'returns an empty array if count is not nil and the set it empty' do
|
35
|
-
@redises.spop(@key)
|
36
|
-
@redises.spop(@key, 100).should == []
|
37
|
-
end
|
38
|
-
|
39
|
-
it_should_behave_like 'a set-only command'
|
40
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#srandmember(key)' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:srandmember'
|
6
|
-
|
7
|
-
@redises.sadd(@key, 'value')
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'returns a member of the set' do
|
11
|
-
@redises.srandmember(@key).should == 'value'
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'does not modify the set' do
|
15
|
-
@redises.srandmember(@key)
|
16
|
-
@redises.smembers(@key).should == ['value']
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'returns nil if the set is empty' do
|
20
|
-
@redises.spop(@key)
|
21
|
-
@redises.srandmember(@key).should be_nil
|
22
|
-
end
|
23
|
-
|
24
|
-
context 'when count argument is specified' do
|
25
|
-
before do
|
26
|
-
@redises.sadd(@key, 'value2')
|
27
|
-
@redises.sadd(@key, 'value3')
|
28
|
-
end
|
29
|
-
|
30
|
-
# NOTE: We disable result checking since MockRedis and Redis will likely
|
31
|
-
# return a different random set (since the selection is, well, random)
|
32
|
-
it 'returns the whole set if count is greater than the set size' do
|
33
|
-
@redises.send_without_checking(:srandmember, @key, 5).should =~ %w[value value2 value3]
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'returns random members up to count from the set when count is smaller than the set size' do
|
37
|
-
@redises.send_without_checking(:srandmember, @key, 2).size.should == 2
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'returns random members up to count from the set when count is negative even if count.abs is greater than the set size' do # rubocop:disable Layout/LineLength
|
41
|
-
@redises.send_without_checking(:srandmember, @key, -5).size.should == 5
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'returns nil if the set is empty' do
|
45
|
-
@redises.srem(@key, %w[value value2 value3])
|
46
|
-
@redises.srandmember(@key, 2).should be_empty
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
data/spec/commands/srem_spec.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#srem(key, member)' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:srem'
|
6
|
-
|
7
|
-
@redises.sadd(@key, 'bert')
|
8
|
-
@redises.sadd(@key, 'ernie')
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'returns true if member is in the set' do
|
12
|
-
@redises.srem(@key, 'bert').should == true
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'returns false if member is not in the set' do
|
16
|
-
@redises.srem(@key, 'cookiemonster').should == false
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'removes member from the set' do
|
20
|
-
@redises.srem(@key, 'ernie')
|
21
|
-
@redises.smembers(@key).should == ['bert']
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'stringifies member' do
|
25
|
-
@redises.sadd(@key, '1')
|
26
|
-
@redises.srem(@key, 1).should == true
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'cleans up empty sets' do
|
30
|
-
@redises.smembers(@key).each { |m| @redises.srem(@key, m) }
|
31
|
-
@redises.get(@key).should be_nil
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'supports a variable number of arguments' do
|
35
|
-
@redises.srem(@key, %w[bert ernie]).should == 2
|
36
|
-
@redises.get(@key).should be_nil
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'allow passing an array of integers as argument' do
|
40
|
-
@redises.sadd(@key, %w[1 2])
|
41
|
-
@redises.srem(@key, [1, 2]).should == 2
|
42
|
-
end
|
43
|
-
|
44
|
-
it_should_behave_like 'a set-only command'
|
45
|
-
end
|