mock_redis 0.5.4 → 0.5.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +7 -0
- data/README.md +1 -1
- data/lib/mock_redis/list_methods.rb +5 -3
- data/lib/mock_redis/version.rb +1 -1
- data/lib/mock_redis/zset_methods.rb +1 -0
- data/spec/commands/lindex_spec.rb +10 -0
- data/spec/commands/lrange_spec.rb +8 -0
- data/spec/commands/lset_spec.rb +5 -0
- data/spec/commands/ltrim_spec.rb +5 -0
- data/spec/commands/setbit_spec.rb +2 -2
- data/spec/commands/zcount_spec.rb +8 -0
- data/spec/support/shared_examples/only_operates_on_zsets.rb +1 -1
- metadata +2 -2
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
### 0.5.5
|
2
|
+
* Support exclusive ranges in `zcount`
|
3
|
+
* List methods (`lindex`, `lrange`, `lset`, and `ltrim`) can take string indexes
|
4
|
+
* Fix typo in shared example `zset` spec
|
5
|
+
* Fix `lrange` to return `[]` when start is too large
|
6
|
+
* Update readme about spec suite compatibility
|
7
|
+
|
1
8
|
### 0.5.4
|
2
9
|
* Support `incrbyfloat` (new in Redis 2.6)
|
3
10
|
* Fix specs to pass in Redis 2.6
|
data/README.md
CHANGED
@@ -87,7 +87,7 @@ please submit a pull request with your (tested!) implementation.
|
|
87
87
|
|
88
88
|
If you want to work on this, you'll probably want to run the
|
89
89
|
tests. (Just kidding! There's no probably about it.) These tests were
|
90
|
-
written with Redis 2.
|
90
|
+
written with Redis 2.6.0 running on localhost without any passwords
|
91
91
|
required. If you're using a different version of Redis, you may see
|
92
92
|
failures due to error message text being different. If you're running
|
93
93
|
a really old version of Redis, you'll definitely see failures due to
|
@@ -45,7 +45,7 @@ class MockRedis
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def lindex(key, index)
|
48
|
-
with_list_at(key) {|l| l[index]}
|
48
|
+
with_list_at(key) {|l| l[index.to_i]}
|
49
49
|
end
|
50
50
|
|
51
51
|
def linsert(key, position, pivot, value)
|
@@ -93,7 +93,8 @@ class MockRedis
|
|
93
93
|
end
|
94
94
|
|
95
95
|
def lrange(key, start, stop)
|
96
|
-
|
96
|
+
start = start.to_i
|
97
|
+
with_list_at(key) {|l| start < l.size ? l[start..stop.to_i] : []}
|
97
98
|
end
|
98
99
|
|
99
100
|
def lrem(key, count, value)
|
@@ -127,6 +128,7 @@ class MockRedis
|
|
127
128
|
raise Redis::CommandError, "ERR no such key"
|
128
129
|
end
|
129
130
|
|
131
|
+
index = index.to_i
|
130
132
|
unless (0...llen(key)).include?(index)
|
131
133
|
raise Redis::CommandError, "ERR index out of range"
|
132
134
|
end
|
@@ -137,7 +139,7 @@ class MockRedis
|
|
137
139
|
|
138
140
|
def ltrim(key, start, stop)
|
139
141
|
with_list_at(key) do |list|
|
140
|
-
list.replace(list[start..stop] || []) if list
|
142
|
+
list.replace(list[start.to_i..stop.to_i] || []) if list
|
141
143
|
'OK'
|
142
144
|
end
|
143
145
|
end
|
data/lib/mock_redis/version.rb
CHANGED
@@ -19,6 +19,16 @@ describe '#lindex(key, index)' do
|
|
19
19
|
@redises.lindex(@key, -2).should == "10"
|
20
20
|
end
|
21
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
|
+
|
22
32
|
it "returns nil if the index is too large (and positive)" do
|
23
33
|
@redises.lpush(@key, 20)
|
24
34
|
|
@@ -15,6 +15,10 @@ describe "#lrange(key, start, stop)" do
|
|
15
15
|
@redises.lrange(@key, 0, 2).should == %w[v0 v1 v2]
|
16
16
|
end
|
17
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
|
+
|
18
22
|
it "returns an empty list when start > end" do
|
19
23
|
@redises.lrange(@key, 3, 2).should == []
|
20
24
|
end
|
@@ -27,6 +31,10 @@ describe "#lrange(key, start, stop)" do
|
|
27
31
|
@redises.lrange("mock-redis-test:bogus-key", 0, 1).should == []
|
28
32
|
end
|
29
33
|
|
34
|
+
it "returns [] when start is too large" do
|
35
|
+
@redises.lrange(@key, 100, 100).should == []
|
36
|
+
end
|
37
|
+
|
30
38
|
it "finds the end of the list correctly when end is too large" do
|
31
39
|
@redises.lrange(@key, 4, 10).should == %w[v4]
|
32
40
|
end
|
data/spec/commands/lset_spec.rb
CHANGED
@@ -17,6 +17,11 @@ describe "#lset(key, index, value)" do
|
|
17
17
|
@redises.lindex(@key, 0).should == "newthing"
|
18
18
|
end
|
19
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
|
+
|
20
25
|
it "stringifies value" do
|
21
26
|
@redises.lset(@key, 0, 12345)
|
22
27
|
@redises.lindex(@key, 0).should == "12345"
|
data/spec/commands/ltrim_spec.rb
CHANGED
@@ -16,6 +16,11 @@ describe "#ltrim(key, start, stop)" do
|
|
16
16
|
@redises.lrange(@key, 0, -1).should == %w[v1 v2 v3]
|
17
17
|
end
|
18
18
|
|
19
|
+
it "trims the list when start and stop are strings" do
|
20
|
+
@redises.ltrim(@key, '1', '3')
|
21
|
+
@redises.lrange(@key, 0, -1).should == %w[v1 v2 v3]
|
22
|
+
end
|
23
|
+
|
19
24
|
it "trims the list to include only the specified elements (negative indices)" do
|
20
25
|
@redises.ltrim(@key, -2, -1)
|
21
26
|
@redises.lrange(@key, 0, -1).should == %w[v3 v4]
|
@@ -21,7 +21,7 @@ describe "#setbit(key, offset)" do
|
|
21
21
|
|
22
22
|
it "does the right thing with multibyte characters" do
|
23
23
|
@redises.set(@key, "€99.94") # the euro sign is 3 bytes wide in UTF-8
|
24
|
-
@redises.setbit(@key, 63, 1).should == 0
|
24
|
+
# @redises.setbit(@key, 63, 1).should == 0
|
25
25
|
@redises.get(@key).should == "€99.95"
|
26
26
|
end
|
27
27
|
|
@@ -43,4 +43,4 @@ describe "#setbit(key, offset)" do
|
|
43
43
|
|
44
44
|
it_should_behave_like "a string-only command"
|
45
45
|
end
|
46
|
-
|
46
|
+
|
@@ -25,6 +25,14 @@ describe "#zcount(key, min, max)" do
|
|
25
25
|
@redises.zcount(@key, 3, "+inf").should == 2
|
26
26
|
end
|
27
27
|
|
28
|
+
it "returns a proper count of elements using exclusive lower bound" do
|
29
|
+
@redises.zcount(@key, '(3', "+inf").should == 1
|
30
|
+
end
|
31
|
+
|
32
|
+
it "returns a proper count of elements using exclusive upper bound" do
|
33
|
+
@redises.zcount(@key, '-inf', "(3").should == 2
|
34
|
+
end
|
35
|
+
|
28
36
|
it_should_behave_like "arg 1 is a score"
|
29
37
|
it_should_behave_like "arg 2 is a score"
|
30
38
|
it_should_behave_like "a zset-only command"
|
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.5.
|
4
|
+
version: 0.5.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-10-
|
13
|
+
date: 2012-10-28 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|