Skip to content

Instantly share code, notes, and snippets.

@jfernandez
Created November 30, 2010 20:26
Show Gist options
  • Save jfernandez/722335 to your computer and use it in GitHub Desktop.
Save jfernandez/722335 to your computer and use it in GitHub Desktop.
Active users in the last 15 minutes with Redis
# 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