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,139 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe '#keys()' do
4
- it 'returns [] when no keys are found (no regex characters)' do
5
- @redises.keys('mock-redis-test:29016').should == []
6
- end
7
-
8
- it 'returns [] when no keys are found (some regex characters)' do
9
- @redises.keys('mock-redis-test:29016*').should == []
10
- end
11
-
12
- describe 'with pattern matching' do
13
- before do
14
- @redises.set('mock-redis-test:key', 0)
15
- @redises.set('mock-redis-test:key1', 1)
16
- @redises.set('mock-redis-test:key2', 2)
17
- @redises.set('mock-redis-test:key3', 3)
18
- @redises.set('mock-redis-test:key10', 10)
19
- @redises.set('mock-redis-test:key20', 20)
20
- @redises.set('mock-redis-test:key30', 30)
21
-
22
- @redises.set('mock-redis-test:regexp-key(1|22)', 40)
23
- @redises.set('mock-redis-test:regexp-key3+', 40)
24
- @redises.set('mock-redis-test:regexp-key33', 40)
25
- @redises.set('mock-redis-test:regexp-key4a', 40)
26
- @redises.set('mock-redis-test:regexp-key4-', 40)
27
- @redises.set('mock-redis-test:regexp-key4b', 40)
28
- @redises.set('mock-redis-test:regexp-key4c', 40)
29
-
30
- @redises.set('mock-redis-test:special-key?', 'true')
31
- @redises.set('mock-redis-test:special-key*', 'true')
32
- @redises.set('mock-redis-test:special-key-!?*', 'true')
33
- end
34
-
35
- describe 'the ? character' do
36
- it 'is treated as a single character (at the end of the pattern)' do
37
- @redises.keys('mock-redis-test:key?').sort.should == [
38
- 'mock-redis-test:key1',
39
- 'mock-redis-test:key2',
40
- 'mock-redis-test:key3',
41
- ]
42
- end
43
-
44
- it 'is treated as a single character (in the middle of the pattern)' do
45
- @redises.keys('mock-redis-test:key?0').sort.should == [
46
- 'mock-redis-test:key10',
47
- 'mock-redis-test:key20',
48
- 'mock-redis-test:key30',
49
- ]
50
- end
51
-
52
- it 'treats \\? as a literal ?' do
53
- @redises.keys('mock-redis-test:special-key\?').sort.should == [
54
- 'mock-redis-test:special-key?',
55
- ]
56
- end
57
-
58
- context 'multiple ? characters' do
59
- it "properly handles multiple consequtive '?' characters" do
60
- @redises.keys('mock-redis-test:special-key-???').sort.should == [
61
- 'mock-redis-test:special-key-!?*',
62
- ]
63
- end
64
-
65
- context '\\? as a literal ' do
66
- it 'handles multiple ? as both literal and special character' do
67
- @redises.keys('mock-redis-test:special-key-?\??').sort.should == [
68
- 'mock-redis-test:special-key-!?*',
69
- ]
70
- end
71
- end
72
- end
73
- end
74
-
75
- describe 'the * character' do
76
- it 'is treated as 0 or more characters' do
77
- @redises.keys('mock-redis-test:key*').sort.should == [
78
- 'mock-redis-test:key',
79
- 'mock-redis-test:key1',
80
- 'mock-redis-test:key10',
81
- 'mock-redis-test:key2',
82
- 'mock-redis-test:key20',
83
- 'mock-redis-test:key3',
84
- 'mock-redis-test:key30',
85
- ]
86
- end
87
-
88
- it 'treats \\* as a literal *' do
89
- @redises.keys('mock-redis-test:special-key\*').sort.should == [
90
- 'mock-redis-test:special-key*',
91
- ]
92
- end
93
- end
94
-
95
- describe 'character classes ([abcde])' do
96
- it 'matches any one of those characters' do
97
- @redises.keys('mock-redis-test:key[12]').sort.should == [
98
- 'mock-redis-test:key1',
99
- 'mock-redis-test:key2',
100
- ]
101
- end
102
- end
103
-
104
- describe 'the | character' do
105
- it "is treated as literal (not 'or')" do
106
- @redises.keys('mock-redis-test:regexp-key(1|22)').sort.should == [
107
- 'mock-redis-test:regexp-key(1|22)',
108
- ]
109
- end
110
- end
111
-
112
- describe 'the + character' do
113
- it "is treated as literal (not 'one or more' quantifier)" do
114
- @redises.keys('mock-redis-test:regexp-key3+').sort.should == [
115
- 'mock-redis-test:regexp-key3+',
116
- ]
117
- end
118
- end
119
-
120
- describe 'character classes ([a-c])' do
121
- it 'specifies a range which matches any lowercase letter from "a" to "c"' do
122
- @redises.keys('mock-redis-test:regexp-key4[a-c]').sort.should == [
123
- 'mock-redis-test:regexp-key4a',
124
- 'mock-redis-test:regexp-key4b',
125
- 'mock-redis-test:regexp-key4c',
126
- ]
127
- end
128
- end
129
-
130
- describe 'combining metacharacters' do
131
- it 'works with different metacharacters simultaneously' do
132
- @redises.keys('mock-redis-test:k*[12]?').sort.should == [
133
- 'mock-redis-test:key10',
134
- 'mock-redis-test:key20',
135
- ]
136
- end
137
- end
138
- end
139
- end
@@ -1,8 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe '#lastsave [mock only]' do
4
- # can't test against both since it's timing-dependent
5
- it 'returns a Unix time' do
6
- @redises.mock.lastsave.to_s.should =~ /^\d+$/
7
- end
8
- end
@@ -1,49 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe '#lindex(key, index)' do
4
- before { @key = 'mock-redis-test:69312' }
5
-
6
- it 'gets an element from the list by its index' do
7
- @redises.lpush(@key, 20)
8
- @redises.lpush(@key, 10)
9
-
10
- @redises.lindex(@key, 0).should == '10'
11
- @redises.lindex(@key, 1).should == '20'
12
- end
13
-
14
- it 'treats negative indices as coming from the right' do
15
- @redises.lpush(@key, 20)
16
- @redises.lpush(@key, 10)
17
-
18
- @redises.lindex(@key, -1).should == '20'
19
- @redises.lindex(@key, -2).should == '10'
20
- end
21
-
22
- it 'gets an element from the list by its index when index is a string' do
23
- @redises.lpush(@key, 20)
24
- @redises.lpush(@key, 10)
25
-
26
- @redises.lindex(@key, '0').should == '10'
27
- @redises.lindex(@key, '1').should == '20'
28
- @redises.lindex(@key, '-1').should == '20'
29
- @redises.lindex(@key, '-2').should == '10'
30
- end
31
-
32
- it 'returns nil if the index is too large (and positive)' do
33
- @redises.lpush(@key, 20)
34
-
35
- @redises.lindex(@key, 100).should be_nil
36
- end
37
-
38
- it 'returns nil if the index is too large (and negative)' do
39
- @redises.lpush(@key, 20)
40
-
41
- @redises.lindex(@key, -100).should be_nil
42
- end
43
-
44
- it 'returns nil for nonexistent values' do
45
- @redises.lindex(@key, 0).should be_nil
46
- end
47
-
48
- it_should_behave_like 'a list-only command'
49
- end
@@ -1,68 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe '#linsert(key, :before|:after, pivot, value)' do
4
- before { @key = 'mock-redis-test:48733' }
5
-
6
- it 'returns the new size of the list when the pivot is found' do
7
- @redises.lpush(@key, 'X')
8
-
9
- @redises.linsert(@key, :before, 'X', 'Y').should == 2
10
- @redises.lpushx(@key, 'X').should == 3
11
- end
12
-
13
- it 'does nothing when run against a nonexistent key' do
14
- @redises.linsert(@key, :before, 1, 2).should == 0
15
- @redises.get(@key).should be_nil
16
- end
17
-
18
- it 'returns -1 if the pivot is not found' do
19
- @redises.lpush(@key, 1)
20
- @redises.linsert(@key, :after, 'X', 'Y').should == -1
21
- end
22
-
23
- it 'inserts elements before the pivot when given :before as position' do
24
- @redises.lpush(@key, 'bert')
25
- @redises.linsert(@key, :before, 'bert', 'ernie')
26
-
27
- @redises.lindex(@key, 0).should == 'ernie'
28
- @redises.lindex(@key, 1).should == 'bert'
29
- end
30
-
31
- it "inserts elements before the pivot when given 'before' as position" do
32
- @redises.lpush(@key, 'bert')
33
- @redises.linsert(@key, 'before', 'bert', 'ernie')
34
-
35
- @redises.lindex(@key, 0).should == 'ernie'
36
- @redises.lindex(@key, 1).should == 'bert'
37
- end
38
-
39
- it 'inserts elements after the pivot when given :after as position' do
40
- @redises.lpush(@key, 'bert')
41
- @redises.linsert(@key, :after, 'bert', 'ernie')
42
-
43
- @redises.lindex(@key, 0).should == 'bert'
44
- @redises.lindex(@key, 1).should == 'ernie'
45
- end
46
-
47
- it "inserts elements after the pivot when given 'after' as position" do
48
- @redises.lpush(@key, 'bert')
49
- @redises.linsert(@key, 'after', 'bert', 'ernie')
50
-
51
- @redises.lindex(@key, 0).should == 'bert'
52
- @redises.lindex(@key, 1).should == 'ernie'
53
- end
54
-
55
- it 'raises an error when given a position that is neither before nor after' do
56
- lambda do
57
- @redises.linsert(@key, :near, 1, 2)
58
- end.should raise_error(Redis::CommandError)
59
- end
60
-
61
- it 'stores values as strings' do
62
- @redises.lpush(@key, 1)
63
- @redises.linsert(@key, :before, 1, 2)
64
- @redises.lindex(@key, 0).should == '2'
65
- end
66
-
67
- it_should_behave_like 'a list-only command'
68
- end
@@ -1,16 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe '#llen(key)' do
4
- before { @key = 'mock-redis-test:78407' }
5
-
6
- it 'returns 0 for a nonexistent key' do
7
- @redises.llen(@key).should == 0
8
- end
9
-
10
- it 'returns the length of the list' do
11
- 5.times { @redises.lpush(@key, 'X') }
12
- @redises.llen(@key).should == 5
13
- end
14
-
15
- it_should_behave_like 'a list-only command'
16
- end
@@ -1,72 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe '#lmove(source, destination, wherefrom, whereto)' do
4
- before do
5
- @list1 = 'mock-redis-test:lmove-list1'
6
- @list2 = 'mock-redis-test:lmove-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.lmove(@list1, @list2, 'left', 'right').should == 'a'
17
- end
18
-
19
- it "returns nil and doesn't append if source empty" do
20
- @redises.lmove('empty', @list1, 'left', 'right').should be_nil
21
- @redises.lrange(@list1, 0, -1).should == %w[a b]
22
- end
23
-
24
- it 'takes the first element of source and prepends it to destination' do
25
- @redises.lmove(@list1, @list2, 'left', 'left')
26
-
27
- @redises.lrange(@list1, 0, -1).should == %w[b]
28
- @redises.lrange(@list2, 0, -1).should == %w[a x y]
29
- end
30
-
31
- it 'takes the first element of source and appends it to destination' do
32
- @redises.lmove(@list1, @list2, 'left', 'right')
33
-
34
- @redises.lrange(@list1, 0, -1).should == %w[b]
35
- @redises.lrange(@list2, 0, -1).should == %w[x y a]
36
- end
37
-
38
- it 'takes the last element of source and prepends it to destination' do
39
- @redises.lmove(@list1, @list2, 'right', 'left')
40
-
41
- @redises.lrange(@list1, 0, -1).should == %w[a]
42
- @redises.lrange(@list2, 0, -1).should == %w[b x y]
43
- end
44
-
45
- it 'takes the last element of source and appends it to destination' do
46
- @redises.lmove(@list1, @list2, 'right', 'right')
47
-
48
- @redises.lrange(@list1, 0, -1).should == %w[a]
49
- @redises.lrange(@list2, 0, -1).should == %w[x y b]
50
- end
51
-
52
- it 'rotates a list when source and destination are the same' do
53
- @redises.lmove(@list1, @list1, 'left', 'right')
54
- @redises.lrange(@list1, 0, -1).should == %w[b a]
55
- end
56
-
57
- it 'removes empty lists' do
58
- @redises.llen(@list1).times { @redises.lmove(@list1, @list2, 'left', 'right') }
59
- @redises.get(@list1).should be_nil
60
- end
61
-
62
- it 'raises an error for non-list source value' do
63
- @redises.set(@list1, 'string value')
64
-
65
- lambda do
66
- @redises.lmove(@list1, @list2, 'left', 'right')
67
- end.should raise_error(Redis::CommandError)
68
- end
69
-
70
- let(:default_error) { RedisMultiplexer::MismatchedResponse }
71
- it_should_behave_like 'a list-only command'
72
- end
@@ -1,35 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe '#lpop(key)' do
4
- before { @key = 'mock-redis-test:65374' }
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.lpop(@key).should == '2'
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.lpop(@key)
18
-
19
- @redises.lpop(@key).should be_nil
20
- end
21
-
22
- it 'returns nil for nonexistent values' do
23
- @redises.lpop(@key).should be_nil
24
- end
25
-
26
- it 'removes empty lists' do
27
- @redises.lpush(@key, 'foo')
28
- @redises.lpop(@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,43 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe '#lpush(key, value)' do
4
- before { @key = 'mock-redis-test:57367' }
5
-
6
- it 'returns the new size of the list' do
7
- @redises.lpush(@key, 'X').should == 1
8
- @redises.lpush(@key, 'X').should == 2
9
- end
10
-
11
- it 'creates a new list when run against a nonexistent key' do
12
- @redises.lpush(@key, 'value')
13
- @redises.llen(@key).should == 1
14
- end
15
-
16
- it 'prepends items to the list' do
17
- @redises.lpush(@key, 'bert')
18
- @redises.lpush(@key, 'ernie')
19
-
20
- @redises.lindex(@key, 0).should == 'ernie'
21
- @redises.lindex(@key, 1).should == 'bert'
22
- end
23
-
24
- it 'stores values as strings' do
25
- @redises.lpush(@key, 1)
26
- @redises.lindex(@key, 0).should == '1'
27
- end
28
-
29
- it 'supports a variable number of arguments' do
30
- @redises.lpush(@key, [1, 2, 3]).should == 3
31
- @redises.lindex(@key, 0).should == '3'
32
- @redises.lindex(@key, 1).should == '2'
33
- @redises.lindex(@key, 2).should == '1'
34
- end
35
-
36
- it 'raises an error if an empty array is given' do
37
- lambda do
38
- @redises.lpush(@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 '#lpushx(key, value)' do
4
- before { @key = 'mock-redis-test:81267' }
5
-
6
- it 'returns the new size of the list' do
7
- @redises.lpush(@key, 'X')
8
-
9
- @redises.lpushx(@key, 'X').should == 2
10
- @redises.lpushx(@key, 'X').should == 3
11
- end
12
-
13
- it 'does nothing when run against a nonexistent key' do
14
- @redises.lpushx(@key, 'value')
15
- @redises.get(@key).should be_nil
16
- end
17
-
18
- it 'prepends items to the list' do
19
- @redises.lpush(@key, 'bert')
20
- @redises.lpushx(@key, 'ernie')
21
-
22
- @redises.lindex(@key, 0).should == 'ernie'
23
- @redises.lindex(@key, 1).should == 'bert'
24
- end
25
-
26
- it 'stores values as strings' do
27
- @redises.lpush(@key, 1)
28
- @redises.lpushx(@key, 2)
29
- @redises.lindex(@key, 0).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.lpushx(@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.lpushx(@key, [1, 2]).should == 3
42
- @redises.lrange(@key, 0, -1).should == %w[2 1 X]
43
- end
44
-
45
- it_should_behave_like 'a list-only command'
46
- end
@@ -1,51 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe '#lrange(key, start, stop)' do
4
- before do
5
- @key = 'mock-redis-test:68036'
6
-
7
- @redises.lpush(@key, 'v4')
8
- @redises.lpush(@key, 'v3')
9
- @redises.lpush(@key, 'v2')
10
- @redises.lpush(@key, 'v1')
11
- @redises.lpush(@key, 'v0')
12
- end
13
-
14
- it 'returns a subset of the list inclusive of the right end' do
15
- @redises.lrange(@key, 0, 2).should == %w[v0 v1 v2]
16
- end
17
-
18
- it 'returns a subset of the list when start and end are strings' do
19
- @redises.lrange(@key, '0', '2').should == %w[v0 v1 v2]
20
- end
21
-
22
- it 'returns an empty list when start > end' do
23
- @redises.lrange(@key, 3, 2).should == []
24
- end
25
-
26
- it 'works with a negative stop index' do
27
- @redises.lrange(@key, 2, -1).should == %w[v2 v3 v4]
28
- end
29
-
30
- it 'works with negative start and stop indices' do
31
- @redises.lrange(@key, -2, -1).should == %w[v3 v4]
32
- end
33
-
34
- it 'works with negative start indices less than list length' do
35
- @redises.lrange(@key, -10, -2).should == %w[v0 v1 v2 v3]
36
- end
37
-
38
- it 'returns [] when run against a nonexistent value' do
39
- @redises.lrange('mock-redis-test:bogus-key', 0, 1).should == []
40
- end
41
-
42
- it 'returns [] when start is too large' do
43
- @redises.lrange(@key, 100, 100).should == []
44
- end
45
-
46
- it 'finds the end of the list correctly when end is too large' do
47
- @redises.lrange(@key, 4, 10).should == %w[v4]
48
- end
49
-
50
- it_should_behave_like 'a list-only command'
51
- end
@@ -1,80 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe '#lrem(key, count, value)' do
4
- before do
5
- @key = 'mock-redis-test:66767'
6
-
7
- %w[99 bottles of beer on the wall
8
- 99 bottles of beer
9
- take one down
10
- pass it around
11
- 98 bottles of beer on the wall].reverse_each do |x|
12
- @redises.lpush(@key, x)
13
- end
14
- end
15
-
16
- it 'deletes the first count instances of key when count > 0' do
17
- @redises.lrem(@key, 2, 'bottles')
18
-
19
- @redises.lrange(@key, 0, 8).should == %w[
20
- 99 of beer on the wall
21
- 99 of beer
22
- ]
23
-
24
- @redises.lrange(@key, -7, -1).should == %w[98 bottles of beer on the wall]
25
- end
26
-
27
- it 'deletes the last count instances of key when count < 0' do
28
- @redises.lrem(@key, -2, 'bottles')
29
-
30
- @redises.lrange(@key, 0, 9).should == %w[
31
- 99 bottles of beer on the wall
32
- 99 of beer
33
- ]
34
-
35
- @redises.lrange(@key, -6, -1).should == %w[98 of beer on the wall]
36
- end
37
-
38
- it 'deletes all instances of key when count == 0' do
39
- @redises.lrem(@key, 0, 'bottles')
40
- @redises.lrange(@key, 0, -1).grep(/bottles/).should be_empty
41
- end
42
-
43
- it 'returns the number of elements deleted' do
44
- @redises.lrem(@key, 2, 'bottles').should == 2
45
- end
46
-
47
- it 'returns the number of elements deleted even if you ask for more' do
48
- @redises.lrem(@key, 10, 'bottles').should == 3
49
- end
50
-
51
- it 'stringifies value' do
52
- @redises.lrem(@key, 0, 99).should == 2
53
- end
54
-
55
- it 'returns 0 when run against a nonexistent value' do
56
- @redises.lrem('mock-redis-test:bogus-key', 0, 1).should == 0
57
- end
58
-
59
- it 'returns 0 when run against an empty list' do
60
- @redises.llen(@key).times { @redises.lpop(@key) } # empty the list
61
- @redises.lrem(@key, 0, 'beer').should == 0
62
- end
63
-
64
- it 'raises an error if the value does not look like an integer' do
65
- lambda do
66
- @redises.lrem(@key, 'foo', 'bottles')
67
- end.should raise_error(Redis::CommandError)
68
- end
69
-
70
- it 'removes empty lists' do
71
- other_key = "mock-redis-test:lrem-#{__LINE__}"
72
-
73
- @redises.lpush(other_key, 'foo')
74
- @redises.lrem(other_key, 0, 'foo')
75
-
76
- @redises.get(other_key).should be_nil
77
- end
78
-
79
- it_should_behave_like 'a list-only command'
80
- end
@@ -1,43 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe '#lset(key, index, value)' do
4
- before do
5
- @key = 'mock-redis-test:21522'
6
-
7
- @redises.lpush(@key, 'v1')
8
- @redises.lpush(@key, 'v0')
9
- end
10
-
11
- it "returns 'OK'" do
12
- @redises.lset(@key, 0, 'newthing').should == 'OK'
13
- end
14
-
15
- it "sets the list's value at index to value" do
16
- @redises.lset(@key, 0, 'newthing')
17
- @redises.lindex(@key, 0).should == 'newthing'
18
- end
19
-
20
- it "sets the list's value at index to value when the index is a string" do
21
- @redises.lset(@key, '0', 'newthing')
22
- @redises.lindex(@key, 0).should == 'newthing'
23
- end
24
-
25
- it 'stringifies value' do
26
- @redises.lset(@key, 0, 12_345)
27
- @redises.lindex(@key, 0).should == '12345'
28
- end
29
-
30
- it 'raises an exception for nonexistent keys' do
31
- lambda do
32
- @redises.lset('mock-redis-test:bogus-key', 100, 'value')
33
- end.should raise_error(Redis::CommandError)
34
- end
35
-
36
- it 'raises an exception for out-of-range indices' do
37
- lambda do
38
- @redises.lset(@key, 100, 'value')
39
- end.should raise_error(Redis::CommandError)
40
- end
41
-
42
- it_should_behave_like 'a list-only command'
43
- end