mock_redis 0.12.1 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/lib/mock_redis.rb +4 -0
- data/lib/mock_redis/database.rb +9 -4
- data/lib/mock_redis/list_methods.rb +2 -1
- data/lib/mock_redis/string_methods.rb +1 -1
- data/lib/mock_redis/version.rb +1 -1
- data/lib/mock_redis/zset_methods.rb +9 -0
- data/spec/client_spec.rb +7 -0
- data/spec/commands/blpop_spec.rb +11 -11
- data/spec/commands/brpop_spec.rb +11 -11
- data/spec/commands/brpoplpush_spec.rb +5 -5
- data/spec/commands/setbit_spec.rb +5 -3
- data/spec/commands/zremrangebyscore_spec.rb +4 -0
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a63181a124183a90e68a84d2aaa16957e47398e
|
4
|
+
data.tar.gz: a633c58b9b8eabe402eeb593bfb72fe83e36f069
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41f515662a87bb3a51d2c1f8f5f9f92a0d3d93f9a909a30eb89b03a6a7a454b64d136cb2c3286217e45e9b64252bcd3bc177bae52655f1ad0f8aa773cdaa2b7f
|
7
|
+
data.tar.gz: f262b7fc4dcf2cfe0a6a44017521a8962ba4769899d65271214a6d909a5aca17f3cbe628b7811d22678e69b014f632d2bc2705032158aebe91f6964b7c768ec4
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
# MockRedis Changelog
|
2
2
|
|
3
|
+
### 0.13.0
|
4
|
+
|
5
|
+
* Fix bug where SETBIT command would not correctly unset a bit
|
6
|
+
* Add support for the `connect` method
|
7
|
+
* Check that `min`/`max` parameters are floats in `zrangebyscore`,
|
8
|
+
`zremrangebyscore`, and `zrevrangebyscore`
|
9
|
+
* Update blocking list commands to take `timeout` in an options hash
|
10
|
+
for compatibility with `redis-rb` >= 3.0.0
|
11
|
+
|
3
12
|
### 0.12.1
|
4
13
|
|
5
14
|
* RENAME command now keeps key expiration
|
data/lib/mock_redis.rb
CHANGED
data/lib/mock_redis/database.rb
CHANGED
@@ -210,8 +210,8 @@ class MockRedis
|
|
210
210
|
private
|
211
211
|
|
212
212
|
def assert_valid_timeout(timeout)
|
213
|
-
if !
|
214
|
-
raise Redis::CommandError, "ERR timeout is not
|
213
|
+
if !looks_like_integer?(timeout.to_s)
|
214
|
+
raise Redis::CommandError, "ERR timeout is not an integer or out of range"
|
215
215
|
elsif timeout < 0
|
216
216
|
raise Redis::CommandError, "ERR timeout is negative"
|
217
217
|
end
|
@@ -227,8 +227,13 @@ class MockRedis
|
|
227
227
|
end
|
228
228
|
|
229
229
|
def extract_timeout(arglist)
|
230
|
-
|
231
|
-
|
230
|
+
options = arglist.last
|
231
|
+
if options.is_a?(Hash) && options[:timeout]
|
232
|
+
timeout = assert_valid_timeout(options[:timeout])
|
233
|
+
[arglist[0..-2], timeout]
|
234
|
+
else
|
235
|
+
[arglist, 0]
|
236
|
+
end
|
232
237
|
end
|
233
238
|
|
234
239
|
def expiration(key)
|
@@ -199,7 +199,7 @@ class MockRedis
|
|
199
199
|
char_as_number = char.each_byte.reduce(0) do |a, byte|
|
200
200
|
(a << 8) + byte
|
201
201
|
end
|
202
|
-
char_as_number
|
202
|
+
char_as_number ^=
|
203
203
|
(2**((char.bytesize * 8)-1) >>
|
204
204
|
(offset_within_char * 8 + offset_within_byte))
|
205
205
|
str[char_index] = char_as_number.chr
|
data/lib/mock_redis/version.rb
CHANGED
@@ -67,6 +67,9 @@ class MockRedis
|
|
67
67
|
end
|
68
68
|
|
69
69
|
def zrangebyscore(key, min, max, options={})
|
70
|
+
assert_scorey(min, 'ERR min or max is not a float') unless min == '-inf'
|
71
|
+
assert_scorey(max, 'ERR min or max is not a float') unless max == '+inf'
|
72
|
+
|
70
73
|
with_zset_at(key) do |zset|
|
71
74
|
all_results = zset.in_range(min, max)
|
72
75
|
to_response(apply_limit(all_results, options[:limit]), options)
|
@@ -104,12 +107,18 @@ class MockRedis
|
|
104
107
|
end
|
105
108
|
|
106
109
|
def zremrangebyscore(key, min, max)
|
110
|
+
assert_scorey(min, 'ERR min or max is not a float') unless min == '-inf'
|
111
|
+
assert_scorey(max, 'ERR min or max is not a float') unless max == '+inf'
|
112
|
+
|
107
113
|
zrangebyscore(key, min, max).
|
108
114
|
each {|member| zrem(key, member)}.
|
109
115
|
size
|
110
116
|
end
|
111
117
|
|
112
118
|
def zrevrangebyscore(key, max, min, options={})
|
119
|
+
assert_scorey(min, 'ERR min or max is not a float') unless min == '-inf'
|
120
|
+
assert_scorey(max, 'ERR min or max is not a float') unless max == '+inf'
|
121
|
+
|
113
122
|
with_zset_at(key) do |zset|
|
114
123
|
to_response(
|
115
124
|
apply_limit(
|
data/spec/client_spec.rb
CHANGED
data/spec/commands/blpop_spec.rb
CHANGED
@@ -12,30 +12,30 @@ describe '#blpop(key [, key, ...,], timeout)' do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it "returns [first-nonempty-list, popped-value]" do
|
15
|
-
@redises.blpop(@list1, @list2
|
15
|
+
@redises.blpop(@list1, @list2).should == [@list1, 'one']
|
16
16
|
end
|
17
17
|
|
18
18
|
it "pops that value off the list" do
|
19
|
-
@redises.blpop(@list1, @list2
|
20
|
-
@redises.blpop(@list1, @list2
|
19
|
+
@redises.blpop(@list1, @list2)
|
20
|
+
@redises.blpop(@list1, @list2)
|
21
21
|
|
22
|
-
@redises.blpop(@list1, @list2
|
22
|
+
@redises.blpop(@list1, @list2).should == [@list2, 'ten']
|
23
23
|
end
|
24
24
|
|
25
25
|
it "ignores empty keys" do
|
26
|
-
@redises.blpop('mock-redis-test:not-here', @list1
|
26
|
+
@redises.blpop('mock-redis-test:not-here', @list1).should ==
|
27
27
|
[@list1, 'one']
|
28
28
|
end
|
29
29
|
|
30
|
-
it "
|
30
|
+
it "raises an error on subsecond timeouts" do
|
31
31
|
lambda do
|
32
|
-
@redises.blpop(@list1, @list2, 0.5)
|
33
|
-
end.
|
32
|
+
@redises.blpop(@list1, @list2, :timeout => 0.5)
|
33
|
+
end.should raise_error(Redis::CommandError)
|
34
34
|
end
|
35
35
|
|
36
36
|
it "raises an error on negative timeout" do
|
37
37
|
lambda do
|
38
|
-
@redises.blpop(@list1, @list2, -1)
|
38
|
+
@redises.blpop(@list1, @list2, :timeout => -1)
|
39
39
|
end.should raise_error(Redis::CommandError)
|
40
40
|
end
|
41
41
|
|
@@ -43,12 +43,12 @@ describe '#blpop(key [, key, ...,], timeout)' do
|
|
43
43
|
|
44
44
|
context "[mock only]" do
|
45
45
|
it "ignores positive timeouts and returns nil" do
|
46
|
-
@redises.mock.blpop('mock-redis-test:not-here', 1).should be_nil
|
46
|
+
@redises.mock.blpop('mock-redis-test:not-here', :timeout => 1).should be_nil
|
47
47
|
end
|
48
48
|
|
49
49
|
it "raises WouldBlock on zero timeout (no blocking in the mock)" do
|
50
50
|
lambda do
|
51
|
-
@redises.mock.blpop('mock-redis-test:not-here', 0)
|
51
|
+
@redises.mock.blpop('mock-redis-test:not-here', :timeout => 0)
|
52
52
|
end.should raise_error(MockRedis::WouldBlock)
|
53
53
|
end
|
54
54
|
end
|
data/spec/commands/brpop_spec.rb
CHANGED
@@ -12,29 +12,29 @@ describe '#brpop(key [, key, ...,], timeout)' do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it "returns [first-nonempty-list, popped-value]" do
|
15
|
-
@redises.brpop(@list1, @list2
|
15
|
+
@redises.brpop(@list1, @list2).should == [@list1, 'two']
|
16
16
|
end
|
17
17
|
|
18
18
|
it "pops that value off the list" do
|
19
|
-
@redises.brpop(@list1, @list2
|
20
|
-
@redises.brpop(@list1, @list2
|
21
|
-
@redises.brpop(@list1, @list2
|
19
|
+
@redises.brpop(@list1, @list2)
|
20
|
+
@redises.brpop(@list1, @list2)
|
21
|
+
@redises.brpop(@list1, @list2).should == [@list2, 'ten']
|
22
22
|
end
|
23
23
|
|
24
24
|
it "ignores empty keys" do
|
25
|
-
@redises.brpop('mock-redis-test:not-here', @list1
|
25
|
+
@redises.brpop('mock-redis-test:not-here', @list1).should ==
|
26
26
|
[@list1, 'two']
|
27
27
|
end
|
28
28
|
|
29
|
-
it "
|
29
|
+
it "raises an error on subsecond timeouts" do
|
30
30
|
lambda do
|
31
|
-
@redises.brpop(@list1, @list2, 0.5)
|
32
|
-
end.
|
31
|
+
@redises.brpop(@list1, @list2, :timeout => 0.5)
|
32
|
+
end.should raise_error(Redis::CommandError)
|
33
33
|
end
|
34
34
|
|
35
35
|
it "raises an error on negative timeout" do
|
36
36
|
lambda do
|
37
|
-
@redises.brpop(@list1, @list2, -1)
|
37
|
+
@redises.brpop(@list1, @list2, :timeout => -1)
|
38
38
|
end.should raise_error(Redis::CommandError)
|
39
39
|
end
|
40
40
|
|
@@ -42,12 +42,12 @@ describe '#brpop(key [, key, ...,], timeout)' do
|
|
42
42
|
|
43
43
|
context "[mock only]" do
|
44
44
|
it "ignores positive timeouts and returns nil" do
|
45
|
-
@redises.mock.brpop('mock-redis-test:not-here', 1).should be_nil
|
45
|
+
@redises.mock.brpop('mock-redis-test:not-here', :timeout => 1).should be_nil
|
46
46
|
end
|
47
47
|
|
48
48
|
it "raises WouldBlock on zero timeout (no blocking in the mock)" do
|
49
49
|
lambda do
|
50
|
-
@redises.mock.brpop('mock-redis-test:not-here', 0)
|
50
|
+
@redises.mock.brpop('mock-redis-test:not-here', :timeout => 0)
|
51
51
|
end.should raise_error(MockRedis::WouldBlock)
|
52
52
|
end
|
53
53
|
end
|
@@ -15,18 +15,18 @@ describe '#brpoplpush(source, destination, timeout)' do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
it "takes the last element of source and prepends it to destination" do
|
18
|
-
@redises.brpoplpush(@list1, @list2
|
18
|
+
@redises.brpoplpush(@list1, @list2)
|
19
19
|
@redises.lrange(@list1, 0, -1).should == %w[A]
|
20
20
|
@redises.lrange(@list2, 0, -1).should == %w[B alpha beta]
|
21
21
|
end
|
22
22
|
|
23
23
|
it "returns the moved element" do
|
24
|
-
@redises.brpoplpush(@list1, @list2
|
24
|
+
@redises.brpoplpush(@list1, @list2).should == "B"
|
25
25
|
end
|
26
26
|
|
27
27
|
it "raises an error on negative timeout" do
|
28
28
|
lambda do
|
29
|
-
@redises.brpoplpush(@list1, @list2, -1)
|
29
|
+
@redises.brpoplpush(@list1, @list2, :timeout => -1)
|
30
30
|
end.should raise_error(Redis::CommandError)
|
31
31
|
end
|
32
32
|
|
@@ -34,13 +34,13 @@ describe '#brpoplpush(source, destination, timeout)' do
|
|
34
34
|
|
35
35
|
context "[mock only]" do
|
36
36
|
it "ignores positive timeouts and returns nil" do
|
37
|
-
@redises.mock.brpoplpush('mock-redis-test:not-here', @list1, 1).
|
37
|
+
@redises.mock.brpoplpush('mock-redis-test:not-here', @list1, :timeout => 1).
|
38
38
|
should be_nil
|
39
39
|
end
|
40
40
|
|
41
41
|
it "raises WouldBlock on zero timeout (no blocking in the mock)" do
|
42
42
|
lambda do
|
43
|
-
@redises.mock.brpoplpush('mock-redis-test:not-here', @list1, 0)
|
43
|
+
@redises.mock.brpoplpush('mock-redis-test:not-here', @list1, :timeout => 0)
|
44
44
|
end.should raise_error(MockRedis::WouldBlock)
|
45
45
|
end
|
46
46
|
end
|
@@ -13,12 +13,15 @@ describe "#setbit(key, offset)" do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
it "sets the bit within the string" do
|
16
|
-
$debug = true
|
17
16
|
@redises.setbit(@key, 7, 1)
|
18
|
-
$debug = false
|
19
17
|
@redises.get(@key).should == 'i' # ASCII 0x69
|
20
18
|
end
|
21
19
|
|
20
|
+
it "unsets the bit within the string" do
|
21
|
+
@redises.setbit(@key, 1, 0)
|
22
|
+
@redises.get(@key).should == '(' # ASCII 0x28
|
23
|
+
end
|
24
|
+
|
22
25
|
it "does the right thing with multibyte characters" do
|
23
26
|
@redises.set(@key, "€99.94") # the euro sign is 3 bytes wide in UTF-8
|
24
27
|
@redises.setbit(@key, 63, 1).should == 0
|
@@ -43,4 +46,3 @@ describe "#setbit(key, offset)" do
|
|
43
46
|
|
44
47
|
it_should_behave_like "a string-only command"
|
45
48
|
end
|
46
|
-
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mock_redis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Causes Engineering
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-05-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -387,4 +387,3 @@ test_files:
|
|
387
387
|
- spec/support/shared_examples/only_operates_on_zsets.rb
|
388
388
|
- spec/support/shared_examples/sorts_enumerables.rb
|
389
389
|
- spec/transactions_spec.rb
|
390
|
-
has_rdoc:
|