mock_redis 0.19.0 → 0.44.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (191) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +161 -0
  3. data/LICENSE.md +21 -0
  4. data/README.md +41 -17
  5. data/lib/mock_redis/connection_method.rb +13 -0
  6. data/lib/mock_redis/database.rb +116 -41
  7. data/lib/mock_redis/expire_wrapper.rb +1 -1
  8. data/lib/mock_redis/future.rb +1 -1
  9. data/lib/mock_redis/geospatial_methods.rb +13 -21
  10. data/lib/mock_redis/hash_methods.rb +34 -15
  11. data/lib/mock_redis/indifferent_hash.rb +0 -8
  12. data/lib/mock_redis/info_method.rb +2 -2
  13. data/lib/mock_redis/list_methods.rb +39 -4
  14. data/lib/mock_redis/memory_method.rb +11 -0
  15. data/lib/mock_redis/multi_db_wrapper.rb +4 -4
  16. data/lib/mock_redis/pipelined_wrapper.rb +32 -15
  17. data/lib/mock_redis/set_methods.rb +34 -6
  18. data/lib/mock_redis/stream/id.rb +58 -0
  19. data/lib/mock_redis/stream.rb +88 -0
  20. data/lib/mock_redis/stream_methods.rb +102 -0
  21. data/lib/mock_redis/string_methods.rb +81 -30
  22. data/lib/mock_redis/transaction_wrapper.rb +32 -21
  23. data/lib/mock_redis/utility_methods.rb +9 -4
  24. data/lib/mock_redis/version.rb +1 -1
  25. data/lib/mock_redis/zset.rb +5 -8
  26. data/lib/mock_redis/zset_methods.rb +64 -12
  27. data/lib/mock_redis.rb +38 -10
  28. metadata +40 -336
  29. data/.gitignore +0 -5
  30. data/.mailmap +0 -2
  31. data/.overcommit.yml +0 -21
  32. data/.rspec +0 -1
  33. data/.rubocop.yml +0 -121
  34. data/.rubocop_todo.yml +0 -35
  35. data/.simplecov +0 -4
  36. data/.travis.yml +0 -33
  37. data/Gemfile +0 -12
  38. data/LICENSE +0 -19
  39. data/Rakefile +0 -2
  40. data/mock_redis.gemspec +0 -30
  41. data/spec/client_spec.rb +0 -17
  42. data/spec/cloning_spec.rb +0 -95
  43. data/spec/commands/append_spec.rb +0 -24
  44. data/spec/commands/auth_spec.rb +0 -7
  45. data/spec/commands/bgrewriteaof_spec.rb +0 -7
  46. data/spec/commands/bgsave_spec.rb +0 -7
  47. data/spec/commands/bitcount_spec.rb +0 -25
  48. data/spec/commands/bitfield_spec.rb +0 -169
  49. data/spec/commands/blpop_spec.rb +0 -59
  50. data/spec/commands/brpop_spec.rb +0 -58
  51. data/spec/commands/brpoplpush_spec.rb +0 -52
  52. data/spec/commands/connected_spec.rb +0 -7
  53. data/spec/commands/dbsize_spec.rb +0 -18
  54. data/spec/commands/decr_spec.rb +0 -34
  55. data/spec/commands/decrby_spec.rb +0 -34
  56. data/spec/commands/del_spec.rb +0 -35
  57. data/spec/commands/disconnect_spec.rb +0 -7
  58. data/spec/commands/echo_spec.rb +0 -11
  59. data/spec/commands/eval_spec.rb +0 -7
  60. data/spec/commands/evalsha_spec.rb +0 -10
  61. data/spec/commands/exists_spec.rb +0 -14
  62. data/spec/commands/expire_spec.rb +0 -111
  63. data/spec/commands/expireat_spec.rb +0 -47
  64. data/spec/commands/flushall_spec.rb +0 -38
  65. data/spec/commands/flushdb_spec.rb +0 -38
  66. data/spec/commands/future_spec.rb +0 -20
  67. data/spec/commands/geoadd_spec.rb +0 -58
  68. data/spec/commands/geodist_spec.rb +0 -114
  69. data/spec/commands/geohash_spec.rb +0 -52
  70. data/spec/commands/geopos_spec.rb +0 -55
  71. data/spec/commands/get_spec.rb +0 -30
  72. data/spec/commands/getbit_spec.rb +0 -34
  73. data/spec/commands/getrange_spec.rb +0 -22
  74. data/spec/commands/getset_spec.rb +0 -23
  75. data/spec/commands/hash_operator_spec.rb +0 -21
  76. data/spec/commands/hdel_spec.rb +0 -54
  77. data/spec/commands/hexists_spec.rb +0 -27
  78. data/spec/commands/hget_spec.rb +0 -28
  79. data/spec/commands/hgetall_spec.rb +0 -32
  80. data/spec/commands/hincrby_spec.rb +0 -58
  81. data/spec/commands/hincrbyfloat_spec.rb +0 -58
  82. data/spec/commands/hkeys_spec.rb +0 -19
  83. data/spec/commands/hlen_spec.rb +0 -19
  84. data/spec/commands/hmget_spec.rb +0 -40
  85. data/spec/commands/hmset_spec.rb +0 -43
  86. data/spec/commands/hscan_each_spec.rb +0 -48
  87. data/spec/commands/hscan_spec.rb +0 -27
  88. data/spec/commands/hset_spec.rb +0 -38
  89. data/spec/commands/hsetnx_spec.rb +0 -44
  90. data/spec/commands/hvals_spec.rb +0 -19
  91. data/spec/commands/incr_spec.rb +0 -34
  92. data/spec/commands/incrby_spec.rb +0 -44
  93. data/spec/commands/incrbyfloat_spec.rb +0 -44
  94. data/spec/commands/info_spec.rb +0 -62
  95. data/spec/commands/keys_spec.rb +0 -122
  96. data/spec/commands/lastsave_spec.rb +0 -8
  97. data/spec/commands/lindex_spec.rb +0 -49
  98. data/spec/commands/linsert_spec.rb +0 -68
  99. data/spec/commands/llen_spec.rb +0 -16
  100. data/spec/commands/lpop_spec.rb +0 -34
  101. data/spec/commands/lpush_spec.rb +0 -43
  102. data/spec/commands/lpushx_spec.rb +0 -46
  103. data/spec/commands/lrange_spec.rb +0 -51
  104. data/spec/commands/lrem_spec.rb +0 -80
  105. data/spec/commands/lset_spec.rb +0 -43
  106. data/spec/commands/ltrim_spec.rb +0 -45
  107. data/spec/commands/mapped_hmget_spec.rb +0 -29
  108. data/spec/commands/mapped_hmset_spec.rb +0 -47
  109. data/spec/commands/mapped_mget_spec.rb +0 -22
  110. data/spec/commands/mapped_mset_spec.rb +0 -19
  111. data/spec/commands/mapped_msetnx_spec.rb +0 -26
  112. data/spec/commands/mget_spec.rb +0 -34
  113. data/spec/commands/move_spec.rb +0 -147
  114. data/spec/commands/mset_spec.rb +0 -29
  115. data/spec/commands/msetnx_spec.rb +0 -40
  116. data/spec/commands/persist_spec.rb +0 -48
  117. data/spec/commands/pexpire_spec.rb +0 -86
  118. data/spec/commands/pexpireat_spec.rb +0 -48
  119. data/spec/commands/ping_spec.rb +0 -7
  120. data/spec/commands/pipelined_spec.rb +0 -42
  121. data/spec/commands/pttl_spec.rb +0 -41
  122. data/spec/commands/quit_spec.rb +0 -7
  123. data/spec/commands/randomkey_spec.rb +0 -20
  124. data/spec/commands/rename_spec.rb +0 -42
  125. data/spec/commands/renamenx_spec.rb +0 -41
  126. data/spec/commands/rpop_spec.rb +0 -34
  127. data/spec/commands/rpoplpush_spec.rb +0 -50
  128. data/spec/commands/rpush_spec.rb +0 -43
  129. data/spec/commands/rpushx_spec.rb +0 -46
  130. data/spec/commands/sadd_spec.rb +0 -45
  131. data/spec/commands/save_spec.rb +0 -7
  132. data/spec/commands/scan_each_spec.rb +0 -39
  133. data/spec/commands/scan_spec.rb +0 -55
  134. data/spec/commands/scard_spec.rb +0 -18
  135. data/spec/commands/script_spec.rb +0 -9
  136. data/spec/commands/sdiff_spec.rb +0 -47
  137. data/spec/commands/sdiffstore_spec.rb +0 -58
  138. data/spec/commands/select_spec.rb +0 -61
  139. data/spec/commands/set_spec.rb +0 -63
  140. data/spec/commands/setbit_spec.rb +0 -54
  141. data/spec/commands/setex_spec.rb +0 -22
  142. data/spec/commands/setnx_spec.rb +0 -25
  143. data/spec/commands/setrange_spec.rb +0 -30
  144. data/spec/commands/sinter_spec.rb +0 -39
  145. data/spec/commands/sinterstore_spec.rb +0 -53
  146. data/spec/commands/sismember_spec.rb +0 -29
  147. data/spec/commands/smembers_spec.rb +0 -28
  148. data/spec/commands/smove_spec.rb +0 -41
  149. data/spec/commands/sort_list_spec.rb +0 -21
  150. data/spec/commands/sort_set_spec.rb +0 -21
  151. data/spec/commands/sort_zset_spec.rb +0 -21
  152. data/spec/commands/spop_spec.rb +0 -25
  153. data/spec/commands/srandmember_spec.rb +0 -49
  154. data/spec/commands/srem_spec.rb +0 -40
  155. data/spec/commands/sscan_each_spec.rb +0 -48
  156. data/spec/commands/sscan_spec.rb +0 -39
  157. data/spec/commands/strlen_spec.rb +0 -18
  158. data/spec/commands/sunion_spec.rb +0 -42
  159. data/spec/commands/sunionstore_spec.rb +0 -59
  160. data/spec/commands/ttl_spec.rb +0 -40
  161. data/spec/commands/type_spec.rb +0 -36
  162. data/spec/commands/unwatch_spec.rb +0 -7
  163. data/spec/commands/watch_spec.rb +0 -16
  164. data/spec/commands/zadd_spec.rb +0 -123
  165. data/spec/commands/zcard_spec.rb +0 -19
  166. data/spec/commands/zcount_spec.rb +0 -39
  167. data/spec/commands/zincrby_spec.rb +0 -31
  168. data/spec/commands/zinterstore_spec.rb +0 -96
  169. data/spec/commands/zrange_spec.rb +0 -80
  170. data/spec/commands/zrangebyscore_spec.rb +0 -83
  171. data/spec/commands/zrank_spec.rb +0 -29
  172. data/spec/commands/zrem_spec.rb +0 -43
  173. data/spec/commands/zremrangebyrank_spec.rb +0 -27
  174. data/spec/commands/zremrangebyscore_spec.rb +0 -35
  175. data/spec/commands/zrevrange_spec.rb +0 -56
  176. data/spec/commands/zrevrangebyscore_spec.rb +0 -58
  177. data/spec/commands/zrevrank_spec.rb +0 -29
  178. data/spec/commands/zscan_each_spec.rb +0 -48
  179. data/spec/commands/zscan_spec.rb +0 -26
  180. data/spec/commands/zscore_spec.rb +0 -22
  181. data/spec/commands/zunionstore_spec.rb +0 -104
  182. data/spec/mock_redis_spec.rb +0 -86
  183. data/spec/spec_helper.rb +0 -63
  184. data/spec/support/redis_multiplexer.rb +0 -106
  185. data/spec/support/shared_examples/only_operates_on_hashes.rb +0 -13
  186. data/spec/support/shared_examples/only_operates_on_lists.rb +0 -13
  187. data/spec/support/shared_examples/only_operates_on_sets.rb +0 -13
  188. data/spec/support/shared_examples/only_operates_on_strings.rb +0 -13
  189. data/spec/support/shared_examples/only_operates_on_zsets.rb +0 -57
  190. data/spec/support/shared_examples/sorts_enumerables.rb +0 -56
  191. data/spec/transactions_spec.rb +0 -159
