Question

Is there a common api such that if I switch between Redis or Memcached I don't have to change my code, just a config setting?

Was it helpful?

Solution

As long as you don't initialize the Memcached client yourself but you rely on Rails.cache common API, switching from Memcached to Redis is just a matter of installing redis-store and changing the configuration from

config.cache_store = :memcached_store

to

config.cache_store = :redis_store

More info about Rails.cache.

OTHER TIPS

I hate to mess with your goals, but I would advise against using redis over memcached for generic rails caching.

I use redis and resque extensively in a large rails application and I thought it would be nice to consolidate caching, raw redis and resque into one. I ran into a few big issues:

  1. First off, it was slower. It could have totally been my specific usage, the redis-store library or redis itself. I'm not going to badmouth anything and your mileage may vary, but it would suck to dump a lot of time switching to redis when memcached "just works"
  2. Memcached is nice because it's extremely easy to add servers and use consistent hashing to accomplish your goals. Redis has this also, but in my experience it was difficult to simultaneously treat redis as both a monolithic datastore in some parts of my app and in other parts treat it as a distributed, consistently hashed blobs of caching storage.

Good luck with your project. I love redis AND memcached and use them in all my projects, but I let one do it's job as a kick-ass data structure server and let the other one kick ass at caching.

The neat parts of Redis include caching "list-based" things - pushing/popping things from this list as they happen in your app.

Rather than de-serializing a large value from memcached, editing it, then re-serializing it.

This would be done in ruby code in a custom filter, vs. the basic rails cache.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top