rediska 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/rediska/driver.rb +2 -2
- data/lib/rediska/version.rb +1 -1
- data/spec/support/sets.rb +6 -0
- data/spec/support/sorted_sets.rb +278 -273
- metadata +2 -2
data/Gemfile.lock
CHANGED
data/lib/rediska/driver.rb
CHANGED
@@ -404,7 +404,7 @@ module Rediska
|
|
404
404
|
def sdiff(key1, *keys)
|
405
405
|
[key1, *keys].each { |k| data_type_check(k, ::Set) }
|
406
406
|
keys = keys.map { |k| data[k] || ::Set.new }
|
407
|
-
keys.inject(data[key1]) do |memo, set|
|
407
|
+
keys.inject(data[key1] || Set.new) do |memo, set|
|
408
408
|
memo - set
|
409
409
|
end.to_a
|
410
410
|
end
|
@@ -732,7 +732,7 @@ module Rediska
|
|
732
732
|
return 0 unless data[key]
|
733
733
|
|
734
734
|
response = values.map do |v|
|
735
|
-
data[key].delete(v) if data[key].has_key?(v)
|
735
|
+
data[key].delete(v.to_s) if data[key].has_key?(v.to_s)
|
736
736
|
end.compact.size
|
737
737
|
|
738
738
|
remove_key_for_empty_collection(key)
|
data/lib/rediska/version.rb
CHANGED
data/spec/support/sets.rb
CHANGED
@@ -44,6 +44,12 @@ shared_examples 'sets' do
|
|
44
44
|
subject.sdiff('key1', 'key2', 'key3').should =~ ['b', 'd']
|
45
45
|
end
|
46
46
|
|
47
|
+
it 'should subtract from a nonexistent set' do
|
48
|
+
subject.sadd('key2', 'a')
|
49
|
+
subject.sadd('key2', 'b')
|
50
|
+
subject.sdiff('key1', 'key2').should be_empty
|
51
|
+
end
|
52
|
+
|
47
53
|
it 'should subtract multiple sets and store the resulting set in a key' do
|
48
54
|
subject.sadd('key1', 'a')
|
49
55
|
subject.sadd('key1', 'b')
|
data/spec/support/sorted_sets.rb
CHANGED
@@ -130,7 +130,6 @@ shared_examples 'sorted sets' do
|
|
130
130
|
subject.zscore('key', 1).should eq(1)
|
131
131
|
end
|
132
132
|
|
133
|
-
# These won't pass until redis-rb releases v3.0.2
|
134
133
|
it 'should handle infinity values when incrementing a sorted set key' do
|
135
134
|
subject.zincrby('bar', '+inf', 's2').should eq(infinity)
|
136
135
|
subject.zincrby('bar', '-inf', 's1').should eq(-infinity)
|
@@ -147,301 +146,307 @@ shared_examples 'sorted sets' do
|
|
147
146
|
subject.zrange('key', 1, 2, with_scores: true).should eq([['two', 2], ['three', 3]])
|
148
147
|
end
|
149
148
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
149
|
+
it 'should sort zrange results logically' do
|
150
|
+
subject.zadd('key', 5, 'val2')
|
151
|
+
subject.zadd('key', 5, 'val3')
|
152
|
+
subject.zadd('key', 5, 'val1')
|
153
|
+
|
154
|
+
subject.zrange('key', 0, -1).should eq(%w(val1 val2 val3))
|
155
|
+
subject.zrange('key', 0, -1, with_scores: true).should eq([['val1', 5], ['val2', 5], ['val3', 5]])
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'should return a reversed range of members in a sorted set, by index' do
|
159
|
+
subject.zadd('key', 1, 'one')
|
160
|
+
subject.zadd('key', 2, 'two')
|
161
|
+
subject.zadd('key', 3, 'three')
|
162
|
+
|
163
|
+
subject.zrevrange('key', 0, -1).should eq(['three', 'two', 'one'])
|
164
|
+
subject.zrevrange('key', 1, 2).should eq(['two', 'one'])
|
165
|
+
subject.zrevrange('key', 0, -1, with_scores: true).should eq([['three', 3], ['two', 2], ['one', 1]])
|
166
|
+
subject.zrevrange('key', 0, -1, with_scores: true).should eq([['three', 3], ['two', 2], ['one', 1]])
|
167
|
+
end
|
168
|
+
|
169
|
+
it 'should return a range of members in a sorted set, by score' do
|
170
|
+
subject.zadd('key', 1, 'one')
|
171
|
+
subject.zadd('key', 2, 'two')
|
172
|
+
subject.zadd('key', 3, 'three')
|
173
|
+
|
174
|
+
subject.zrangebyscore('key', 0, 100).should eq(['one', 'two', 'three'])
|
175
|
+
subject.zrangebyscore('key', 1, 2).should eq(['one', 'two'])
|
176
|
+
subject.zrangebyscore('key', 0, 100, with_scores: true).should eq([['one', 1], ['two', 2], ['three', 3]])
|
177
|
+
subject.zrangebyscore('key', 1, 2, with_scores: true).should eq([['one', 1], ['two', 2]])
|
178
|
+
subject.zrangebyscore('key', 0, 100, limit: [0, 1]).should eq(['one'])
|
179
|
+
subject.zrangebyscore('key', 0, 100, limit: [0, -1]).should eq(['one', 'two', 'three'])
|
180
|
+
subject.zrangebyscore('key', 0, 100, limit: [1, -1], with_scores: true).should eq([['two', 2], ['three', 3]])
|
181
|
+
subject.zrangebyscore('key', '-inf', '+inf').should eq(['one', 'two', 'three'])
|
182
|
+
subject.zrangebyscore('key', 2, '+inf').should eq(['two', 'three'])
|
183
|
+
subject.zrangebyscore('key', '-inf', 2).should eq(['one', 'two'])
|
184
|
+
end
|
185
|
+
|
186
|
+
it 'should return a reversed range of members in a sorted set, by score' do
|
187
|
+
subject.zadd('key', 1, 'one')
|
188
|
+
subject.zadd('key', 2, 'two')
|
189
|
+
subject.zadd('key', 3, 'three')
|
190
|
+
|
191
|
+
subject.zrevrangebyscore('key', 100, 0).should eq(['three', 'two', 'one'])
|
192
|
+
subject.zrevrangebyscore('key', 2, 1).should eq(['two', 'one'])
|
193
|
+
subject.zrevrangebyscore('key', 1, 2).should be_empty
|
194
|
+
subject.zrevrangebyscore('key', 2, 1, with_scores: true).should eq([['two', 2], ['one', 1]])
|
195
|
+
subject.zrevrangebyscore('key', 100, 0, limit: [0, 1]).should eq(['three'])
|
196
|
+
subject.zrevrangebyscore('key', 100, 0, limit: [0, -1]).should eq(['three', 'two', 'one'])
|
197
|
+
subject.zrevrangebyscore('key', 100, 0, limit: [1, -1], with_scores: true).should eq([['two', 2], ['one', 1]])
|
198
|
+
end
|
199
|
+
|
200
|
+
it 'should determine the index of a member in a sorted set' do
|
201
|
+
subject.zadd('key', 1, 'one')
|
202
|
+
subject.zadd('key', 2, 'two')
|
203
|
+
subject.zadd('key', 3, 'three')
|
204
|
+
|
205
|
+
subject.zrank('key', 'three').should eq(2)
|
206
|
+
subject.zrank('key', 'four').should be_nil
|
207
|
+
end
|
208
|
+
|
209
|
+
it 'should determine the reversed index of a member in a sorted set' do
|
210
|
+
subject.zadd('key', 1, 'one')
|
211
|
+
subject.zadd('key', 2, 'two')
|
212
|
+
subject.zadd('key', 3, 'three')
|
213
|
+
|
214
|
+
subject.zrevrank('key', 'three').should eq(0)
|
215
|
+
subject.zrevrank('key', 'four').should be_nil
|
216
|
+
end
|
154
217
|
|
155
|
-
|
156
|
-
|
218
|
+
it 'should not raise errors for zrank() on accessing a non-existing key in a sorted set' do
|
219
|
+
subject.zrank('no_such_key', 'no_suck_id').should be_nil
|
220
|
+
end
|
221
|
+
|
222
|
+
it 'should not raise errors for zrevrank() on accessing a non-existing key in a sorted set' do
|
223
|
+
subject.zrevrank('no_such_key', 'no_suck_id').should be_nil
|
224
|
+
end
|
225
|
+
|
226
|
+
describe '#zinterstore' do
|
227
|
+
before do
|
228
|
+
subject.zadd('key1', 1, 'one')
|
229
|
+
subject.zadd('key1', 2, 'two')
|
230
|
+
subject.zadd('key1', 3, 'three')
|
231
|
+
subject.zadd('key2', 5, 'two')
|
232
|
+
subject.zadd('key2', 7, 'three')
|
233
|
+
subject.sadd('key3', 'one')
|
234
|
+
subject.sadd('key3', 'two')
|
157
235
|
end
|
158
236
|
|
159
|
-
it 'should
|
160
|
-
subject.
|
161
|
-
subject.
|
162
|
-
|
237
|
+
it 'should intersect two keys with custom scores' do
|
238
|
+
subject.zinterstore('out', ['key1', 'key2']).should eq(2)
|
239
|
+
subject.zrange('out', 0, -1, with_scores: true).should eq([['two', (2 + 5)], ['three', (3 + 7)]])
|
240
|
+
end
|
163
241
|
|
164
|
-
|
165
|
-
subject.
|
166
|
-
subject.
|
167
|
-
subject.zrevrange('key', 0, -1, with_scores: true).should eq([['three', 3], ['two', 2], ['one', 1]])
|
242
|
+
it 'should intersect two keys with a default score' do
|
243
|
+
subject.zinterstore('out', ['key1', 'key3']).should eq(2)
|
244
|
+
subject.zrange('out', 0, -1, with_scores: true).should eq([['one', (1 + 1)], ['two', (2 + 1)]])
|
168
245
|
end
|
169
246
|
|
170
|
-
it 'should
|
171
|
-
subject.
|
172
|
-
subject.
|
173
|
-
|
247
|
+
it 'should intersect more than two keys' do
|
248
|
+
subject.zinterstore('out', ['key1', 'key2', 'key3']).should eq(1)
|
249
|
+
subject.zrange('out', 0, -1, with_scores: true).should eq([['two', (2 + 5 + 1)]])
|
250
|
+
end
|
251
|
+
|
252
|
+
it 'should not intersect an unknown key' do
|
253
|
+
subject.zinterstore('out', ['key1', 'no_key']).should eq(0)
|
254
|
+
subject.zrange('out', 0, -1, with_scores: true).should be_empty
|
255
|
+
end
|
256
|
+
|
257
|
+
it 'should intersect two keys by minimum values' do
|
258
|
+
subject.zinterstore('out', ['key1', 'key2'], aggregate: :min).should eq(2)
|
259
|
+
subject.zrange('out', 0, -1, with_scores: true).should eq([['two', 2], ['three', 3]])
|
260
|
+
end
|
261
|
+
|
262
|
+
it 'should intersect two keys by maximum values' do
|
263
|
+
subject.zinterstore('out', ['key1', 'key2'], aggregate: :max).should eq(2)
|
264
|
+
subject.zrange('out', 0, -1, with_scores: true).should eq([['two', 5], ['three', 7]])
|
265
|
+
end
|
266
|
+
|
267
|
+
it 'should intersect two keys by explicitly summing values' do
|
268
|
+
subject.zinterstore('out', %w(key1 key2), aggregate: :sum).should eq(2)
|
269
|
+
subject.zrange('out', 0, -1, with_scores: true).should eq([['two', (2 + 5)], ['three', (3 + 7)]])
|
270
|
+
end
|
271
|
+
|
272
|
+
it 'should intersect two keys with weighted values' do
|
273
|
+
subject.zinterstore('out', %w(key1 key2), weights: [10, 1]).should eq(2)
|
274
|
+
subject.zrange('out', 0, -1, with_scores: true).should eq([['two', (2 * 10 + 5)], ['three', (3 * 10 + 7)]])
|
275
|
+
end
|
174
276
|
|
175
|
-
|
176
|
-
subject.
|
177
|
-
subject.
|
178
|
-
subject.zrangebyscore('key', 1, 2, with_scores: true).should eq([['one', 1], ['two', 2]])
|
179
|
-
subject.zrangebyscore('key', 0, 100, limit: [0, 1]).should eq(['one'])
|
180
|
-
subject.zrangebyscore('key', 0, 100, limit: [0, -1]).should eq(['one', 'two', 'three'])
|
181
|
-
subject.zrangebyscore('key', 0, 100, limit: [1, -1], with_scores: true).should eq([['two', 2], ['three', 3]])
|
182
|
-
subject.zrangebyscore('key', '-inf', '+inf').should eq(['one', 'two', 'three'])
|
183
|
-
subject.zrangebyscore('key', 2, '+inf').should eq(['two', 'three'])
|
184
|
-
subject.zrangebyscore('key', '-inf', 2).should eq(['one', 'two'])
|
277
|
+
it 'should intersect two keys with weighted minimum values' do
|
278
|
+
subject.zinterstore('out', %w(key1 key2), weights: [10, 1], aggregate: :min).should eq(2)
|
279
|
+
subject.zrange('out', 0, -1, with_scores: true).should eq([['two', 5], ['three', 7]])
|
185
280
|
end
|
186
281
|
|
187
|
-
it 'should
|
282
|
+
it 'should intersect two keys with weighted maximum values' do
|
283
|
+
subject.zinterstore('out', %w(key1 key2), weights: [10, 1], aggregate: :max).should eq(2)
|
284
|
+
subject.zrange('out', 0, -1, with_scores: true).should eq([['two', (2 * 10)], ['three', (3 * 10)]])
|
285
|
+
end
|
286
|
+
|
287
|
+
it 'should error without enough weights given' do
|
288
|
+
expect {
|
289
|
+
subject.zinterstore('out', %w(key1 key2), weights: [])
|
290
|
+
}.to raise_error(Redis::CommandError)
|
291
|
+
|
292
|
+
expect {
|
293
|
+
subject.zinterstore('out', %w(key1 key2), weights: [10])
|
294
|
+
}.to raise_error(Redis::CommandError)
|
295
|
+
end
|
296
|
+
|
297
|
+
it 'should error with too many weights given' do
|
298
|
+
expect {
|
299
|
+
subject.zinterstore('out', %w(key1 key2), weights: [10, 1, 1])
|
300
|
+
}.to raise_error(Redis::CommandError)
|
301
|
+
end
|
302
|
+
|
303
|
+
it 'should error with an invalid aggregate' do
|
304
|
+
expect {
|
305
|
+
subject.zinterstore('out', %w(key1 key2), aggregate: :invalid)
|
306
|
+
}.to raise_error(Redis::CommandError)
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
310
|
+
describe 'zremrangebyscore' do
|
311
|
+
it 'should remove items by score' do
|
188
312
|
subject.zadd('key', 1, 'one')
|
189
313
|
subject.zadd('key', 2, 'two')
|
190
314
|
subject.zadd('key', 3, 'three')
|
191
315
|
|
192
|
-
subject.
|
193
|
-
subject.
|
194
|
-
subject.zrevrangebyscore('key', 1, 2).should be_empty
|
195
|
-
subject.zrevrangebyscore('key', 2, 1, with_scores: true).should eq([['two', 2], ['one', 1]])
|
196
|
-
subject.zrevrangebyscore('key', 100, 0, limit: [0, 1]).should eq(['three'])
|
197
|
-
subject.zrevrangebyscore('key', 100, 0, limit: [0, -1]).should eq(['three', 'two', 'one'])
|
198
|
-
subject.zrevrangebyscore('key', 100, 0, limit: [1, -1], with_scores: true).should eq([['two', 2], ['one', 1]])
|
316
|
+
subject.zremrangebyscore('key', 0, 2).should eq(2)
|
317
|
+
subject.zcard('key').should eq(1)
|
199
318
|
end
|
200
319
|
|
201
|
-
it 'should
|
320
|
+
it 'should remove items by score with infinity' do # Issue #50
|
321
|
+
subject.zadd('key', 10.0, 'one')
|
322
|
+
subject.zadd('key', 20.0, 'two')
|
323
|
+
subject.zadd('key', 30.0, 'three')
|
324
|
+
subject.zremrangebyscore('key', '-inf', '+inf').should eq(3)
|
325
|
+
subject.zcard('key').should eq(0)
|
326
|
+
subject.zscore('key', 'one').should be_nil
|
327
|
+
subject.zscore('key', 'two').should be_nil
|
328
|
+
subject.zscore('key', 'three').should be_nil
|
329
|
+
end
|
330
|
+
|
331
|
+
it 'should return 0 if the key did not exist' do
|
332
|
+
subject.zremrangebyscore('key', 0, 2).should eq(0)
|
333
|
+
end
|
334
|
+
end
|
335
|
+
|
336
|
+
describe '#zremrangebyrank' do
|
337
|
+
it 'removes all elements with in the given range' do
|
202
338
|
subject.zadd('key', 1, 'one')
|
203
339
|
subject.zadd('key', 2, 'two')
|
204
340
|
subject.zadd('key', 3, 'three')
|
205
341
|
|
206
|
-
subject.
|
207
|
-
subject.
|
342
|
+
subject.zremrangebyrank('key', 0, 1).should eq(2)
|
343
|
+
subject.zcard('key').should eq(1)
|
208
344
|
end
|
209
345
|
|
210
|
-
it '
|
346
|
+
it 'handles out of range requests' do
|
211
347
|
subject.zadd('key', 1, 'one')
|
212
348
|
subject.zadd('key', 2, 'two')
|
213
349
|
subject.zadd('key', 3, 'three')
|
214
350
|
|
215
|
-
subject.
|
216
|
-
subject.
|
217
|
-
end
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
subject.
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
end
|
303
|
-
|
304
|
-
it 'should error with an invalid aggregate' do
|
305
|
-
expect {
|
306
|
-
subject.zinterstore('out', %w(key1 key2), aggregate: :invalid)
|
307
|
-
}.to raise_error(Redis::CommandError)
|
308
|
-
end
|
309
|
-
end
|
310
|
-
|
311
|
-
context 'zremrangebyscore' do
|
312
|
-
it 'should remove items by score' do
|
313
|
-
subject.zadd('key', 1, 'one')
|
314
|
-
subject.zadd('key', 2, 'two')
|
315
|
-
subject.zadd('key', 3, 'three')
|
316
|
-
|
317
|
-
subject.zremrangebyscore('key', 0, 2).should eq(2)
|
318
|
-
subject.zcard('key').should eq(1)
|
319
|
-
end
|
320
|
-
|
321
|
-
it 'should remove items by score with infinity' do # Issue #50
|
322
|
-
subject.zadd('key', 10.0, 'one')
|
323
|
-
subject.zadd('key', 20.0, 'two')
|
324
|
-
subject.zadd('key', 30.0, 'three')
|
325
|
-
subject.zremrangebyscore('key', '-inf', '+inf').should eq(3)
|
326
|
-
subject.zcard('key').should eq(0)
|
327
|
-
subject.zscore('key', 'one').should be_nil
|
328
|
-
subject.zscore('key', 'two').should be_nil
|
329
|
-
subject.zscore('key', 'three').should be_nil
|
330
|
-
end
|
331
|
-
|
332
|
-
it 'should return 0 if the key did not exist' do
|
333
|
-
subject.zremrangebyscore('key', 0, 2).should eq(0)
|
334
|
-
end
|
335
|
-
end
|
336
|
-
|
337
|
-
context '#zremrangebyrank' do
|
338
|
-
it 'removes all elements with in the given range' do
|
339
|
-
subject.zadd('key', 1, 'one')
|
340
|
-
subject.zadd('key', 2, 'two')
|
341
|
-
subject.zadd('key', 3, 'three')
|
342
|
-
|
343
|
-
subject.zremrangebyrank('key', 0, 1).should eq(2)
|
344
|
-
subject.zcard('key').should eq(1)
|
345
|
-
end
|
346
|
-
|
347
|
-
it 'handles out of range requests' do
|
348
|
-
subject.zadd('key', 1, 'one')
|
349
|
-
subject.zadd('key', 2, 'two')
|
350
|
-
subject.zadd('key', 3, 'three')
|
351
|
-
|
352
|
-
subject.zremrangebyrank('key', 25, -1).should eq(0)
|
353
|
-
subject.zcard('key').should eq(3)
|
354
|
-
end
|
355
|
-
end
|
356
|
-
|
357
|
-
describe '#zunionstore' do
|
358
|
-
before do
|
359
|
-
subject.zadd('key1', 1, 'val1')
|
360
|
-
subject.zadd('key1', 2, 'val2')
|
361
|
-
subject.zadd('key1', 3, 'val3')
|
362
|
-
subject.zadd('key2', 5, 'val2')
|
363
|
-
subject.zadd('key2', 7, 'val3')
|
364
|
-
subject.sadd('key3', 'val1')
|
365
|
-
subject.sadd('key3', 'val2')
|
366
|
-
end
|
367
|
-
|
368
|
-
it 'should union two keys with custom scores' do
|
369
|
-
subject.zunionstore('out', %w(key1 key2)).should eq(3)
|
370
|
-
subject.zrange('out', 0, -1, with_scores: true).should eq([['val1', 1], ['val2', (2 + 5)], ['val3', (3 + 7)]])
|
371
|
-
end
|
372
|
-
|
373
|
-
it 'should union two keys with a default score' do
|
374
|
-
subject.zunionstore('out', %w(key1 key3)).should eq(3)
|
375
|
-
subject.zrange('out', 0, -1, with_scores: true).should eq([['val1', (1 + 1)], ['val2', (2 + 1)], ['val3', 3]])
|
376
|
-
end
|
377
|
-
|
378
|
-
it 'should union more than two keys' do
|
379
|
-
subject.zunionstore('out', %w(key1 key2 key3)).should eq(3)
|
380
|
-
subject.zrange('out', 0, -1, with_scores: true).should eq([['val1', (1 + 1)], ['val2', (2 + 5 + 1)], ['val3', (3 + 7)]])
|
381
|
-
end
|
382
|
-
|
383
|
-
it 'should union with an unknown key' do
|
384
|
-
subject.zunionstore('out', %w(key1 no_key)).should eq(3)
|
385
|
-
subject.zrange('out', 0, -1, with_scores: true).should eq([['val1', 1], ['val2', 2], ['val3', 3]])
|
386
|
-
end
|
387
|
-
|
388
|
-
it 'should union two keys by minimum values' do
|
389
|
-
subject.zunionstore('out', %w(key1 key2), aggregate: :min).should eq(3)
|
390
|
-
subject.zrange('out', 0, -1, with_scores: true).should eq([['val1', 1], ['val2', 2], ['val3', 3]])
|
391
|
-
end
|
392
|
-
|
393
|
-
it 'should union two keys by maximum values' do
|
394
|
-
subject.zunionstore('out', %w(key1 key2), aggregate: :max).should eq(3)
|
395
|
-
subject.zrange('out', 0, -1, with_scores: true).should eq([['val1', 1], ['val2', 5], ['val3', 7]])
|
396
|
-
end
|
397
|
-
|
398
|
-
it 'should union two keys by explicitly summing values' do
|
399
|
-
subject.zunionstore('out', %w(key1 key2), aggregate: :sum).should eq(3)
|
400
|
-
subject.zrange('out', 0, -1, with_scores: true).should eq([['val1', 1], ['val2', (2 + 5)], ['val3', (3 + 7)]])
|
401
|
-
end
|
402
|
-
|
403
|
-
it 'should union two keys with weighted values' do
|
404
|
-
subject.zunionstore('out', %w(key1 key2), :weights => [10, 1]).should eq(3)
|
405
|
-
subject.zrange('out', 0, -1, with_scores: true).should eq([['val1', (1 * 10)], ['val2', (2 * 10 + 5)], ['val3', (3 * 10 + 7)]])
|
406
|
-
end
|
407
|
-
|
408
|
-
it 'should union two keys with weighted minimum values' do
|
409
|
-
subject.zunionstore('out', %w(key1 key2), weights: [10, 1], aggregate: :min).should eq(3)
|
410
|
-
subject.zrange('out', 0, -1, with_scores: true).should eq([['val2', 5], ['val3', 7], ['val1', (1 * 10)]])
|
411
|
-
end
|
412
|
-
|
413
|
-
it 'should union two keys with weighted maximum values' do
|
414
|
-
subject.zunionstore('out', %w(key1 key2), weights: [10, 1], aggregate: :max).should eq(3)
|
415
|
-
subject.zrange('out', 0, -1, with_scores: true).should eq([['val1', (1 * 10)], ['val2', (2 * 10)], ['val3', (3 * 10)]])
|
416
|
-
end
|
417
|
-
|
418
|
-
it 'should error without enough weights given' do
|
419
|
-
expect {
|
420
|
-
subject.zunionstore('out', %w(key1 key2), weights: [])
|
421
|
-
}.to raise_error(Redis::CommandError)
|
422
|
-
|
423
|
-
expect {
|
424
|
-
subject.zunionstore('out', %w(key1 key2), weights: [10])
|
425
|
-
}.to raise_error(Redis::CommandError)
|
426
|
-
end
|
427
|
-
|
428
|
-
it 'should error with too many weights given' do
|
429
|
-
expect {
|
430
|
-
subject.zunionstore('out', %w(key1 key2), weights: [10, 1, 1])
|
431
|
-
}.to raise_error(Redis::CommandError)
|
432
|
-
end
|
433
|
-
|
434
|
-
it 'should error with an invalid aggregate' do
|
435
|
-
expect {
|
436
|
-
subject.zunionstore('out', %w(key1 key2), aggregate: :invalid)
|
437
|
-
}.to raise_error(Redis::CommandError)
|
438
|
-
end
|
439
|
-
end
|
440
|
-
|
441
|
-
#it 'should remove all members in a sorted set within the given indexes'
|
442
|
-
#it 'should return a range of members in a sorted set, by index, with scores ordered from high to low'
|
443
|
-
#it 'should return a range of members in a sorted set, by score, with scores ordered from high to low'
|
444
|
-
#it 'should determine the index of a member in a sorted set, with scores ordered from high to low'
|
445
|
-
#it 'should get the score associated with the given member in a sorted set'
|
446
|
-
#it 'should add multiple sorted sets and store the resulting sorted set in a new key'
|
351
|
+
subject.zremrangebyrank('key', 25, -1).should eq(0)
|
352
|
+
subject.zcard('key').should eq(3)
|
353
|
+
end
|
354
|
+
end
|
355
|
+
|
356
|
+
describe '#zunionstore' do
|
357
|
+
before do
|
358
|
+
subject.zadd('key1', 1, 'val1')
|
359
|
+
subject.zadd('key1', 2, 'val2')
|
360
|
+
subject.zadd('key1', 3, 'val3')
|
361
|
+
subject.zadd('key2', 5, 'val2')
|
362
|
+
subject.zadd('key2', 7, 'val3')
|
363
|
+
subject.sadd('key3', 'val1')
|
364
|
+
subject.sadd('key3', 'val2')
|
365
|
+
end
|
366
|
+
|
367
|
+
it 'should union two keys with custom scores' do
|
368
|
+
subject.zunionstore('out', %w(key1 key2)).should eq(3)
|
369
|
+
subject.zrange('out', 0, -1, with_scores: true).should eq([['val1', 1], ['val2', (2 + 5)], ['val3', (3 + 7)]])
|
370
|
+
end
|
371
|
+
|
372
|
+
it 'should union two keys with a default score' do
|
373
|
+
subject.zunionstore('out', %w(key1 key3)).should eq(3)
|
374
|
+
subject.zrange('out', 0, -1, with_scores: true).should eq([['val1', (1 + 1)], ['val2', (2 + 1)], ['val3', 3]])
|
375
|
+
end
|
376
|
+
|
377
|
+
it 'should union more than two keys' do
|
378
|
+
subject.zunionstore('out', %w(key1 key2 key3)).should eq(3)
|
379
|
+
subject.zrange('out', 0, -1, with_scores: true).should eq([['val1', (1 + 1)], ['val2', (2 + 5 + 1)], ['val3', (3 + 7)]])
|
380
|
+
end
|
381
|
+
|
382
|
+
it 'should union with an unknown key' do
|
383
|
+
subject.zunionstore('out', %w(key1 no_key)).should eq(3)
|
384
|
+
subject.zrange('out', 0, -1, with_scores: true).should eq([['val1', 1], ['val2', 2], ['val3', 3]])
|
385
|
+
end
|
386
|
+
|
387
|
+
it 'should union two keys by minimum values' do
|
388
|
+
subject.zunionstore('out', %w(key1 key2), aggregate: :min).should eq(3)
|
389
|
+
subject.zrange('out', 0, -1, with_scores: true).should eq([['val1', 1], ['val2', 2], ['val3', 3]])
|
390
|
+
end
|
391
|
+
|
392
|
+
it 'should union two keys by maximum values' do
|
393
|
+
subject.zunionstore('out', %w(key1 key2), aggregate: :max).should eq(3)
|
394
|
+
subject.zrange('out', 0, -1, with_scores: true).should eq([['val1', 1], ['val2', 5], ['val3', 7]])
|
395
|
+
end
|
396
|
+
|
397
|
+
it 'should union two keys by explicitly summing values' do
|
398
|
+
subject.zunionstore('out', %w(key1 key2), aggregate: :sum).should eq(3)
|
399
|
+
subject.zrange('out', 0, -1, with_scores: true).should eq([['val1', 1], ['val2', (2 + 5)], ['val3', (3 + 7)]])
|
400
|
+
end
|
401
|
+
|
402
|
+
it 'should union two keys with weighted values' do
|
403
|
+
subject.zunionstore('out', %w(key1 key2), :weights => [10, 1]).should eq(3)
|
404
|
+
subject.zrange('out', 0, -1, with_scores: true).should eq([['val1', (1 * 10)], ['val2', (2 * 10 + 5)], ['val3', (3 * 10 + 7)]])
|
405
|
+
end
|
406
|
+
|
407
|
+
it 'should union two keys with weighted minimum values' do
|
408
|
+
subject.zunionstore('out', %w(key1 key2), weights: [10, 1], aggregate: :min).should eq(3)
|
409
|
+
subject.zrange('out', 0, -1, with_scores: true).should eq([['val2', 5], ['val3', 7], ['val1', (1 * 10)]])
|
410
|
+
end
|
411
|
+
|
412
|
+
it 'should union two keys with weighted maximum values' do
|
413
|
+
subject.zunionstore('out', %w(key1 key2), weights: [10, 1], aggregate: :max).should eq(3)
|
414
|
+
subject.zrange('out', 0, -1, with_scores: true).should eq([['val1', (1 * 10)], ['val2', (2 * 10)], ['val3', (3 * 10)]])
|
415
|
+
end
|
416
|
+
|
417
|
+
it 'should error without enough weights given' do
|
418
|
+
expect {
|
419
|
+
subject.zunionstore('out', %w(key1 key2), weights: [])
|
420
|
+
}.to raise_error(Redis::CommandError)
|
421
|
+
|
422
|
+
expect {
|
423
|
+
subject.zunionstore('out', %w(key1 key2), weights: [10])
|
424
|
+
}.to raise_error(Redis::CommandError)
|
425
|
+
end
|
426
|
+
|
427
|
+
it 'should error with too many weights given' do
|
428
|
+
expect {
|
429
|
+
subject.zunionstore('out', %w(key1 key2), weights: [10, 1, 1])
|
430
|
+
}.to raise_error(Redis::CommandError)
|
431
|
+
end
|
432
|
+
|
433
|
+
it 'should error with an invalid aggregate' do
|
434
|
+
expect {
|
435
|
+
subject.zunionstore('out', %w(key1 key2), aggregate: :invalid)
|
436
|
+
}.to raise_error(Redis::CommandError)
|
437
|
+
end
|
447
438
|
end
|
439
|
+
|
440
|
+
it 'zrem should remove members add by zadd' do
|
441
|
+
subject.zadd('key1', 1, 3)
|
442
|
+
subject.zrem('key1', 3)
|
443
|
+
subject.zscore('key1', 3).should be_nil
|
444
|
+
end
|
445
|
+
|
446
|
+
#it 'should remove all members in a sorted set within the given indexes'
|
447
|
+
#it 'should return a range of members in a sorted set, by index, with scores ordered from high to low'
|
448
|
+
#it 'should return a range of members in a sorted set, by score, with scores ordered from high to low'
|
449
|
+
#it 'should determine the index of a member in a sorted set, with scores ordered from high to low'
|
450
|
+
#it 'should get the score associated with the given member in a sorted set'
|
451
|
+
#it 'should add multiple sorted sets and store the resulting sorted set in a new key'
|
452
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rediska
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-11-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: redis
|