Redis Store aims to be a toolkit for your Ruby applications, it natively supports sharding, master/slave replication, marshalling, timeouts and namespaces. Plus, it’s really easy to use with the most popular frameworks, such as Ruby on Rails.
If you love modularity, you will love Redis Store too: under the hood it just activates, at runtime, the best set of low level features requested by the above software layers. It’s delivered as a set of gems, one for each targeted framework, with a common background that’s the redis-store gem itself. This decision helped me a lot to deal with different versions of Ruby, several frameworks, and versions.
How to use it
Let’s say we want to use Redis Store in our Rails project. First of all we need to add an entry in our
Then we have many options:
As you can see, it’s pretty easy to plug in, but let’s investigate how to manage our configuration. The first case is self-explanatory, we’re telling
ActiveSupport to load our Redis backed store. Remember that, au contraire of Redis, which only supports strings, we can dump full objects here.
The second example is a little bit more complicated. First of all, we are employing a cluster of servers. As mentioned before, Redis Store supports sharding, that means the HTTP sessions will be transparently split across the two hosts. For each node we are specififying, respectively: protocol, password, ip, port and the Redis database.
The last one, instead describes the setup for the Rails recently added
Rack::Cache. This is a Ruby implementation of an HTTP cache proxy (like Squid or Varnish), which helps to drastically improve response times, by storing the full contents for a given url. It has two components: the metastore, used mainly to check the existence of an entry, and the entitystore, that’s the repository itself. You’ve probably noticed another parameter in the configuration: it’s the namespace, all the keys will be prefixed with something like
<namespace>:<key> . One last note: since we are storing just plain text, the mashalling module isn’t activated.
I strongly believe that Redis is must-have in your environment, it’s fast, flexible enough to be used as database, cache, pub/sub. That being said, Redis Store can be a great tool for scale your applications, but everything has a cost: fine tuning. Again, it-just-works, but as Rails itself, to step up, you’ll probably find out to experiment a little bit with the Redis configuration, in order to find the right threshold between performances, scalability and memory consumption.
If you want to give Redis store a try, please check it out on GitHub.
Sign up for a RedisToGo account and try this out in 5min.