fakeredis 0.3.3 → 0.4.0

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/spec/server_spec.rb CHANGED
@@ -12,48 +12,11 @@ module FakeRedis
12
12
  @client.set("key2", "2")
13
13
  @client.set("key2", "two")
14
14
 
15
- @client.dbsize.should be == 2
15
+ @client.dbsize.should == 2
16
16
  end
17
17
 
18
18
  it "should get information and statistics about the server" do
19
- @client.info.key?("redis_version").should be == true
20
- end
21
-
22
- it "should handle non-existent methods" do
23
- lambda { @client.idontexist }.should raise_error(RuntimeError, "ERR unknown command 'idontexist'")
24
- end
25
-
26
- describe "multiple databases" do
27
- it "should default to database 0" do
28
- @client.inspect.should =~ %r#/0 \(#
29
- end
30
-
31
- it "should select another database" do
32
- @client.select(1)
33
- @client.inspect.should =~ %r#/1 \(#
34
- end
35
-
36
- it "should flush a database" do
37
- @client.select(0)
38
- @client.set("key1", "1")
39
- @client.set("key2", "2")
40
- @client.dbsize.should be == 2
41
-
42
- @client.flushdb.should be == "OK"
43
-
44
- @client.dbsize.should be == 0
45
- end
46
-
47
- it "should flush all databases" do
48
- @client.select(0)
49
- @client.set("key3", "3")
50
- @client.set("key4", "4")
51
- @client.dbsize.should be == 2
52
-
53
- @client.flushall.should be == "OK"
54
-
55
- @client.dbsize.should be == 0
56
- end
19
+ @client.info.key?("redis_version").should == true
57
20
  end
58
21
  end
59
22
  end
data/spec/sets_spec.rb CHANGED
@@ -7,23 +7,17 @@ module FakeRedis
7
7
  end
8
8
 
9
9
  it "should add a member to a set" do
10
- @client.sadd("key", "value").should be == true
11
- @client.sadd("key", "value").should be == false
10
+ @client.sadd("key", "value").should == true
11
+ @client.sadd("key", "value").should == false
12
12
 
13
- @client.smembers("key").should be == ["value"]
14
- end
15
-
16
- it "should not add multiple members to a set" do
17
- # redis.rb v2.2.2 just calls #to_s on the second argument
18
- @client.sadd("key", %w(value other something more)).should be_true
19
- @client.smembers("key").should be == [%w(value other something more).to_s]
13
+ @client.smembers("key").should == ["value"]
20
14
  end
21
15
 
22
16
  it "should get the number of members in a set" do
23
17
  @client.sadd("key", "val1")
24
18
  @client.sadd("key", "val2")
25
19
 
26
- @client.scard("key").should be == 2
20
+ @client.scard("key").should == 2
27
21
  end
28
22
 
29
23
  it "should subtract multiple sets" do
@@ -63,7 +57,7 @@ module FakeRedis
63
57
  @client.sadd("key3", "c")
64
58
  @client.sadd("key3", "e")
65
59
 
66
- @client.sinter("key1", "key2", "key3").should be == ["c"]
60
+ @client.sinter("key1", "key2", "key3").should == ["c"]
67
61
  end
68
62
 
69
63
  it "should intersect multiple sets and store the resulting set in a key" do
@@ -76,15 +70,15 @@ module FakeRedis
76
70
  @client.sadd("key3", "c")
77
71
  @client.sadd("key3", "e")
78
72
  @client.sinterstore("key", "key1", "key2", "key3")
79
- @client.smembers("key").should be == ["c"]
73
+ @client.smembers("key").should == ["c"]
80
74
  end
81
75
 
82
76
  it "should determine if a given value is a member of a set" do
83
77
  @client.sadd("key1", "a")
84
78
 
85
- @client.sismember("key1", "a").should be == true
86
- @client.sismember("key1", "b").should be == false
87
- @client.sismember("key2", "a").should be == false
79
+ @client.sismember("key1", "a").should == true
80
+ @client.sismember("key1", "b").should == false
81
+ @client.sismember("key2", "a").should == false
88
82
  end
89
83
 
90
84
  it "should get all the members in a set" do
