Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

73 lines (45 sloc) 1.862 kB


RedisTags is a simple graph based implementation of a tagging system. Instead of using complex relational structure, this implementation consists of using Redis sets for reference and aggregation.


Say we tag a User instance with a tag named tzetzi:

@user =
@user.tags_collection << `tzetzi`                        # => <User: id:1> 

Now in Redis, we will have these keys:

  1. A set that holds the ids of the users tagged by "tzetzi"

    user:tagged_with:tzetzi => [1]

  2. A set that holds all the tags for a specific user instance

    user:1:tag_list => ["tzetzi"]

  3. A complete breakdown of each tag per char, to allow simple autocomplete interface

    tag:all:t # => ["tzetzi"] tag:all:tz # => ["tzetzi"] tag:all:tze # => ["tzetzi"] tag:all:tzet # => ["tzetzi"] tag:all:tzetz # => ["tzetzi"] tag:all:tzetzi # => ["tzetzi"]


Add this line to your application's Gemfile:

gem 'redis_tags'

And then execute:

$ bundle

Or install it yourself as:

$ gem install redis_tags


class User

    include RedisTags

    uses_redis_tags :engine =>


@user =
@user.tag_collection                  # => []
@user.tag_collection << "elad"        # => ["elad"]
@user.tag_collection = ["beata"]      # => ["beata"]

User.has_tags(:tags => ["elad"])   # => []
User.tags_starting_with("el")         # => ["elad"]


  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request
Jump to Line
Something went wrong with that request. Please try again.