Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of github.com:tobi/redis-tools

  • Loading branch information...
commit f30cd70dc222fbecead4e073fd172e1c2a7e6239 2 parents 9bbe06c + 7bd65a2
@tobi authored
Showing with 7 additions and 9 deletions.
  1. +7 −9 presence/presence.rb
View
16 presence/presence.rb
@@ -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
@@ -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
@@ -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)}")
Please sign in to comment.
Something went wrong with that request. Please try again.