@@ -100,10 +94,10 @@ module FakeRedis
100
94
  @client.sadd("key1", "a")
101
95
  @client.sadd("key1", "b")
102
96
  @client.sadd("key2", "c")
103
- @client.smove("key1", "key2", "a").should be == true
104
- @client.smove("key1", "key2", "a").should be == false
97
+ @client.smove("key1", "key2", "a").should == true
98
+ @client.smove("key1", "key2", "a").should == false
105
99
 
106
- @client.smembers("key1").should be == ["b"]
100
+ @client.smembers("key1").should == ["b"]
107
101
  @client.smembers("key2").should =~ ["c", "a"]
108
102
  end
109
103
 
@@ -126,10 +120,10 @@ module FakeRedis
126
120
  it "should remove a member from a set" do
127
121
  @client.sadd("key1", "a")
128
122
  @client.sadd("key1", "b")
129
- @client.srem("key1", "a").should be == true
130
- @client.srem("key1", "a").should be == false
123
+ @client.srem("key1", "a").should == true
124
+ @client.srem("key1", "a").should == false
131
125
 
132
- @client.smembers("key1").should be == ["b"]
126
+ @client.smembers("key1").should == ["b"]
133
127
  end
134
128
 
135
129
  it "should remove the set's key once it's empty" do
@@ -138,7 +132,7 @@ module FakeRedis
138
132
  @client.srem("key1", "b")
139
133
  @client.srem("key1", "a")
140
134
 
141
- @client.exists("key1").should be == false
135
+ @client.exists("key1").should == false
142
136
  end
143
137
 
144
138
  it "should add multiple sets" do
@@ -8,39 +8,18 @@ module FakeRedis
8
8
 
9
9
  it "should add a member to a sorted set, or update its score if it already exists" do
10
10
  @client.zadd("key", 1, "val").should be(true)
11
- @client.zscore("key", "val").should be == "1"
11
+ @client.zscore("key", "val").should == 1.0
12
12
 
13
13
  @client.zadd("key", 2, "val").should be(false)
14
- @client.zscore("key", "val").should be == "2"
15
-
16
- @client.zadd("key2", "inf", "val").should be == true
17
- @client.zscore("key2", "val").should be == "inf"
18
-
19
- @client.zadd("key3", "+inf", "val").should be == true
20
- @client.zscore("key3", "val").should be == "inf"
21
-
22
- @client.zadd("key4", "-inf", "val").should be == true
23
- @client.zscore("key4", "val").should be == "-inf"
24
- end
25
-
26
- it "should return a nil score for value not in a sorted set or empty key" do
27
- @client.zadd "key", 1, "val"
28
-
29
- @client.zscore("key", "val").should be == "1"
30
- @client.zscore("key", "val2").should be_nil
31
- @client.zscore("key2", "val").should be_nil
32
- end
33
-
34
- it "errors adding multiple things to a set" do
35
- lambda { @client.zadd("key", [[1, "val"], [2, 'val2']]) }.should raise_error(ArgumentError)
14
+ @client.zscore("key", "val").should == 2.0
36
15
  end
37
16
 
38
17
  it "should allow floats as scores when adding or updating" do
39
18
  @client.zadd("key", 4.321, "val").should be(true)
40
- @client.zscore("key", "val").should =~ /^4.32/
19
+ @client.zscore("key", "val").should == 4.321
41
20
 
42
21
  @client.zadd("key", 54.3210, "val").should be(false)
43
- @client.zscore("key", "val").should =~ /^54.32/
22
+ @client.zscore("key", "val").should == 54.321
44
23
  end
45
24
 
46
25
  it "should remove members from sorted sets" do
@@ -52,7 +31,7 @@ module FakeRedis
52
31
  it "should remove sorted set's key when it is empty" do
53
32
  @client.zadd("key", 1, "val")
54
33
  @client.zrem("key", "val")
55
- @client.exists("key").should be == false
34
+ @client.exists("key").should == false
56
35
  end
57
36
 
58
37
  it "should get the number of members in a sorted set" do
@@ -60,7 +39,7 @@ module FakeRedis
60
39
  @client.zadd("key", 2, "val1")
