blendris 1.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/blendris.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{blendris}
5
- s.version = "1.0"
5
+ s.version = "1.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Alex McHale"]
@@ -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
- (0 ... arr.length/2).map { |i| [ arr[2*i], arr[2*i + 1] ] }
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
@@ -2,7 +2,7 @@ $:.unshift(File.dirname(__FILE__)) unless
2
2
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
4
  module Blendris
5
- VERSION = '1.0'
5
+ VERSION = '1.1'
6
6
  end
7
7
 
8
8
  require "redis"
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
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blendris
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
- - 0
9
- version: "1.0"
8
+ - 1
9
+ version: "1.1"
10
10
  platform: ruby
11
11
  authors:
12
12
  - Alex McHale
metadata.gz.sig CHANGED
Binary file