Created
November 30, 2010 20:26
-
-
Save jfernandez/722335 to your computer and use it in GitHub Desktop.
Active users in the last 15 minutes with Redis
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Adds a User ID to a sorted set using the current timestamp as the score | |
redis = Redis.new | |
redis.zadd("active-users", Time.now.to_i, user.id) | |
# Get all User IDs with a timestamp within the timestamp range | |
user_ids = redis.zrangebyscore("active-users", 15.minutes.ago.to_i, Time.now.to_i) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment