blendris 1.0 → 1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/blendris.gemspec +1 -1
- data/lib/blendris/utils.rb +6 -1
- data/lib/blendris/zset.rb +15 -0
- data/lib/blendris.rb +1 -1
- data/spec/zset_spec.rb +13 -0
- data.tar.gz.sig +0 -0
- metadata +3 -3
- metadata.gz.sig +0 -0
data/blendris.gemspec
CHANGED
data/lib/blendris/utils.rb
CHANGED
@@ -41,7 +41,12 @@ module Blendris
|
|
41
41
|
# Take an array and turn it into a list of pairs.
|
42
42
|
def pairify(*arr)
|
43
43
|
arr = arr.flatten
|
44
|
-
|
44
|
+
|
45
|
+
if arr.length == 1 && arr.first.kind_of?(Hash)
|
46
|
+
arr.first.map { |k, v| [ k, v ] }
|
47
|
+
else
|
48
|
+
(0 ... arr.length/2).map { |i| [ arr[2*i], arr[2*i + 1] ] }
|
49
|
+
end
|
45
50
|
end
|
46
51
|
|
47
52
|
end
|
data/lib/blendris/zset.rb
CHANGED
@@ -24,6 +24,21 @@ module Blendris
|
|
24
24
|
self
|
25
25
|
end
|
26
26
|
|
27
|
+
def each_with_scores(min = "-inf", max = "+inf", mode = :score)
|
28
|
+
flat_pairs =
|
29
|
+
case mode
|
30
|
+
when :rank then redis.zrange key, min, max, :with_scores => true
|
31
|
+
when :score then redis.zrangebyscore key, min, max, :with_scores => true
|
32
|
+
else raise "unknown zset mode #{mode}"
|
33
|
+
end
|
34
|
+
|
35
|
+
pairify(flat_pairs).each do |value, score|
|
36
|
+
yield score.to_f, value
|
37
|
+
end
|
38
|
+
|
39
|
+
self
|
40
|
+
end
|
41
|
+
|
27
42
|
def set(*pairs)
|
28
43
|
tempkey = "#{key}:::TEMP:::#{rand}"
|
29
44
|
redis.del tempkey
|
data/lib/blendris.rb
CHANGED
data/spec/zset_spec.rb
CHANGED
@@ -13,4 +13,17 @@ describe "redis zsets" do
|
|
13
13
|
z.to_a.should == %w( dog )
|
14
14
|
end
|
15
15
|
|
16
|
+
it "should delete correctly" do
|
17
|
+
z = RedisSortedSet.new("set1")
|
18
|
+
z << [ [2, "timothy"], [1, "alexander"], [3, "mchale"], [0, "dog"], [7, "cat"] ]
|
19
|
+
z.delete_by_score 1, 3
|
20
|
+
z.to_a.should == %w( dog cat )
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should accept hashes" do
|
24
|
+
z = RedisSortedSet.new("set1")
|
25
|
+
z << { 2 => "c", 0 => "a", 1 => "b" }
|
26
|
+
z.to_a.should == %w( a b c )
|
27
|
+
end
|
28
|
+
|
16
29
|
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|