@@ -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
@@ -1,55 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe '#scan' do
4
- subject { MockRedis::Database.new(self) }
5
-
6
- let(:count) { 10 }
7
- let(:match) { '*' }
8
-
9
- before do
10
- allow(subject).to receive_message_chain(:data, :keys).and_return(collection)
11
- end
12
-
13
- context 'when no keys are found' do
14
- let(:collection) { [] }
15
-
16
- it 'returns a 0 cursor and an empty collection' do
17
- expect(subject.scan(0, count: count, match: match)).to eq(['0', []])
18
- end
19
- end
20
-
21
- context 'when keys are found' do
22
- context 'when count is lower than collection size' do
23
- let(:collection) { Array.new(count * 2) { |i| "mock:key#{i}" } }
24
- let(:expected_first) { [count.to_s, collection[0...count]] }
25
- let(:expected_second) { ['0', collection[count..-1]] }
26
-
27
- it 'returns a the next cursor and the collection' do
28
- expect(subject.scan(0, count: count, match: match)).to eq(expected_first)
29
- end
30
-
31
- it 'returns the correct results of the next cursor' do
32
- expect(subject.scan(count, count: count, match: match)).to eq(expected_second)
33
- end
34
- end
35
-
36
- context 'when count is greater or equal than collection size' do
37
- let(:collection) { Array.new(count) { |i| "mock:key#{i}" } }
38
- let(:expected) { ['0', collection] }
39
-
40
- it 'returns a 0 cursor and the collection' do
41
- expect(subject.scan(0, count: count, match: match)).to eq(expected)
42
- end
43
- end
44
-
45
- context 'when giving a custom match filter' do
46
- let(:match) { 'mock:key*' }
47
- let(:collection) { %w[mock:key mock:key2 mock:otherkey] }
48
- let(:expected) { ['0', %w[mock:key mock:key2]] }
49
-
50
- it 'returns a 0 cursor and the filtered collection' do
51
- expect(subject.scan(0, count: count, match: match)).to eq(expected)
52
- end
53
- end
54
- end
55
- end
@@ -1,18 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe '#scard(key)' do
4
- before { @key = 'mock-redis-test:scard' }
5
-
6
- it 'returns 0 for an empty set' do
7
- @redises.scard(@key).should == 0
8
- end
9
-
10
- it 'returns the number of elements in the set' do
11
- @redises.sadd(@key, 'one')
12
- @redises.sadd(@key, 'two')
13
- @redises.sadd(@key, 'three')
14
- @redises.scard(@key).should == 3
15
- end
16
-
17
- it_should_behave_like 'a set-only command'
18
- end
@@ -1,9 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe '#script(subcommand, *args)' do
4
- before { @key = 'mock-redis-test:script' }
5
-
6
- it 'works with load subcommand' do
7
- expect { @redises.send_without_checking(:script, :load, 'return 1') }.to_not raise_error
8
- end
9
- end
@@ -1,47 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe '#sdiff(key [, key, ...])' do
4
- before do
5
- @numbers = 'mock-redis-test:sdiff:numbers'
6
- @evens = 'mock-redis-test:sdiff:odds'
7
- @primes = 'mock-redis-test:sdiff: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 first set minus the second set' do
15
- @redises.sdiff(@numbers, @evens).should == %w[1 3 5 7 9]
16
- end
17
-
18
- it 'returns the first set minus all the other sets' do
19
- @redises.sdiff(@numbers, @evens, @primes).should == %w[1 9]
20
- end
21
-
22
- it 'treats missing keys as empty sets' do
23
- @redises.sdiff(@evens, 'mock-redis-test:nonesuch').should == %w[2 4 6 8 10]
24
- end
25
-
26
- it 'returns the first set when called with a single argument' do
27
- @redises.sdiff(@primes).should == %w[2 3 5 7]
28
- end
29
-
30
- it 'raises an error if given 0 arguments' do
31
- lambda do
32
- @redises.sdiff
33
- end.should raise_error(Redis::CommandError)
34
- end
35
-
36
- it 'raises an error if any argument is not a a set' do
37
- @redises.set('foo', 1)
38
-
39
- lambda do
40
- @redises.sdiff(@numbers, 'foo')
41
- end.should raise_error(Redis::CommandError)
42
-
43
- lambda do
44
- @redises.sdiff('foo', @numbers)
45
- end.should raise_error(Redis::CommandError)
46
- end
47
- end
@@ -1,58 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe '#sdiffstore(destination, key [, key, ...])' do
4
- before do
5
- @numbers = 'mock-redis-test:sdiffstore:numbers'
6
- @evens = 'mock-redis-test:sdiffstore:evens'
7
- @primes = 'mock-redis-test:sdiffstore:primes'
8
- @destination = 'mock-redis-test:sdiffstore: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.sdiffstore(@destination, @numbers, @evens).should == 5
17
- end
18
-
19
- it 'stores the resulting set' do
20
- @redises.sdiffstore(@destination, @numbers, @evens)
21
- @redises.smembers(@destination).should == %w[9 7 5 3 1]
22
- end
23
-
24
- it 'does not store empty sets' do
25
- @redises.sdiffstore(@destination, @numbers, @numbers).should == 0
26
- @redises.get(@destination).should be_nil
27
- end
28
-
29
- it 'treats missing keys as empty sets' do
30
- @redises.sdiffstore(@destination, @evens, 'mock-redis-test:nonesuch')
31
- @redises.smembers(@destination).should == %w[10 8 6 4 2]
32
- end
33
-
34
- it 'removes existing elements in destination' do
35
- @redises.sadd(@destination, 42)
36
-
37
- @redises.sdiffstore(@destination, @primes)
38
- @redises.smembers(@destination).should == %w[7 5 3 2]
39
- end
40
-
41
- it 'raises an error if given 0 sets' do
42
- lambda do
43
- @redises.sdiffstore(@destination)
44
- end.should raise_error(Redis::CommandError)
45
- end
46
-
47
- it 'raises an error if any argument is not a a set' do
48
- @redises.set('mock-redis-test:notset', 1)
49
-
50
- lambda do
51
- @redises.sdiffstore(@destination, @numbers, 'mock-redis-test:notset')
52
- end.should raise_error(Redis::CommandError)
53
-
54
- lambda do
55
- @redises.sdiffstore(@destination, 'mock-redis-test:notset', @numbers)
56
- end.should raise_error(Redis::CommandError)
57
- end
58
- end
@@ -1,61 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe '#select(db)' do
4
- before { @key = 'mock-redis-test:select' }
5
-
6
- it "returns 'OK'" do
7
- @redises.select(0).should == 'OK'
8
- end
9
-
10
- it "treats '0' and 0 the same" do
11
- @redises.select('0')
12
- @redises.set(@key, 'foo')
13
- @redises.select(0)
14
- @redises.get(@key).should == 'foo'
15
- end
16
-
17
- it 'switches databases' do
18
- @redises.select(0)
19
- @redises.set(@key, 'foo')
20
-
21
- @redises.select(1)
22
- @redises.get(@key).should be_nil
23
-
24
- @redises.select(0)
25
- @redises.get(@key).should == 'foo'
26
- end
27
-
28
- context '[mock only]' do
29
- # Time dependence introduces a bit of nondeterminism here
30
- before do
31
- @now = Time.now
32
- Time.stub(:now).and_return(@now)
33
-
34
- @mock = @redises.mock
35
-
36
- @mock.select(0)
37
- @mock.set(@key, 1)
38
- @mock.expire(@key, 100)
39
-
40
- @mock.select(1)
41
- @mock.set(@key, 2)
42
- @mock.expire(@key, 200)
43
- end
44
-
45
- it 'keeps expire times per-db' do
46
- @mock.select(0)
47
- @mock.ttl(@key).should == 100
48
-
49
- @mock.select(1)
50
- @mock.ttl(@key).should == 200
51
- end
52
-
53
- it 'keeps expire times in miliseconds per-db' do
54
- @mock.select(0)
55
- (100_000 - 1000..100_000 + 1000).should cover(@mock.pttl(@key))
56
-
57
- @mock.select(1)
58
- (200_000 - 1000..200_000 + 1000).should cover(@mock.pttl(@key))
59
- end
60
- end
61
- end
@@ -1,63 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe '#set(key, value)' do
4
- it "responds with 'OK'" do
5
- @redises.set('mock-redis-test', 1).should == 'OK'
6
- end
7
-
8
- context 'options' do
9
- it 'raises an error for EX seconds = 0' do
10
- expect do
11
- @redises.set('mock-redis-test', 1, ex: 0)
12
- end.to raise_error(Redis::CommandError, 'ERR invalid expire time in set')
13
- end
14
-
15
- it 'raises an error for PX milliseconds = 0' do
16
- expect do
17
- @redises.set('mock-redis-test', 1, px: 0)
18
- end.to raise_error(Redis::CommandError, 'ERR invalid expire time in set')
19
- end
20
-
21
- it 'accepts NX' do
22
- key = 'mock-redis-test'
23
- @redises.del(key)
24
- @redises.set(key, 1, nx: true).should == true
25
- @redises.set(key, 1, nx: true).should == false
26
- end
27
-
28
- it 'accepts XX' do
29
- key = 'mock-redis-test'
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
- context '[mock only]' do
37
- before(:all) do
38
- @mock = @redises.mock
39
- end
40
-
41
- before do
42
- @now = Time.now
43
- Time.stub(:now).and_return(@now)
44
- end
45
-
46
- it 'accepts EX seconds' do
47
- key = 'mock-redis-test'
48
- @mock.set(key, 1, ex: 1).should == 'OK'
49
- @mock.get(key).should_not be_nil
50
- Time.stub(:now).and_return(@now + 2)
51
- @mock.get(key).should be_nil
52
- end
53
-
54
- it 'accepts PX milliseconds' do
55
- key = 'mock-redis-test'
56
- @mock.set(key, 1, px: 1000).should == 'OK'
57
- @mock.get(key).should_not be_nil
58
- Time.stub(:now).and_return(@now + 2)
59
- @mock.get(key).should be_nil
60
- end
61
- end
62
- end
63
- end
@@ -1,54 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe '#setbit(key, offset)' do
4
- before do
5
- @key = 'mock-redis-test:setbit'
6
- @redises.set(@key, 'h') # ASCII 0x68
7
- end
8
-
9
- it "returns the original stored bit's value" do
10
- @redises.setbit(@key, 0, 1).should == 0
11
- @redises.setbit(@key, 1, 1).should == 1
12
- end
13
-
14
- it 'sets the bit within the string' do
15
- @redises.setbit(@key, 7, 1)
16
- @redises.get(@key).should == 'i' # ASCII 0x69
17
- end
18
-
19
- it 'unsets the bit within the string' do
20
- @redises.setbit(@key, 1, 0)
21
- @redises.get(@key).should == '(' # ASCII 0x28
22
- end
23
-
24
- it 'does the right thing with multibyte characters' do
25
- @redises.set(@key, '€99.94') # the euro sign is 3 bytes wide in UTF-8
26
- @redises.setbit(@key, 63, 1).should == 0
27
- @redises.get(@key).should == '€99.95'
28
- end
29
-
30
- it 'expands the string if necessary' do
31
- @redises.setbit(@key, 9, 1)
32
- @redises.get(@key).should == 'h@'
33
- end
34
-
35
- it 'sets added bits to 0' do
36
- @redises.setbit(@key, 17, 1)
37
- @redises.get(@key).should == "h\000@"
38
- end
39
-
40
- it 'treats missing keys as empty strings' do
41
- @redises.del(@key)
42
- @redises.setbit(@key, 1, 1)
43
- @redises.get(@key).should == '@'
44
- end
45
-
46
- it 'sets and retrieves bits' do
47
- @redises.setbit(@key, 22, 1)
48
- @redises.getbit(@key, 22).should == 1
49
- @redises.setbit(@key, 23, 0)
50
- @redises.getbit(@key, 23).should == 0
51
- end
52
-
53
- it_should_behave_like 'a string-only command'
54
- end
@@ -1,22 +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
- end
@@ -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