Rails and caching, is it easy to switch between memcache and redis?

Is there a general api such that if I switch between Redis or Memcached, I don’t need to change my code, just configuration?

+25
caching ruby-on-rails memcached redis
Nov 19 '10 at 3:03
source share
3 answers

Until you initialize the Memcached client yourself, but rely on the common Rails.cache API, switching from Memcached to Redis is a matter of installing redis-store and changing the configuration from

 config.cache_store = :memcached_store 

to

 config.cache_store = :redis_store 

More information on Rails.cache .

+42
Nov 19 '10 at 9:06
source share

I hate communicating with your goals, but I would advise against using redis for memcached for general rail caching.

I use redis and multiple resque in a large rails application, and I thought it would be nice to combine caching, raw redis and resque into one. I ran into several serious issues:

  • First of all, it was slower. This could be completely my specific use, the redis-store library, or redis itself. I'm not going to do anything wrong, and your mileage may vary, but it suck to dump a lot of time, going to redis when memcached "just works."
  • Memcached is good because it is very easy to add servers and use consistent hashing to achieve your goals. Redis also has this, but in my experience it was difficult to simultaneously consider redis as a monolithic data warehouse in some parts of my application, and in other parts consider it as distributed, sequentially hashed drops of caching.

Good luck with your project. I adore redis AND memcached and use them in all my projects, but I let him do it as a kick-ass data structure server and let another remove his ass while caching.

+37
Dec 03 '10 at 3:43
source share

The pure parts of Redis include list-based caching of things β€” clicking / saying things from this list as they happen in your application.

Instead of de-serializing a lot of value from memcached, editing and then re-serializing.

This will be done in the ruby ​​code in the user filter, as well as in the underlying cache.

+2
Sep 22 '13 at 22:13
source share



All Articles