61
40
  @client.zadd("key", 5, "val3")
62
41
 
63
- @client.zcard("key").should be == 3
42
+ @client.zcard("key").should == 3
64
43
  end
65
44
 
66
45
  it "should count the members in a sorted set with scores within the given values" do
@@ -68,47 +47,34 @@ module FakeRedis
68
47
  @client.zadd("key", 2, "val2")
69
48
  @client.zadd("key", 3, "val3")
70
49
 
71
- @client.zcount("key", 2, 3).should be == 2
50
+ @client.zcount("key", 2, 3).should == 2
72
51
  end
73
52
 
74
53
  it "should increment the score of a member in a sorted set" do
75
54
  @client.zadd("key", 1, "val1")
76
- @client.zincrby("key", 2, "val1").should be == "3"
77
- @client.zscore("key", "val1").should be == "3"
55
+ @client.zincrby("key", 2, "val1").should == 3
56
+ @client.zscore("key", "val1").should == 3
78
57
  end
79
58
 
80
59
  it "initializes the sorted set if the key wasnt already set" do
81
- @client.zincrby("key", 1, "val1").should be == "1"
60
+ @client.zincrby("key", 1, "val1").should == 1
82
61
  end
83
62
 
84
63
  it "should convert the key to a string for zscore" do
85
64
  @client.zadd("key", 1, 1)
86
- @client.zscore("key", 1).should be == "1"
87
- end
88
-
89
- it "should handle infinity values when incrementing a sorted set key" do
90
- @client.zincrby("bar", "+inf", "s2").should be == "inf"
91
- @client.zincrby("bar", "-inf", "s1").should be == "-inf"
65
+ @client.zscore("key", 1).should == 1
92
66
  end
67
+ #it "should intersect multiple sorted sets and store the resulting sorted set in a new key"
93
68
 
94
69
  it "should return a range of members in a sorted set, by index" do
95
70
  @client.zadd("key", 1, "one")
96
71
  @client.zadd("key", 2, "two")
97
72
  @client.zadd("key", 3, "three")
98
73
 
99
- @client.zrange("key", 0, -1).should be == ["one", "two", "three"]
100
- @client.zrange("key", 1, 2).should be == ["two", "three"]
101
- @client.zrange("key", 0, -1, :withscores => true).should be == ["one", "1", "two", "2", "three", "3"]
102
- @client.zrange("key", 1, 2, :with_scores => true).should be == ["two", "2", "three", "3"]
103
- end
104
-
105
- it "should sort zrange results logically" do
106
- @client.zadd("key", 5, "val2")
107
- @client.zadd("key", 5, "val3")
108
- @client.zadd("key", 5, "val1")
109
-
110
- @client.zrange("key", 0, -1).should be == %w(val1 val2 val3)
111
- @client.zrange("key", 0, -1, :with_scores => true).should be == ["val1", "5", "val2", "5", "val3", "5"]
74
+ @client.zrange("key", 0, -1).should == ["one", "two", "three"]
75
+ @client.zrange("key", 1, 2).should == ["two", "three"]
76
+ @client.zrange("key", 0, -1, :withscores => true).should == [["one", 1], ["two", 2], ["three", 3]]
77
+ @client.zrange("key", 1, 2, :with_scores => true).should == [["two", 2], ["three", 3]]
112
78
  end
113
79
 
114
80
  it "should return a reversed range of members in a sorted set, by index" do
@@ -116,10 +82,10 @@ module FakeRedis
116
82
  @client.zadd("key", 2, "two")
117
83
  @client.zadd("key", 3, "three")
118
84
 
119
- @client.zrevrange("key", 0, -1).should be == ["three", "two", "one"]
120
- @client.zrevrange("key", 1, 2).should be == ["two", "one"]
121
- @client.zrevrange("key", 0, -1, :withscores => true).should be == ["three", "3", "two", "2", "one", "1"]
122
- @client.zrevrange("key", 0, -1, :with_scores => true).should be == ["three", "3", "two", "2", "one", "1"]
85
+ @client.zrevrange("key", 0, -1).should == ["three", "two", "one"]
86
+ @client.zrevrange("key", 1, 2).should == ["two", "one"]
87
+ @client.zrevrange("key", 0, -1, :withscores => true).should == [["three", 3], ["two", 2], ["one", 1]]
88
+ @client.zrevrange("key", 0, -1, :with_scores => true).should == [["three", 3], ["two", 2], ["one", 1]]
123
89
  end
