Redis Store Jr.

This is a vastly simplified version of RedisStore.

Much of this code was shamelessly lifted from an earlier version of Luca Guidi’s redis-store gem. It does not support Sinatra, Merb, distributed storage, or many of the other options that his Gem does. So if you’re lookig for that stuff, you probably want to take a look at the original project:

github.com/jodosha/redis-store

On the other hand, if you’re looking for a super-simple Redis store interface that works reliably with Rails and Redis 1.2, without the complicated (and often unnecessary) dependencies, look no further.

Note that this gem is specifically designed to work with Redis 1.2 and v1.0.7 of the Redis gem.

Installation

We assume you already have Redis (code.google.com/p/redis/) set up and running. If not, you know what to do.

In your environment.rb:

config.gem 'redis_store_jr', :lib => 'redis_store'

Or your Gemfile:

gem 'redis_store_jr', :require => 'redis_store'

To use the Rails.cache store, add the following to an initializer or your environment-specific config:

require 'redis_store'
config.cache_store = :redis_store, 'localhost:6379'

Want to store user session data in Redis too? Of course you do.

ActionController::Base.session = {
  :host => 'dbhost'
  :port => 6379,
  :db   => 2,
  :expire_after => 24.hours,
  :key_prefix   => "myapp:session:"
}
ActionController::Base.session_store = :redis_session_store

This has only been tested on Rails 2.3.x. No guarantees about Rails 3.

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Copyright © 2010 Nick Plante. See LICENSE for details.