Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Tracks the number of active objects during a certain time period in a Redis sorted set.
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.

Active Set

This tracks the number of active objects during a certain time period in a Redis sorted set. Object activity is defined by your application, and is out of the scope of this library.


gem install active_set


When an object is active, it gets added to a Redis set with a timestamp.

set =
set.add(1, # is default if no time is given.

This is equivalent to the following Redis command:

ZADD active:objects 1305054408 "1"

We can count the number of items in the set:

set.count # => 1
# ZCARD active:objects

You can also count the active items since a given time:

# ZCOUNT active:objects 1302462660 +inf

The set should be trimmed periodically so that old objects aren't counted.

# ZREMRANGEBYSCORE active:objects -inf (1302462660

If no trim date is given, 30 days is assumed.

You can also check if an object is in the active set, and get it's last timestamp.

set.timestamp_for(1) # => Time
# ZSCORE active:objects "1"


If you'd like to hack on ActiveSet, start by forking the repo on GitHub:

The best way to get your changes merged back into core is as follows:

  • Clone down your fork
  • Create a thoughtfully named topic branch to contain your change
  • Hack away
  • Add tests and make sure everything still passes by running rake
  • If you are adding new functionality, document it in the README
  • Do not change the version number, I will do that on my end
  • If necessary, rebase your commits into logical chunks, without errors
  • Push the branch up to GitHub
  • Send a pull request to the technoweenie/redis_active_set project.
Something went wrong with that request. Please try again.