124
90
 
125
91
  it "should return a range of members in a sorted set, by score" do
@@ -127,13 +93,13 @@ module FakeRedis
127
93
  @client.zadd("key", 2, "two")
128
94
  @client.zadd("key", 3, "three")
129
95
 
130
- @client.zrangebyscore("key", 0, 100).should be == ["one", "two", "three"]
131
- @client.zrangebyscore("key", 1, 2).should be == ["one", "two"]
132
- @client.zrangebyscore("key", 0, 100, :withscores => true).should be == ["one", "1", "two", "2", "three", "3"]
133
- @client.zrangebyscore("key", 1, 2, :with_scores => true).should be == ["one", "1", "two", "2"]
134
- @client.zrangebyscore("key", 0, 100, :limit => [0, 1]).should be == ["one"]
135
- @client.zrangebyscore("key", 0, 100, :limit => [0, -1]).should be == ["one", "two", "three"]
136
- @client.zrangebyscore("key", 0, 100, :limit => [1, -1], :with_scores => true).should be == ["two", "2", "three", "3"]
96
+ @client.zrangebyscore("key", 0, 100).should == ["one", "two", "three"]
97
+ @client.zrangebyscore("key", 1, 2).should == ["one", "two"]
98
+ @client.zrangebyscore("key", 0, 100, :withscores => true).should == [["one", 1], ["two", 2], ["three", 3]]
99
+ @client.zrangebyscore("key", 1, 2, :with_scores => true).should == [["one", 1], ["two", 2]]
100
+ @client.zrangebyscore("key", 0, 100, :limit => [0, 1]).should == ["one"]
101
+ @client.zrangebyscore("key", 0, 100, :limit => [0, -1]).should == ["one", "two", "three"]
102
+ @client.zrangebyscore("key", 0, 100, :limit => [1, -1], :with_scores => true).should == [["two", 2], ["three", 3]]
137
103
  end
138
104
 
139
105
  it "should return a reversed range of members in a sorted set, by score" do
@@ -141,13 +107,13 @@ module FakeRedis
141
107
  @client.zadd("key", 2, "two")
142
108
  @client.zadd("key", 3, "three")
143
109
 
144
- @client.zrevrangebyscore("key", 100, 0).should be == ["three", "two", "one"]
145
- @client.zrevrangebyscore("key", 2, 1).should be == ["two", "one"]
146
- @client.zrevrangebyscore("key", 1, 2).should be == []
147
- @client.zrevrangebyscore("key", 2, 1, :with_scores => true).should be == ["two", "2", "one", "1"]
148
- @client.zrevrangebyscore("key", 100, 0, :limit => [0, 1]).should be == ["three"]
149
- @client.zrevrangebyscore("key", 100, 0, :limit => [0, -1]).should be == ["three", "two", "one"]
150
- @client.zrevrangebyscore("key", 100, 0, :limit => [1, -1], :with_scores => true).should be == ["two", "2", "one", "1"]
110
+ @client.zrevrangebyscore("key", 100, 0).should == ["three", "two", "one"]
111
+ @client.zrevrangebyscore("key", 2, 1).should == ["two", "one"]
112
+ @client.zrevrangebyscore("key", 1, 2).should == []
113
+ @client.zrevrangebyscore("key", 2, 1, :with_scores => true).should == [["two", 2], ["one", 1]]
114
+ @client.zrevrangebyscore("key", 100, 0, :limit => [0, 1]).should == ["three"]
115
+ @client.zrevrangebyscore("key", 100, 0, :limit => [0, -1]).should == ["three", "two", "one"]
116
+ @client.zrevrangebyscore("key", 100, 0, :limit => [1, -1], :with_scores => true).should == [["two", 2], ["one", 1]]
151
117
  end
152
118
 
153
119
  it "should determine the index of a member in a sorted set" do
