mock_redis 0.14.1 → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.overcommit.yml +1 -1
- data/.rubocop.yml +91 -0
- data/.simplecov +4 -0
- data/.travis.yml +14 -2
- data/CHANGELOG.md +4 -0
- data/Gemfile +4 -2
- data/README.md +1 -0
- data/Rakefile +2 -2
- data/lib/mock_redis.rb +25 -26
- data/lib/mock_redis/assertions.rb +0 -1
- data/lib/mock_redis/database.rb +35 -28
- data/lib/mock_redis/expire_wrapper.rb +1 -1
- data/lib/mock_redis/future.rb +1 -1
- data/lib/mock_redis/hash_methods.rb +18 -17
- data/lib/mock_redis/indifferent_hash.rb +4 -0
- data/lib/mock_redis/info_method.rb +109 -108
- data/lib/mock_redis/list_methods.rb +17 -16
- data/lib/mock_redis/multi_db_wrapper.rb +5 -4
- data/lib/mock_redis/pipelined_wrapper.rb +3 -3
- data/lib/mock_redis/set_methods.rb +10 -9
- data/lib/mock_redis/sort_method.rb +11 -12
- data/lib/mock_redis/string_methods.rb +26 -29
- data/lib/mock_redis/transaction_wrapper.rb +7 -8
- data/lib/mock_redis/utility_methods.rb +9 -12
- data/lib/mock_redis/version.rb +1 -1
- data/lib/mock_redis/zset.rb +22 -23
- data/lib/mock_redis/zset_methods.rb +25 -25
- data/spec/cloning_spec.rb +17 -18
- data/spec/commands/append_spec.rb +4 -4
- data/spec/commands/auth_spec.rb +1 -1
- data/spec/commands/bgrewriteaof_spec.rb +2 -2
- data/spec/commands/bgsave_spec.rb +2 -2
- data/spec/commands/bitcount_spec.rb +3 -3
- data/spec/commands/blpop_spec.rb +10 -10
- data/spec/commands/brpop_spec.rb +10 -10
- data/spec/commands/brpoplpush_spec.rb +9 -9
- data/spec/commands/connected_spec.rb +2 -2
- data/spec/commands/dbsize_spec.rb +3 -3
- data/spec/commands/decr_spec.rb +7 -7
- data/spec/commands/decrby_spec.rb +7 -7
- data/spec/commands/del_spec.rb +4 -4
- data/spec/commands/disconnect_spec.rb +2 -2
- data/spec/commands/echo_spec.rb +4 -4
- data/spec/commands/exists_spec.rb +3 -3
- data/spec/commands/expire_spec.rb +13 -13
- data/spec/commands/expireat_spec.rb +6 -7
- data/spec/commands/flushall_spec.rb +5 -5
- data/spec/commands/flushdb_spec.rb +5 -5
- data/spec/commands/future_spec.rb +2 -2
- data/spec/commands/get_spec.rb +7 -7
- data/spec/commands/getbit_spec.rb +6 -6
- data/spec/commands/getrange_spec.rb +9 -9
- data/spec/commands/getset_spec.rb +7 -7
- data/spec/commands/hash_operator_spec.rb +5 -5
- data/spec/commands/hdel_spec.rb +12 -12
- data/spec/commands/hexists_spec.rb +7 -7
- data/spec/commands/hget_spec.rb +7 -7
- data/spec/commands/hgetall_spec.rb +6 -6
- data/spec/commands/hincrby_spec.rb +14 -14
- data/spec/commands/hincrbyfloat_spec.rb +14 -14
- data/spec/commands/hkeys_spec.rb +5 -5
- data/spec/commands/hlen_spec.rb +5 -5
- data/spec/commands/hmget_spec.rb +8 -8
- data/spec/commands/hmset_spec.rb +10 -10
- data/spec/commands/hset_spec.rb +11 -11
- data/spec/commands/hsetnx_spec.rb +14 -14
- data/spec/commands/hvals_spec.rb +5 -5
- data/spec/commands/incr_spec.rb +7 -7
- data/spec/commands/incrby_spec.rb +11 -11
- data/spec/commands/incrbyfloat_spec.rb +11 -11
- data/spec/commands/info_spec.rb +30 -30
- data/spec/commands/keys_spec.rb +42 -43
- data/spec/commands/lastsave_spec.rb +2 -2
- data/spec/commands/lindex_spec.rb +15 -15
- data/spec/commands/linsert_spec.rb +13 -13
- data/spec/commands/llen_spec.rb +4 -4
- data/spec/commands/lpop_spec.rb +6 -6
- data/spec/commands/lpush_spec.rb +16 -16
- data/spec/commands/lpushx_spec.rb +13 -13
- data/spec/commands/lrange_spec.rb +12 -12
- data/spec/commands/lrem_spec.rb +15 -15
- data/spec/commands/lset_spec.rb +12 -12
- data/spec/commands/ltrim_spec.rb +9 -9
- data/spec/commands/mapped_hmget_spec.rb +8 -8
- data/spec/commands/mapped_hmset_spec.rb +12 -12
- data/spec/commands/mapped_mget_spec.rb +4 -4
- data/spec/commands/mapped_mset_spec.rb +1 -1
- data/spec/commands/mget_spec.rb +11 -11
- data/spec/commands/move_spec.rb +29 -29
- data/spec/commands/mset_spec.rb +4 -4
- data/spec/commands/msetnx_spec.rb +10 -10
- data/spec/commands/persist_spec.rb +9 -10
- data/spec/commands/pexpire_spec.rb +12 -13
- data/spec/commands/pexpireat_spec.rb +6 -6
- data/spec/commands/ping_spec.rb +1 -1
- data/spec/commands/pipelined_spec.rb +5 -5
- data/spec/commands/pttl_spec.rb +5 -5
- data/spec/commands/randomkey_spec.rb +3 -3
- data/spec/commands/rename_spec.rb +9 -9
- data/spec/commands/renamenx_spec.rb +10 -10
- data/spec/commands/rpop_spec.rb +6 -6
- data/spec/commands/rpoplpush_spec.rb +7 -7
- data/spec/commands/rpush_spec.rb +16 -16
- data/spec/commands/rpushx_spec.rb +13 -13
- data/spec/commands/sadd_spec.rb +8 -9
- data/spec/commands/scan_spec.rb +6 -7
- data/spec/commands/scard_spec.rb +3 -3
- data/spec/commands/sdiff_spec.rb +10 -10
- data/spec/commands/sdiffstore_spec.rb +10 -10
- data/spec/commands/select_spec.rb +7 -7
- data/spec/commands/setbit_spec.rb +13 -13
- data/spec/commands/setex_spec.rb +4 -4
- data/spec/commands/setnx_spec.rb +4 -4
- data/spec/commands/setrange_spec.rb +12 -12
- data/spec/commands/sinter_spec.rb +8 -10
- data/spec/commands/sinterstore_spec.rb +9 -9
- data/spec/commands/sismember_spec.rb +5 -5
- data/spec/commands/smembers_spec.rb +5 -5
- data/spec/commands/smove_spec.rb +7 -7
- data/spec/commands/sort_list_spec.rb +3 -3
- data/spec/commands/sort_set_spec.rb +3 -3
- data/spec/commands/sort_zset_spec.rb +3 -3
- data/spec/commands/spop_spec.rb +4 -4
- data/spec/commands/srandmember_spec.rb +8 -8
- data/spec/commands/srem_spec.rb +9 -9
- data/spec/commands/strlen_spec.rb +4 -4
- data/spec/commands/sunion_spec.rb +7 -9
- data/spec/commands/sunionstore_spec.rb +9 -9
- data/spec/commands/ttl_spec.rb +5 -5
- data/spec/commands/type_spec.rb +1 -1
- data/spec/commands/zadd_spec.rb +10 -10
- data/spec/commands/zcard_spec.rb +4 -4
- data/spec/commands/zcount_spec.rb +14 -14
- data/spec/commands/zincrby_spec.rb +6 -6
- data/spec/commands/zinterstore_spec.rb +17 -17
- data/spec/commands/zrange_spec.rb +12 -12
- data/spec/commands/zrangebyscore_spec.rb +26 -26
- data/spec/commands/zrank_spec.rb +4 -4
- data/spec/commands/zrem_spec.rb +9 -9
- data/spec/commands/zremrangebyrank_spec.rb +5 -5
- data/spec/commands/zremrangebyscore_spec.rb +9 -7
- data/spec/commands/zrevrange_spec.rb +10 -10
- data/spec/commands/zrevrangebyscore_spec.rb +14 -14
- data/spec/commands/zrevrank_spec.rb +4 -4
- data/spec/commands/zscore_spec.rb +5 -5
- data/spec/commands/zunionstore_spec.rb +18 -18
- data/spec/mock_redis_spec.rb +11 -1
- data/spec/spec_helper.rb +13 -4
- data/spec/support/redis_multiplexer.rb +39 -31
- data/spec/support/shared_examples/only_operates_on_hashes.rb +2 -2
- data/spec/support/shared_examples/only_operates_on_lists.rb +2 -2
- data/spec/support/shared_examples/only_operates_on_sets.rb +2 -2
- data/spec/support/shared_examples/only_operates_on_strings.rb +3 -3
- data/spec/support/shared_examples/only_operates_on_zsets.rb +12 -12
- data/spec/support/shared_examples/sorts_enumerables.rb +12 -12
- data/spec/transactions_spec.rb +18 -18
- metadata +5 -3
data/lib/mock_redis/version.rb
CHANGED
data/lib/mock_redis/zset.rb
CHANGED
@@ -12,7 +12,7 @@ class MockRedis
|
|
12
12
|
|
13
13
|
def initialize
|
14
14
|
@members = Set.new
|
15
|
-
@scores =
|
15
|
+
@scores = {}
|
16
16
|
end
|
17
17
|
|
18
18
|
def initialize_copy(source)
|
@@ -33,39 +33,39 @@ class MockRedis
|
|
33
33
|
|
34
34
|
def delete?(member)
|
35
35
|
scores.delete(member)
|
36
|
-
members.delete?(member)
|
36
|
+
members.delete?(member) && self
|
37
37
|
end
|
38
38
|
|
39
39
|
def each
|
40
|
-
members.each {|m| yield score(m), m}
|
40
|
+
members.each { |m| yield score(m), m }
|
41
41
|
end
|
42
42
|
|
43
43
|
def in_range(min, max)
|
44
44
|
in_from_the_left = case min
|
45
|
-
when
|
46
|
-
|
47
|
-
when
|
48
|
-
|
45
|
+
when '-inf'
|
46
|
+
lambda { |_| true }
|
47
|
+
when '+inf'
|
48
|
+
lambda { |_| false }
|
49
49
|
when /\((.*)$/
|
50
|
-
|
51
|
-
lambda {|x| x.to_f > val }
|
50
|
+
val = $1.to_f
|
51
|
+
lambda { |x| x.to_f > val }
|
52
52
|
else
|
53
|
-
lambda {|x| x.to_f >= min.to_f }
|
53
|
+
lambda { |x| x.to_f >= min.to_f }
|
54
54
|
end
|
55
55
|
|
56
56
|
in_from_the_right = case max
|
57
|
-
when
|
58
|
-
|
59
|
-
when
|
60
|
-
|
57
|
+
when '-inf'
|
58
|
+
lambda { |_| false }
|
59
|
+
when '+inf'
|
60
|
+
lambda { |_| true }
|
61
61
|
when /\((.*)$/
|
62
|
-
|
63
|
-
lambda {|x| x.to_f < val }
|
62
|
+
val = $1.to_f
|
63
|
+
lambda { |x| x.to_f < val }
|
64
64
|
else
|
65
|
-
lambda {|x| x.to_f <= max.to_f }
|
65
|
+
lambda { |x| x.to_f <= max.to_f }
|
66
66
|
end
|
67
67
|
|
68
|
-
sorted.find_all do |(score,
|
68
|
+
sorted.find_all do |(score, _member)|
|
69
69
|
in_from_the_left[score] && in_from_the_right[score]
|
70
70
|
end
|
71
71
|
end
|
@@ -74,8 +74,8 @@ class MockRedis
|
|
74
74
|
if !block_given?
|
75
75
|
intersection(other, &:+)
|
76
76
|
else
|
77
|
-
|
78
|
-
new_score = yield(
|
77
|
+
members.intersection(other.members).reduce(self.class.new) do |acc, m|
|
78
|
+
new_score = yield(score(m), other.score(m))
|
79
79
|
acc.add(new_score, m)
|
80
80
|
end
|
81
81
|
end
|
@@ -99,12 +99,11 @@ class MockRedis
|
|
99
99
|
if !block_given?
|
100
100
|
union(other, &:+)
|
101
101
|
else
|
102
|
-
|
103
|
-
new_score = yield(
|
102
|
+
members.union(other.members).reduce(self.class.new) do |acc, m|
|
103
|
+
new_score = yield(score(m), other.score(m))
|
104
104
|
acc.add(new_score, m)
|
105
105
|
end
|
106
106
|
end
|
107
107
|
end
|
108
|
-
|
109
108
|
end
|
110
109
|
end
|
@@ -21,9 +21,9 @@ class MockRedis
|
|
21
21
|
score, member = args
|
22
22
|
assert_scorey(score) unless score =~ /(\+|\-)inf/
|
23
23
|
retval = !zscore(key, member)
|
24
|
-
with_zset_at(key) {|z| z.add(score, member.to_s)}
|
24
|
+
with_zset_at(key) { |z| z.add(score, member.to_s) }
|
25
25
|
else
|
26
|
-
raise Redis::CommandError,
|
26
|
+
raise Redis::CommandError, 'ERR wrong number of arguments'
|
27
27
|
end
|
28
28
|
|
29
29
|
retval
|
@@ -52,20 +52,20 @@ class MockRedis
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
-
def zinterstore(destination, keys, options={})
|
55
|
+
def zinterstore(destination, keys, options = {})
|
56
56
|
assert_has_args(keys, 'zinterstore')
|
57
57
|
|
58
58
|
data[destination] = combine_weighted_zsets(keys, options, :intersection)
|
59
59
|
zcard(destination)
|
60
60
|
end
|
61
61
|
|
62
|
-
def zrange(key, start, stop, options={})
|
62
|
+
def zrange(key, start, stop, options = {})
|
63
63
|
with_zset_at(key) do |z|
|
64
64
|
to_response(z.sorted[start.to_i..stop.to_i] || [], options)
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
-
def zrangebyscore(key, min, max, options={})
|
68
|
+
def zrangebyscore(key, min, max, options = {})
|
69
69
|
assert_range_args(min, max)
|
70
70
|
|
71
71
|
with_zset_at(key) do |zset|
|
@@ -75,12 +75,12 @@ class MockRedis
|
|
75
75
|
end
|
76
76
|
|
77
77
|
def zrank(key, member)
|
78
|
-
with_zset_at(key) {|z| z.sorted_members.index(member.to_s) }
|
78
|
+
with_zset_at(key) { |z| z.sorted_members.index(member.to_s) }
|
79
79
|
end
|
80
80
|
|
81
81
|
def zrem(key, *args)
|
82
82
|
if !args.first.is_a?(Array)
|
83
|
-
retval = with_zset_at(key) {|z| !!z.delete?(args.first.to_s)}
|
83
|
+
retval = with_zset_at(key) { |z| !!z.delete?(args.first.to_s) }
|
84
84
|
else
|
85
85
|
args = args.first
|
86
86
|
retval = args.map { |member| !!zscore(key, member.to_s) }.count(true)
|
@@ -92,7 +92,7 @@ class MockRedis
|
|
92
92
|
retval
|
93
93
|
end
|
94
94
|
|
95
|
-
def zrevrange(key, start, stop, options={})
|
95
|
+
def zrevrange(key, start, stop, options = {})
|
96
96
|
with_zset_at(key) do |z|
|
97
97
|
to_response(z.sorted.reverse[start..stop] || [], options)
|
98
98
|
end
|
@@ -100,7 +100,7 @@ class MockRedis
|
|
100
100
|
|
101
101
|
def zremrangebyrank(key, start, stop)
|
102
102
|
zrange(key, start, stop).
|
103
|
-
each {|member| zrem(key, member)}.
|
103
|
+
each { |member| zrem(key, member) }.
|
104
104
|
size
|
105
105
|
end
|
106
106
|
|
@@ -108,11 +108,11 @@ class MockRedis
|
|
108
108
|
assert_range_args(min, max)
|
109
109
|
|
110
110
|
zrangebyscore(key, min, max).
|
111
|
-
each {|member| zrem(key, member)}.
|
111
|
+
each { |member| zrem(key, member) }.
|
112
112
|
size
|
113
113
|
end
|
114
114
|
|
115
|
-
def zrevrangebyscore(key, max, min, options={})
|
115
|
+
def zrevrangebyscore(key, max, min, options = {})
|
116
116
|
assert_range_args(min, max)
|
117
117
|
|
118
118
|
with_zset_at(key) do |zset|
|
@@ -125,7 +125,7 @@ class MockRedis
|
|
125
125
|
end
|
126
126
|
|
127
127
|
def zrevrank(key, member)
|
128
|
-
with_zset_at(key) {|z| z.sorted_members.reverse.index(member.to_s) }
|
128
|
+
with_zset_at(key) { |z| z.sorted_members.reverse.index(member.to_s) }
|
129
129
|
end
|
130
130
|
|
131
131
|
def zscore(key, member)
|
@@ -135,7 +135,7 @@ class MockRedis
|
|
135
135
|
end
|
136
136
|
end
|
137
137
|
|
138
|
-
def zunionstore(destination, keys, options={})
|
138
|
+
def zunionstore(destination, keys, options = {})
|
139
139
|
assert_has_args(keys, 'zunionstore')
|
140
140
|
|
141
141
|
data[destination] = combine_weighted_zsets(keys, options, :union)
|
@@ -143,13 +143,14 @@ class MockRedis
|
|
143
143
|
end
|
144
144
|
|
145
145
|
private
|
146
|
+
|
146
147
|
def apply_limit(collection, limit)
|
147
148
|
if limit
|
148
149
|
if limit.is_a?(Array) && limit.length == 2
|
149
150
|
offset, count = limit
|
150
151
|
collection.drop(offset).take(count)
|
151
152
|
else
|
152
|
-
raise Redis::CommandError,
|
153
|
+
raise Redis::CommandError, 'ERR syntax error'
|
153
154
|
end
|
154
155
|
else
|
155
156
|
collection
|
@@ -157,7 +158,7 @@ class MockRedis
|
|
157
158
|
end
|
158
159
|
|
159
160
|
def to_response(score_member_pairs, options)
|
160
|
-
score_member_pairs.map do |(score,member)|
|
161
|
+
score_member_pairs.map do |(score, member)|
|
161
162
|
if options[:with_scores] || options[:withscores]
|
162
163
|
[member, score.to_f]
|
163
164
|
else
|
@@ -169,18 +170,18 @@ class MockRedis
|
|
169
170
|
def combine_weighted_zsets(keys, options, how)
|
170
171
|
weights = options.fetch(:weights, keys.map { 1 })
|
171
172
|
if weights.length != keys.length
|
172
|
-
raise Redis::CommandError,
|
173
|
+
raise Redis::CommandError, 'ERR syntax error'
|
173
174
|
end
|
174
175
|
|
175
176
|
aggregator = case options.fetch(:aggregate, :sum).to_s.downcase.to_sym
|
176
177
|
when :sum
|
177
|
-
proc {|a,b| [a,b].compact.reduce(&:+)}
|
178
|
+
proc { |a, b| [a, b].compact.reduce(&:+) }
|
178
179
|
when :min
|
179
|
-
proc {|a,b| [a,b].compact.min}
|
180
|
+
proc { |a, b| [a, b].compact.min }
|
180
181
|
when :max
|
181
|
-
proc {|a,b| [a,b].compact.max}
|
182
|
+
proc { |a, b| [a, b].compact.max }
|
182
183
|
else
|
183
|
-
raise Redis::CommandError,
|
184
|
+
raise Redis::CommandError, 'ERR syntax error'
|
184
185
|
end
|
185
186
|
|
186
187
|
with_zsets_at(*keys) do |*zsets|
|
@@ -192,11 +193,10 @@ class MockRedis
|
|
192
193
|
za.send(how, zb, &aggregator)
|
193
194
|
end
|
194
195
|
end
|
195
|
-
|
196
196
|
end
|
197
197
|
|
198
198
|
def with_zset_at(key, &blk)
|
199
|
-
with_thing_at(key, :assert_zsety, proc {Zset.new}, &blk)
|
199
|
+
with_thing_at(key, :assert_zsety, proc { Zset.new }, &blk)
|
200
200
|
end
|
201
201
|
|
202
202
|
def with_zsets_at(*keys, &blk)
|
@@ -212,13 +212,13 @@ class MockRedis
|
|
212
212
|
end
|
213
213
|
|
214
214
|
def zsety?(key)
|
215
|
-
data[key].nil? || data[key].
|
215
|
+
data[key].nil? || data[key].is_a?(Zset)
|
216
216
|
end
|
217
217
|
|
218
218
|
def assert_zsety(key)
|
219
219
|
unless zsety?(key)
|
220
220
|
raise Redis::CommandError,
|
221
|
-
|
221
|
+
'WRONGTYPE Operation against a key holding the wrong kind of value'
|
222
222
|
end
|
223
223
|
end
|
224
224
|
|
@@ -227,7 +227,7 @@ class MockRedis
|
|
227
227
|
!!Float(x) rescue false
|
228
228
|
end
|
229
229
|
|
230
|
-
def assert_scorey(value, message =
|
230
|
+
def assert_scorey(value, message = 'ERR value is not a valid float')
|
231
231
|
return if value =~ /\(?(\-|\+)inf/
|
232
232
|
|
233
233
|
value = $1 if value.to_s.match(/\((.*)/)
|
data/spec/cloning_spec.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe 'MockRedis#clone' do
|
4
4
|
before do
|
5
5
|
@mock = MockRedis.new
|
6
6
|
end
|
7
7
|
|
8
|
-
context
|
8
|
+
context 'the stored data' do
|
9
9
|
before do
|
10
10
|
@mock.set('foo', 'bar')
|
11
11
|
@mock.hset('foohash', 'bar', 'baz')
|
@@ -16,60 +16,60 @@ describe "MockRedis#clone" do
|
|
16
16
|
@clone = @mock.clone
|
17
17
|
end
|
18
18
|
|
19
|
-
it
|
19
|
+
it 'copies the stored data to the clone' do
|
20
20
|
@clone.get('foo').should == 'bar'
|
21
21
|
end
|
22
22
|
|
23
|
-
it
|
23
|
+
it 'performs a deep copy (string values)' do
|
24
24
|
@mock.del('foo')
|
25
25
|
@clone.get('foo').should == 'bar'
|
26
26
|
end
|
27
27
|
|
28
|
-
it
|
28
|
+
it 'performs a deep copy (list values)' do
|
29
29
|
@mock.lpop('foolist')
|
30
30
|
@clone.lrange('foolist', 0, 1).should == ['bar']
|
31
31
|
end
|
32
32
|
|
33
|
-
it
|
33
|
+
it 'performs a deep copy (hash values)' do
|
34
34
|
@mock.hset('foohash', 'bar', 'quux')
|
35
|
-
@clone.hgetall('foohash').should == {'bar' => 'baz'}
|
35
|
+
@clone.hgetall('foohash').should == { 'bar' => 'baz' }
|
36
36
|
end
|
37
37
|
|
38
|
-
it
|
38
|
+
it 'performs a deep copy (set values)' do
|
39
39
|
@mock.srem('fooset', 'bar')
|
40
40
|
@clone.smembers('fooset').should == ['bar']
|
41
41
|
end
|
42
42
|
|
43
|
-
it
|
43
|
+
it 'performs a deep copy (zset values)' do
|
44
44
|
@mock.zadd('foozset', 2, 'bar')
|
45
45
|
@clone.zscore('foozset', 'bar').should == 1.0
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
context
|
49
|
+
context 'expiration times' do
|
50
50
|
before do
|
51
51
|
@mock.set('foo', 1)
|
52
|
-
@mock.expire('foo',
|
52
|
+
@mock.expire('foo', 60_026)
|
53
53
|
|
54
54
|
@clone = @mock.clone
|
55
55
|
end
|
56
56
|
|
57
|
-
it
|
57
|
+
it 'copies the expiration times' do
|
58
58
|
@clone.ttl('foo').should > 0
|
59
59
|
end
|
60
60
|
|
61
|
-
it
|
61
|
+
it 'deep-copies the expiration times' do
|
62
62
|
@mock.persist('foo')
|
63
63
|
@clone.ttl('foo').should > 0
|
64
64
|
end
|
65
65
|
|
66
|
-
it
|
66
|
+
it 'deep-copies the expiration times' do
|
67
67
|
@clone.persist('foo')
|
68
68
|
@mock.ttl('foo').should > 0
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
|
-
context
|
72
|
+
context 'transactional info' do
|
73
73
|
before do
|
74
74
|
@mock.multi
|
75
75
|
@mock.incr('foo')
|
@@ -79,18 +79,17 @@ describe "MockRedis#clone" do
|
|
79
79
|
@clone = @mock.clone
|
80
80
|
end
|
81
81
|
|
82
|
-
it
|
82
|
+
it 'makes sure the clone is in a transaction' do
|
83
83
|
lambda do
|
84
84
|
@clone.exec
|
85
85
|
end.should_not raise_error
|
86
86
|
end
|
87
87
|
|
88
|
-
it
|
88
|
+
it 'deep-copies the queued commands' do
|
89
89
|
@clone.incrby('foo', 8)
|
90
90
|
@clone.exec.should == [1, 3, 7, 15]
|
91
91
|
|
92
92
|
@mock.exec.should == [1, 3, 7]
|
93
93
|
end
|
94
94
|
end
|
95
|
-
|
96
95
|
end
|
@@ -3,22 +3,22 @@ require 'spec_helper'
|
|
3
3
|
describe '#append(key, value)' do
|
4
4
|
before { @key = 'mock-redis-test:append' }
|
5
5
|
|
6
|
-
it
|
6
|
+
it 'returns the new length of the string' do
|
7
7
|
@redises.set(@key, 'porkchop')
|
8
8
|
@redises.append(@key, 'sandwiches').should == 18
|
9
9
|
end
|
10
10
|
|
11
|
-
it
|
11
|
+
it 'appends value to the previously-stored value' do
|
12
12
|
@redises.set(@key, 'porkchop')
|
13
13
|
@redises.append(@key, 'sandwiches')
|
14
14
|
|
15
15
|
@redises.get(@key).should == 'porkchopsandwiches'
|
16
16
|
end
|
17
17
|
|
18
|
-
it
|
18
|
+
it 'treats a missing key as an empty string' do
|
19
19
|
@redises.append(@key, 'foo')
|
20
20
|
@redises.get(@key).should == 'foo'
|
21
21
|
end
|
22
22
|
|
23
|
-
it_should_behave_like
|
23
|
+
it_should_behave_like 'a string-only command'
|
24
24
|
end
|
data/spec/commands/auth_spec.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe '#bitcount(key [, start, end ])' do
|
4
4
|
before do
|
5
5
|
@key = 'mock-redis-test:bitcount'
|
6
|
-
@redises.set(@key,
|
6
|
+
@redises.set(@key, 'foobar')
|
7
7
|
end
|
8
8
|
|
9
9
|
it 'gets the number of set bits from the key' do
|
@@ -21,5 +21,5 @@ describe "#bitcount(key [, start, end ])" do
|
|
21
21
|
@redises.bitcount('mock-redis-test:not-found').should == 0
|
22
22
|
end
|
23
23
|
|
24
|
-
it_should_behave_like
|
24
|
+
it_should_behave_like 'a string-only command'
|
25
25
|
end
|