Skip to content
Browse files

add rank command

  • Loading branch information...
1 parent f23ca39 commit 7bebff235405fde02986248009e5455789e5e50c @igrigorik committed May 9, 2010
Showing with 20 additions and 0 deletions.
  1. +5 −0 lib/rrrdtool.rb
  2. +15 −0 spec/rrrdtool_spec.rb
View
5 lib/rrrdtool.rb
@@ -78,6 +78,11 @@ def last(set, num, options = {})
options.key?(:with_scores) ? Hash[*e] : e
end
+ def rank(set, key)
+ union_epochs(set)
+ @db.zrevrank("#{set}:union", key)
+ end
+
def stats(set)
stats = {}
View
15 spec/rrrdtool_spec.rb
@@ -122,6 +122,21 @@
end
end
+ it "should return rank of key across all epochs" do
+ rr.set("test", "key1", 2)
+ rr.set("test", "key2", 1)
+
+ time_travel_to(Time.now + 10) do
+ rr.epoch("test").should match(/test:1/)
+
+ rr.set("test", "key1", 1)
+ rr.set("test", "key2", 3)
+
+ rr.rank("test", "key2").should == 0
+ rr.rank("test", "key1").should == 1
+ end
+ end
+
it "should footprint stats" do
rr.incr("test", "key")
rr.incr("test", "key2")

0 comments on commit 7bebff2

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