@@ -155,7 +121,7 @@ module FakeRedis
155
121
  @client.zadd("key", 2, "two")
156
122
  @client.zadd("key", 3, "three")
157
123
 
158
- @client.zrank("key", "three").should be == 2
124
+ @client.zrank("key", "three").should == 2
159
125
  @client.zrank("key", "four").should be_nil
160
126
  end
161
127
 
@@ -164,83 +130,30 @@ module FakeRedis
164
130
  @client.zadd("key", 2, "two")
165
131
  @client.zadd("key", 3, "three")
166
132
 
167
- @client.zrevrank("key", "three").should be == 0
133
+ @client.zrevrank("key", "three").should == 0
168
134
  @client.zrevrank("key", "four").should be_nil
169
135
  end
170
136
 
171
- describe "#zinterstore" do
172
- before do
173
- @client.zadd("key1", 1, "one")
174
- @client.zadd("key1", 2, "two")
175
- @client.zadd("key1", 3, "three")
176
- @client.zadd("key2", 5, "two")
177
- @client.zadd("key2", 7, "three")
178
- @client.sadd("key3", 'one')
179
- @client.sadd("key3", 'two')
180
- end
181
-
182
- it "should intersect two keys with custom scores" do
183
- @client.zinterstore("out", ["key1", "key2"]).should be == 2
184
- @client.zrange("out", 0, -1, :with_scores => true).should be == ['two', (2 + 5).to_s, 'three', (3 + 7).to_s]
185
- end
186
-
187
- it "should intersect two keys with a default score" do
188
- @client.zinterstore("out", ["key1", "key3"]).should be == 2
189
- @client.zrange("out", 0, -1, :with_scores => true).should be == ['one', (1 + 1).to_s, 'two', (2 + 1).to_s]
190
- end
191
-
192
- it "should intersect more than two keys" do
193
- @client.zinterstore("out", ["key1", "key2", "key3"]).should be == 1
194
- @client.zrange("out", 0, -1, :with_scores => true).should be == ['two', (2 + 5 + 1).to_s]
195
- end
196
-
197
- it "should not intersect an unknown key" do
198
- @client.zinterstore("out", ["key1", "no_key"]).should be == 0
199
- @client.zrange("out", 0, -1, :with_scores => true).should be == []
200
- end
201
-
202
- it "should intersect two keys by minimum values" do
203
- @client.zinterstore("out", ["key1", "key2"], :aggregate => :min).should be == 2
204
- @client.zrange("out", 0, -1, :with_scores => true).should be == ["two", "2", "three", "3"]
205
- end
206
-
207
- it "should intersect two keys by maximum values" do
208
- @client.zinterstore("out", ["key1", "key2"], :aggregate => :max).should be == 2
209
- @client.zrange("out", 0, -1, :with_scores => true).should be == ["two", "5", "three", "7"]
210
- end
137
+ it "should create untersections between multiple (sorted) sets and store the resulting sorted set in a new key" do
138
+ @client.zadd("key1", 1, "one")
139
+ @client.zadd("key1", 2, "two")
140
+ @client.zadd("key1", 3, "three")
141
+ @client.zadd("key2", 5, "two")
142
+ @client.zadd("key2", 7, "three")
143
+ @client.sadd("key3", 'one')
144
+ @client.sadd("key3", 'two')
211
145
 
212
- it "should intersect two keys by explicitly summing values" do
213
- @client.zinterstore("out", %w(key1 key2), :aggregate => :sum).should be == 2
214
- @client.zrange("out", 0, -1, :with_scores => true).should be == ["two", (2 + 5).to_s, "three", (3 + 7).to_s]
215
- end
146
+ @client.zinterstore("out", ["key1", "key2"]).should == 2
147
+ @client.zrange("out", 0, 100, :with_scores => true).should == [['two', 7], ['three', 10]]
216
148
 
217
- it "should intersect two keys with weighted values" do
218
- @client.zinterstore("out", %w(key1 key2), :weights => [10, 1]).should be == 2
219
- @client.zrange("out", 0, -1, :with_scores => true).should be == ["two", (2 * 10 + 5).to_s, "three", (3 * 10 + 7).to_s]
220
- end
149
+ @client.zinterstore("out", ["key1", "key3"]).should == 2
150
+ @client.zrange("out", 0, 100, :with_scores => true).should == [['one', 1], ['two', 2]]
221
151
 
