Navigation Menu

Skip to content

Commit

Permalink
add rank command
Browse files Browse the repository at this point in the history
  • Loading branch information
igrigorik committed May 9, 2010
1 parent f23ca39 commit 7bebff2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/rrrdtool.rb
Expand Up @@ -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 = {}

Expand Down
15 changes: 15 additions & 0 deletions spec/rrrdtool_spec.rb
Expand Up @@ -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")
Expand Down

0 comments on commit 7bebff2

Please sign in to comment.