mock_redis 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +14 -0
- data/lib/mock_redis/version.rb +1 -1
- data/lib/mock_redis/zset.rb +30 -0
- data/lib/mock_redis/zset_methods.rb +7 -8
- data/spec/commands/zrangebyscore_spec.rb +26 -0
- data/spec/commands/zremrangebyscore_spec.rb +7 -0
- data/spec/commands/zrevrangebyscore_spec.rb +5 -0
- metadata +5 -4
data/CHANGELOG.md
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
### 0.1.1
|
2
|
+
* Fix handling of -inf, +inf, and exclusive endpoints (e.g. "(3") in
|
3
|
+
zrangebyscore, zrevrangebyscore, and zremrangebyscore. ("Fix" here
|
4
|
+
means "write", as it's something that was completely forgotten the
|
5
|
+
first time around.)
|
6
|
+
|
7
|
+
### 0.1.0
|
8
|
+
* Support `move(key, db)` to move keys between databases.
|
9
|
+
|
10
|
+
### 0.0.2
|
11
|
+
* Fix gem homepage.
|
12
|
+
|
13
|
+
### 0.0.1
|
14
|
+
Initial release.
|
data/lib/mock_redis/version.rb
CHANGED
data/lib/mock_redis/zset.rb
CHANGED
@@ -40,6 +40,36 @@ class MockRedis
|
|
40
40
|
members.each {|m| yield score(m), m}
|
41
41
|
end
|
42
42
|
|
43
|
+
def in_range(min, max)
|
44
|
+
in_from_the_left = case min
|
45
|
+
when "-inf":
|
46
|
+
lambda { true }
|
47
|
+
when "+inf":
|
48
|
+
lambda { false }
|
49
|
+
when /\((.*)$/:
|
50
|
+
val = $1.to_f
|
51
|
+
lambda {|x| x.to_f > val }
|
52
|
+
else
|
53
|
+
lambda {|x| x.to_f >= min.to_f }
|
54
|
+
end
|
55
|
+
|
56
|
+
in_from_the_right = case max
|
57
|
+
when "-inf":
|
58
|
+
lambda { false }
|
59
|
+
when "+inf":
|
60
|
+
lambda { true }
|
61
|
+
when /\((.*)$/:
|
62
|
+
val = $1.to_f
|
63
|
+
lambda {|x| x.to_f < val }
|
64
|
+
else
|
65
|
+
lambda {|x| x.to_f <= max.to_f }
|
66
|
+
end
|
67
|
+
|
68
|
+
sorted.find_all do |(score, member)|
|
69
|
+
in_from_the_left[score] && in_from_the_right[score]
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
43
73
|
def intersection(other)
|
44
74
|
if !block_given?
|
45
75
|
intersection(other, &:+)
|
@@ -55,10 +55,8 @@ class MockRedis
|
|
55
55
|
|
56
56
|
def zrangebyscore(key, min, max, options={})
|
57
57
|
with_zset_at(key) do |zset|
|
58
|
-
|
59
|
-
|
60
|
-
end
|
61
|
-
to_response(apply_limit(in_range, options[:limit]), options)
|
58
|
+
all_results = zset.in_range(min, max)
|
59
|
+
to_response(apply_limit(all_results, options[:limit]), options)
|
62
60
|
end
|
63
61
|
end
|
64
62
|
|
@@ -90,10 +88,11 @@ class MockRedis
|
|
90
88
|
|
91
89
|
def zrevrangebyscore(key, max, min, options={})
|
92
90
|
with_zset_at(key) do |zset|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
91
|
+
to_response(
|
92
|
+
apply_limit(
|
93
|
+
zset.in_range(min, max).reverse,
|
94
|
+
options[:limit]),
|
95
|
+
options)
|
97
96
|
end
|
98
97
|
end
|
99
98
|
|
@@ -38,5 +38,31 @@ describe "#zrangebyscore(key, start, stop [:with_scores => true] [:limit => [off
|
|
38
38
|
end.should raise_error(RuntimeError)
|
39
39
|
end
|
40
40
|
|
41
|
+
it "treats scores like floats, not strings" do
|
42
|
+
@redises.zadd(@key, "10", "Tyler")
|
43
|
+
@redises.zrangebyscore(@key, 1, 2).should == ['Washington', 'Adams']
|
44
|
+
end
|
45
|
+
|
46
|
+
it "treats -inf as negative infinity" do
|
47
|
+
@redises.zrangebyscore(@key, "-inf", 3).should ==
|
48
|
+
["Washington", "Adams", "Jefferson"]
|
49
|
+
end
|
50
|
+
|
51
|
+
it "treats +inf as positive infinity" do
|
52
|
+
@redises.zrangebyscore(@key, 3, "+inf").should == ["Jefferson", "Madison"]
|
53
|
+
end
|
54
|
+
|
55
|
+
it "treats +inf as positive infinity" do
|
56
|
+
@redises.zrangebyscore(@key, 3, "+inf").should == ["Jefferson", "Madison"]
|
57
|
+
end
|
58
|
+
|
59
|
+
it "honors exclusive ranges on the left" do
|
60
|
+
@redises.zrangebyscore(@key, "(3", 4).should == ["Madison"]
|
61
|
+
end
|
62
|
+
|
63
|
+
it "honors exclusive ranges on the right" do
|
64
|
+
@redises.zrangebyscore(@key, "3", "(4").should == ["Jefferson"]
|
65
|
+
end
|
66
|
+
|
41
67
|
it_should_behave_like "a zset-only command"
|
42
68
|
end
|
@@ -17,5 +17,12 @@ describe "#zremrangebyscore(key, min, max)" do
|
|
17
17
|
@redises.zremrangebyscore(@key, 2, 3)
|
18
18
|
@redises.zrange(@key, 0, -1).should == %w[Washington Madison]
|
19
19
|
end
|
20
|
+
|
21
|
+
# As seen in http://redis.io/commands/zremrangebyscore
|
22
|
+
it "removes the elements for complex statements" do
|
23
|
+
@redises.zremrangebyscore(@key, '-inf', '(4')
|
24
|
+
@redises.zrange(@key, 0, -1).should == %w[Madison]
|
25
|
+
end
|
26
|
+
|
20
27
|
it_should_behave_like "a zset-only command"
|
21
28
|
end
|
@@ -23,6 +23,11 @@ describe "#zrevrangebyscore(key, start, stop [:with_scores => true] [:limit => [
|
|
23
23
|
should == %w[Madison 4 Jefferson 3]
|
24
24
|
end
|
25
25
|
|
26
|
+
it "treats +inf as positive infinity" do
|
27
|
+
@redises.zrevrangebyscore(@key, "+inf", 3).
|
28
|
+
should == %w[Madison Jefferson]
|
29
|
+
end
|
30
|
+
|
26
31
|
it "honors the :limit => [offset count] argument" do
|
27
32
|
@redises.zrevrangebyscore(@key, 100, -100, :limit => [1, 2]).
|
28
33
|
should == ["Jefferson", "Adams"]
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mock_redis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Samuel Merritt
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-08-24 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -76,6 +76,7 @@ extra_rdoc_files: []
|
|
76
76
|
files:
|
77
77
|
- .gitignore
|
78
78
|
- .rspec
|
79
|
+
- CHANGELOG.md
|
79
80
|
- Gemfile
|
80
81
|
- LICENSE
|
81
82
|
- README.md
|