Skip to content
Browse files

add set command

  • Loading branch information...
1 parent 514a0fe commit ce697b4b44855fadf77206a3d40f8d7856b66782 @igrigorik committed May 9, 2010
Showing with 17 additions and 0 deletions.
  1. +5 −0 lib/rrrdtool.rb
  2. +12 −0 spec/rrrdtool_spec.rb
View
5 lib/rrrdtool.rb
@@ -60,6 +60,11 @@ def incr(set, key, val=1)
@db.zincrby(epoch(set), val, key).to_i
end
+ def set(set, key, val)
+ debug [:zadd, epoch(set), val, key]
+ @db.zadd(epoch(set), val, key)
+ end
+
def first(set, num, options = {})
union_epochs(set)
e = @db.zrevrange("#{set}:union", 0, num, options)
View
12 spec/rrrdtool_spec.rb
@@ -22,6 +22,18 @@
rr.score("test", "random_key").should == 0
end
+ it "should (re)set score within correct epoch" do
+ rr.score("test", "key").should == 0
+ rr.set("test", "key", 5)
+ rr.score("test", "key").should == 5
+
+ rr.incr("test", "key").should == 6
+ rr.score("test", "key").should == 6
+
+ rr.set("test", "key", 5)
+ rr.score("test", "key").should == 5
+ end
+
it "should increment buckets within correct epoch" do
rr.epoch("test").should match(/test:0/)

0 comments on commit ce697b4

Please sign in to comment.
Something went wrong with that request. Please try again.