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.
Files changed (197) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -0
  3. data/README.md +1 -1
  4. data/lib/mock_redis/database.rb +1 -1
  5. data/lib/mock_redis/hash_methods.rb +1 -1
  6. data/lib/mock_redis/list_methods.rb +7 -2
  7. data/lib/mock_redis/multi_db_wrapper.rb +1 -1
  8. data/lib/mock_redis/pipelined_wrapper.rb +12 -14
  9. data/lib/mock_redis/set_methods.rb +6 -1
  10. data/lib/mock_redis/stream.rb +3 -3
  11. data/lib/mock_redis/string_methods.rb +3 -3
  12. data/lib/mock_redis/transaction_wrapper.rb +5 -7
  13. data/lib/mock_redis/utility_methods.rb +4 -2
  14. data/lib/mock_redis/version.rb +1 -1
  15. data/lib/mock_redis/zset.rb +4 -2
  16. data/lib/mock_redis/zset_methods.rb +3 -3
  17. data/lib/mock_redis.rb +1 -2
  18. metadata +19 -360
  19. data/.github/workflows/lint.yml +0 -31
  20. data/.github/workflows/tests.yml +0 -63
  21. data/.gitignore +0 -5
  22. data/.mailmap +0 -2
  23. data/.overcommit.yml +0 -21
  24. data/.rspec +0 -1
  25. data/.rubocop.yml +0 -148
  26. data/.rubocop_todo.yml +0 -35
  27. data/.simplecov +0 -4
  28. data/Gemfile +0 -13
  29. data/Rakefile +0 -2
  30. data/mock_redis.gemspec +0 -32
  31. data/spec/client_spec.rb +0 -36
  32. data/spec/cloning_spec.rb +0 -95
  33. data/spec/commands/append_spec.rb +0 -24
  34. data/spec/commands/auth_spec.rb +0 -7
  35. data/spec/commands/bgrewriteaof_spec.rb +0 -7
  36. data/spec/commands/bgsave_spec.rb +0 -7
  37. data/spec/commands/bitcount_spec.rb +0 -25
  38. data/spec/commands/bitfield_spec.rb +0 -169
  39. data/spec/commands/blmove_spec.rb +0 -52
  40. data/spec/commands/blpop_spec.rb +0 -53
  41. data/spec/commands/brpop_spec.rb +0 -59
  42. data/spec/commands/brpoplpush_spec.rb +0 -52
  43. data/spec/commands/connected_spec.rb +0 -7
  44. data/spec/commands/connection_spec.rb +0 -15
  45. data/spec/commands/dbsize_spec.rb +0 -18
  46. data/spec/commands/decr_spec.rb +0 -34
  47. data/spec/commands/decrby_spec.rb +0 -34
  48. data/spec/commands/del_spec.rb +0 -52
  49. data/spec/commands/disconnect_spec.rb +0 -7
  50. data/spec/commands/dump_spec.rb +0 -19
  51. data/spec/commands/echo_spec.rb +0 -11
  52. data/spec/commands/eval_spec.rb +0 -7
  53. data/spec/commands/evalsha_spec.rb +0 -10
  54. data/spec/commands/exists_spec.rb +0 -43
  55. data/spec/commands/expire_spec.rb +0 -111
  56. data/spec/commands/expireat_spec.rb +0 -47
  57. data/spec/commands/flushall_spec.rb +0 -38
  58. data/spec/commands/flushdb_spec.rb +0 -38
  59. data/spec/commands/future_spec.rb +0 -30
  60. data/spec/commands/geoadd_spec.rb +0 -58
  61. data/spec/commands/geodist_spec.rb +0 -118
  62. data/spec/commands/geohash_spec.rb +0 -52
  63. data/spec/commands/geopos_spec.rb +0 -55
  64. data/spec/commands/get_spec.rb +0 -31
  65. data/spec/commands/getbit_spec.rb +0 -34
  66. data/spec/commands/getdel.rb +0 -24
  67. data/spec/commands/getrange_spec.rb +0 -22
  68. data/spec/commands/getset_spec.rb +0 -23
  69. data/spec/commands/hdel_spec.rb +0 -77
  70. data/spec/commands/hexists_spec.rb +0 -27
  71. data/spec/commands/hget_spec.rb +0 -28
  72. data/spec/commands/hgetall_spec.rb +0 -32
  73. data/spec/commands/hincrby_spec.rb +0 -58
  74. data/spec/commands/hincrbyfloat_spec.rb +0 -58
  75. data/spec/commands/hkeys_spec.rb +0 -19
  76. data/spec/commands/hlen_spec.rb +0 -19
  77. data/spec/commands/hmget_spec.rb +0 -46
  78. data/spec/commands/hmset_spec.rb +0 -69
  79. data/spec/commands/hscan_each_spec.rb +0 -48
  80. data/spec/commands/hscan_spec.rb +0 -27
  81. data/spec/commands/hset_spec.rb +0 -42
  82. data/spec/commands/hsetnx_spec.rb +0 -44
  83. data/spec/commands/hvals_spec.rb +0 -19
  84. data/spec/commands/incr_spec.rb +0 -34
  85. data/spec/commands/incrby_spec.rb +0 -44
  86. data/spec/commands/incrbyfloat_spec.rb +0 -44
  87. data/spec/commands/info_spec.rb +0 -62
  88. data/spec/commands/keys_spec.rb +0 -139
  89. data/spec/commands/lastsave_spec.rb +0 -8
  90. data/spec/commands/lindex_spec.rb +0 -49
  91. data/spec/commands/linsert_spec.rb +0 -68
  92. data/spec/commands/llen_spec.rb +0 -16
  93. data/spec/commands/lmove_spec.rb +0 -72
  94. data/spec/commands/lpop_spec.rb +0 -35
  95. data/spec/commands/lpush_spec.rb +0 -43
  96. data/spec/commands/lpushx_spec.rb +0 -46
  97. data/spec/commands/lrange_spec.rb +0 -51
  98. data/spec/commands/lrem_spec.rb +0 -80
  99. data/spec/commands/lset_spec.rb +0 -43
  100. data/spec/commands/ltrim_spec.rb +0 -45
  101. data/spec/commands/mapped_hmget_spec.rb +0 -29
  102. data/spec/commands/mapped_hmset_spec.rb +0 -47
  103. data/spec/commands/mapped_mget_spec.rb +0 -22
  104. data/spec/commands/mapped_mset_spec.rb +0 -19
  105. data/spec/commands/mapped_msetnx_spec.rb +0 -26
  106. data/spec/commands/mget_spec.rb +0 -65
  107. data/spec/commands/move_spec.rb +0 -147
  108. data/spec/commands/mset_spec.rb +0 -43
  109. data/spec/commands/msetnx_spec.rb +0 -40
  110. data/spec/commands/persist_spec.rb +0 -48
  111. data/spec/commands/pexpire_spec.rb +0 -86
  112. data/spec/commands/pexpireat_spec.rb +0 -48
  113. data/spec/commands/ping_spec.rb +0 -11
  114. data/spec/commands/pipelined_spec.rb +0 -114
  115. data/spec/commands/psetex_spec.rb +0 -44
  116. data/spec/commands/pttl_spec.rb +0 -41
  117. data/spec/commands/quit_spec.rb +0 -7
  118. data/spec/commands/randomkey_spec.rb +0 -20
  119. data/spec/commands/rename_spec.rb +0 -42
  120. data/spec/commands/renamenx_spec.rb +0 -41
  121. data/spec/commands/restore_spec.rb +0 -47
  122. data/spec/commands/rpop_spec.rb +0 -35
  123. data/spec/commands/rpoplpush_spec.rb +0 -50
  124. data/spec/commands/rpush_spec.rb +0 -43
  125. data/spec/commands/rpushx_spec.rb +0 -46
  126. data/spec/commands/sadd_spec.rb +0 -45
  127. data/spec/commands/save_spec.rb +0 -7
  128. data/spec/commands/scan_each_spec.rb +0 -39
  129. data/spec/commands/scan_spec.rb +0 -64
  130. data/spec/commands/scard_spec.rb +0 -18
  131. data/spec/commands/script_spec.rb +0 -9
  132. data/spec/commands/sdiff_spec.rb +0 -47
  133. data/spec/commands/sdiffstore_spec.rb +0 -58
  134. data/spec/commands/select_spec.rb +0 -61
  135. data/spec/commands/set_spec.rb +0 -134
  136. data/spec/commands/setbit_spec.rb +0 -55
  137. data/spec/commands/setex_spec.rb +0 -38
  138. data/spec/commands/setnx_spec.rb +0 -25
  139. data/spec/commands/setrange_spec.rb +0 -30
  140. data/spec/commands/sinter_spec.rb +0 -39
  141. data/spec/commands/sinterstore_spec.rb +0 -53
  142. data/spec/commands/sismember_spec.rb +0 -29
  143. data/spec/commands/smembers_spec.rb +0 -28
  144. data/spec/commands/smismember_spec.rb +0 -34
  145. data/spec/commands/smove_spec.rb +0 -41
  146. data/spec/commands/sort_list_spec.rb +0 -21
  147. data/spec/commands/sort_set_spec.rb +0 -21
  148. data/spec/commands/sort_zset_spec.rb +0 -21
  149. data/spec/commands/spop_spec.rb +0 -40
  150. data/spec/commands/srandmember_spec.rb +0 -49
  151. data/spec/commands/srem_spec.rb +0 -45
  152. data/spec/commands/sscan_each_spec.rb +0 -48
  153. data/spec/commands/sscan_spec.rb +0 -39
  154. data/spec/commands/strlen_spec.rb +0 -18
  155. data/spec/commands/sunion_spec.rb +0 -42
  156. data/spec/commands/sunionstore_spec.rb +0 -59
  157. data/spec/commands/ttl_spec.rb +0 -40
  158. data/spec/commands/type_spec.rb +0 -36
  159. data/spec/commands/unwatch_spec.rb +0 -7
  160. data/spec/commands/watch_spec.rb +0 -21
  161. data/spec/commands/xadd_spec.rb +0 -122
  162. data/spec/commands/xlen_spec.rb +0 -22
  163. data/spec/commands/xrange_spec.rb +0 -164
  164. data/spec/commands/xread_spec.rb +0 -66
  165. data/spec/commands/xrevrange_spec.rb +0 -130
  166. data/spec/commands/xtrim_spec.rb +0 -36
  167. data/spec/commands/zadd_spec.rb +0 -129
  168. data/spec/commands/zcard_spec.rb +0 -19
  169. data/spec/commands/zcount_spec.rb +0 -39
  170. data/spec/commands/zincrby_spec.rb +0 -31
  171. data/spec/commands/zinterstore_spec.rb +0 -130
  172. data/spec/commands/zpopmax_spec.rb +0 -60
  173. data/spec/commands/zpopmin_spec.rb +0 -60
  174. data/spec/commands/zrange_spec.rb +0 -80
  175. data/spec/commands/zrangebyscore_spec.rb +0 -83
  176. data/spec/commands/zrank_spec.rb +0 -29
  177. data/spec/commands/zrem_spec.rb +0 -50
  178. data/spec/commands/zremrangebyrank_spec.rb +0 -27
  179. data/spec/commands/zremrangebyscore_spec.rb +0 -35
  180. data/spec/commands/zrevrange_spec.rb +0 -56
  181. data/spec/commands/zrevrangebyscore_spec.rb +0 -58
  182. data/spec/commands/zrevrank_spec.rb +0 -29
  183. data/spec/commands/zscan_each_spec.rb +0 -48
  184. data/spec/commands/zscan_spec.rb +0 -26
  185. data/spec/commands/zscore_spec.rb +0 -22
  186. data/spec/commands/zunionstore_spec.rb +0 -137
  187. data/spec/mock_redis_spec.rb +0 -93
  188. data/spec/spec_helper.rb +0 -74
  189. data/spec/support/redis_multiplexer.rb +0 -123
  190. data/spec/support/shared_examples/does_not_cleanup_empty_strings.rb +0 -14
  191. data/spec/support/shared_examples/only_operates_on_hashes.rb +0 -15
  192. data/spec/support/shared_examples/only_operates_on_lists.rb +0 -15
  193. data/spec/support/shared_examples/only_operates_on_sets.rb +0 -15
  194. data/spec/support/shared_examples/only_operates_on_strings.rb +0 -13
  195. data/spec/support/shared_examples/only_operates_on_zsets.rb +0 -59
  196. data/spec/support/shared_examples/sorts_enumerables.rb +0 -56
  197. 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
@@ -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
@@ -1,7 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe '#quit' do
4
- it "responds with 'OK'" do
5
- @redises.quit.should == 'OK'
6
- end
7
- end
@@ -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
@@ -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
@@ -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
@@ -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
@@ -1,7 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe '#save' do
4
- it "responds with 'OK'" do
5
- @redises.save.should == 'OK'
6
- end
7
- end
@@ -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