222
- it "should intersect two keys with weighted minimum values" do
223
- @client.zinterstore("out", %w(key1 key2), :weights => [10, 1], :aggregate => :min).should be == 2
224
- @client.zrange("out", 0, -1, :with_scores => true).should be == ["two", "5", "three", "7"]
225
- end
226
-
227
- it "should intersect two keys with weighted maximum values" do
228
- @client.zinterstore("out", %w(key1 key2), :weights => [10, 1], :aggregate => :max).should be == 2
229
- @client.zrange("out", 0, -1, :with_scores => true).should be == ["two", (2 * 10).to_s, "three", (3 * 10).to_s]
230
- end
231
-
232
- it "should error without enough weights given" do
233
- lambda { @client.zinterstore("out", %w(key1 key2), :weights => []) }.should raise_error(RuntimeError, "ERR syntax error")
234
- lambda { @client.zinterstore("out", %w(key1 key2), :weights => [10]) }.should raise_error(RuntimeError, "ERR syntax error")
235
- end
236
-
237
- it "should error with too many weights given" do
238
- lambda { @client.zinterstore("out", %w(key1 key2), :weights => [10, 1, 1]) }.should raise_error(RuntimeError, "ERR syntax error")
239
- end
152
+ @client.zinterstore("out", ["key1", "key2", "key3"]).should == 1
153
+ @client.zrange("out", 0, 100, :with_scores => true).should == [['two', 7]]
240
154
 
241
- it "should error with an invalid aggregate" do
242
- lambda { @client.zinterstore("out", %w(key1 key2), :aggregate => :invalid) }.should raise_error(RuntimeError, "ERR syntax error")
243
- end
155
+ @client.zinterstore("out", ["key1", "no_key"]).should == 0
156
+ @client.zrange("out", 0, 100, :with_scores => true).should == []
244
157
  end
245
158
 
246
159
  context "zremrangebyscore" do
@@ -249,107 +162,23 @@ module FakeRedis
249
162
  @client.zadd("key", 2, "two")
250
163
  @client.zadd("key", 3, "three")
251
164
 
252
- @client.zremrangebyscore("key", 0, 2).should be == 2
253
- @client.zcard("key").should be == 1
165
+ @client.zremrangebyscore("key", 0, 2).should == 2
166
+ @client.zcard("key").should == 1
254
167
  end
255
168
 
256
169
  it "should return 0 if the key didn't exist" do
257
- @client.zremrangebyscore("key", 0, 2).should be == 0
170
+ @client.zremrangebyscore("key", 0, 2).should == 0
258
171
  end
259
172
  end
260
173
 
261
174
  context '#zremrangebyrank' do
262
- it "removes all elements with in the given range" do
175
+ it 'removes all elements with in the given range' do
263
176
  @client.zadd("key", 1, "one")
264
177
  @client.zadd("key", 2, "two")
265
178
  @client.zadd("key", 3, "three")
266
179
 
