You can just grab the gem and you’re good to go:

$ gem install easyredis

Or, you can get the source with git:

$ git clone git://

and run:

$ rake manifest
$ rake build_gemspec
$ rake install easyredis.gemspec


First, create a simple model:

require 'easyredis'

class Post < EasyRedis::Model
  field :title
  field :body


This creates a Post model and connects to a redis server running on localhost on the default port (you can pass options to EasyRedis.connect like you would to

We can now make post objects:

p =
p.title = "My First Post"
p.body = "This is my very first post!"

Posts are automatically given ids that we can then use to retrive them:

id =
p2 = Post.find(id)
p2.title  # => "My First Post"

Or, we can choose our own ids:

p ="coolpost")
p.title = "A Cool Post"
p.body = "This post has a high level of coolness."

p2 = Post.find("coolpost")  # this is a very fast lookup
p2.title  # => "A Cool Post"

We also get a created_at field for free that we can sort by.

p.created_at              # a ruby Time object
Post.all :order => :desc  # all posts ordered by descending time
Post[n]                   # the nth (0-based indexing) post that was created

Searching and Sorting

We can also tell EasyRedis to optimize sorting and searching on certain fields. If we had defined Post as:

class Post < EasyRedis::Model
  field :title
  field :body

  sort_on :title

We can now sort our posts by title:

Post.sort_by :title, :order => :desc

And also search:

Post.search_by :title, "A common title"  # all posts with this title
Post.find_by :title, "My First Post"  # just one post

Implicit References

You may have noticed fields have not been given any types. EasyRedis automatically tracks the type of a field based on the type of data you assign it.

This works for references, too:

class Comment < EasyRedis::Model
  field :text
  field :post

c =
c.text = "A comment!" = Post[0]
Fork me on GitHub