Skip to content

Commit

Permalink
Merge branch 'master' of github.com:tobi/redis-tools
Browse files Browse the repository at this point in the history
  • Loading branch information
tobi committed Jul 20, 2010
2 parents 9bbe06c + 7bd65a2 commit f30cd70
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions presence/presence.rb
Expand Up @@ -5,14 +5,12 @@

$redis = Redis.new

# By default it uses 60 secs intervals and keeps 10 unique buckets.
# This is useful for example for a chat buddy list, allows you to keep presence of all the
# people who are online by periodically adding their user ids to the presence class when they
# do http calls to you.
class Presence


# By default it uses 60 secs or 1 minute buckets and starts reusing buckets every hour.

# This is useful for example for a chat buddy list, allows you to keep presence of all the
# people who are online by periodically adding their user ids to the presence class when they
# do http calls to you.

def initialize(name, seconds = 60, buckets = 10)
@name = name
@seconds = seconds
Expand All @@ -25,7 +23,7 @@ def clear
end
end

def clear_oder_then(num)
def clear_older_then(num)
@buckets.downto(num+1) do |num|
$redis.del "#{@name}:#{recent_bucket_num(num-1)}"
end
Expand Down Expand Up @@ -90,7 +88,7 @@ def test_clear_oder_then
(0..9).each do |num|
$redis.sadd "clearing:#{num}", "DATA"
end
a.clear_oder_then(5)
a.clear_older_then(5)
assert_equal ['DATA'], $redis.smembers("clearing:#{a.send(:recent_bucket_num, 0)}")
assert_equal ['DATA'], $redis.smembers("clearing:#{a.send(:recent_bucket_num, 1)}")
assert_equal ['DATA'], $redis.smembers("clearing:#{a.send(:recent_bucket_num, 2)}")
Expand Down

0 comments on commit f30cd70

Please sign in to comment.