267
- @client.zremrangebyrank("key", 0, 1).should be == 2
268
- @client.zcard('key').should be == 1
269
- end
270
-
271
- it "handles out of range requests" do
272
- @client.zadd("key", 1, "one")
273
- @client.zadd("key", 2, "two")
274
- @client.zadd("key", 3, "three")
275
-
276
- @client.zremrangebyrank("key", 25, -1).should be == 0
277
- @client.zcard('key').should be == 3
278
- end
279
- end
280
-
281
- describe "#zunionstore" do
282
- before do
283
- @client.zadd("key1", 1, "val1")
284
- @client.zadd("key1", 2, "val2")
285
- @client.zadd("key1", 3, "val3")
286
- @client.zadd("key2", 5, "val2")
287
- @client.zadd("key2", 7, "val3")
288
- @client.sadd("key3", "val1")
289
- @client.sadd("key3", "val2")
290
- end
291
-
292
- it "should union two keys with custom scores" do
293
- @client.zunionstore("out", %w(key1 key2)).should be == 3
294
- @client.zrange("out", 0, -1, :with_scores => true).should be == ["val1", "1", "val2", (2 + 5).to_s, "val3", (3 + 7).to_s]
295
- end
296
-
297
- it "should union two keys with a default score" do
298
- @client.zunionstore("out", %w(key1 key3)).should be == 3
299
- @client.zrange("out", 0, -1, :with_scores => true).should be == ["val1", (1 + 1).to_s, "val2", (2 + 1).to_s, "val3", "3"]
300
- end
301
-
302
- it "should union more than two keys" do
303
- @client.zunionstore("out", %w(key1 key2 key3)).should be == 3
304
- @client.zrange("out", 0, -1, :with_scores => true).should be == ["val1", (1 + 1).to_s, "val2", (2 + 5 + 1).to_s, "val3", (3 + 7).to_s]
305
- end
306
-
307
- it "should union with an unknown key" do
308
- @client.zunionstore("out", %w(key1 no_key)).should be == 3
309
- @client.zrange("out", 0, -1, :with_scores => true).should be == ["val1", "1", "val2", "2", "val3", "3"]
310
- end
311
-
312
- it "should union two keys by minimum values" do
313
- @client.zunionstore("out", %w(key1 key2), :aggregate => :min).should be == 3
314
- @client.zrange("out", 0, -1, :with_scores => true).should be == ["val1", "1", "val2", "2", "val3", "3"]
315
- end
316
-
317
- it "should union two keys by maximum values" do
318
- @client.zunionstore("out", %w(key1 key2), :aggregate => :max).should be == 3
319
- @client.zrange("out", 0, -1, :with_scores => true).should be == ["val1", "1", "val2", "5", "val3", "7"]
320
- end
321
-
322
- it "should union two keys by explicitly summing values" do
323
- @client.zunionstore("out", %w(key1 key2), :aggregate => :sum).should be == 3
324
- @client.zrange("out", 0, -1, :with_scores => true).should be == ["val1", "1", "val2", (2 + 5).to_s, "val3", (3 + 7).to_s]
325
- end
326
-
327
- it "should union two keys with weighted values" do
328
- @client.zunionstore("out", %w(key1 key2), :weights => [10, 1]).should be == 3
329
- @client.zrange("out", 0, -1, :with_scores => true).should be == ["val1", (1 * 10).to_s, "val2", (2 * 10 + 5).to_s, "val3", (3 * 10 + 7).to_s]
330
- end
331
-
332
- it "should union two keys with weighted minimum values" do
333
- @client.zunionstore("out", %w(key1 key2), :weights => [10, 1], :aggregate => :min).should be == 3
334
- @client.zrange("out", 0, -1, :with_scores => true).should be == ["val2", "5", "val3", "7", "val1", (1 * 10).to_s]
335
- end
336
-
337
- it "should union two keys with weighted maximum values" do
338
- @client.zunionstore("out", %w(key1 key2), :weights => [10, 1], :aggregate => :max).should be == 3
339
- @client.zrange("out", 0, -1, :with_scores => true).should be == ["val1", (1 * 10).to_s, "val2", (2 * 10).to_s, "val3", (3 * 10).to_s]
340
- end
341
-
342
- it "should error without enough weights given" do
343
- lambda { @client.zunionstore("out", %w(key1 key2), :weights => []) }.should raise_error(RuntimeError, "ERR syntax error")
344
- lambda { @client.zunionstore("out", %w(key1 key2), :weights => [10]) }.should raise_error(RuntimeError, "ERR syntax error")
345
- end
346
-
347
- it "should error with too many weights given" do
348
- lambda { @client.zunionstore("out", %w(key1 key2), :weights => [10, 1, 1]) }.should raise_error(RuntimeError, "ERR syntax error")
349
- end
350
-
351
- it "should error with an invalid aggregate" do
352
- lambda { @client.zunionstore("out", %w(key1 key2), :aggregate => :invalid) }.should raise_error(RuntimeError, "ERR syntax error")
180
+ @client.zremrangebyrank("key", 0, 1).should == 2
181
+ @client.zcard('key').should == 1
353
182
  end
354
183
  end
355
184