开发者

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

Is there a common api such that if I switch between Redis or Memcached I don't h开发者_StackOverflow社区ave to change my code, just a config setting?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