9

I currently use Redis as a work queue for Sidekiq. I'm interested in also using it as a caching mechanism for Rails.cache.

The recommended Rails caching mechanism never expires items and relies on evicting the least recently used (LRU) item. Unfortunately, Redis by default isn't configured to evict the least recently used item while the recommended cache store, memcached, is.

Furthermore, evicting items isn't a behavior I would want for my work queue, and configuring the same Redis instance to do this could lead to undesirable results. Nor would I want my queue to share cycles with my cache anyways.

What would you all recommend in this situation? A second redis store to act as a cache and have LRU configured? Or just use the rails recommended memcached cache store and only use redis alone to be a queue?

I'm leaning towards using both Redis and Memcached, despite plenty of stack overflow articles recommending otherwise. memcached supporting LRU eviction by default is what wins me over.

Some articles:

Hidden deeper in the comments, posters mention that memcached's LRU eviction as a great reason to use it as a cache.

Community
  • 1
  • 1
dimroc
  • 1,215
  • 1
  • 15
  • 25

2 Answers2

2

Ended up using both redis and memcached. Pretty happy with the results.

dimroc
  • 1,215
  • 1
  • 15
  • 25
1

Main difference is that Memcached can run in parallel cores/machines but Redis is so lightweight and fast that it takes a good amount of load to get to its limit if it's running on a decent machine, where it only uses a couple cores, well since it works to use both for you that's great, but it sounds like a bit unnecessary complexity to use both, that's all. (ie if you need contractors to work on it etc you'll need someone with experience in both technologies rather than just one)

serdarsenay
  • 2,363
  • 19
  • 21
  • You need two separate deployments regardless of whether or not you go all redis or use both memcached and redis. You don't want your caching to affect your queue and vice versa. Seeing as how memcached works out of the box for LRU caching while redis doesn't, I believe it's simpler to use the two different technologies. I haven't had any maintenance trouble going between the two, but perhaps I'm not yet at the scale where it matters. – dimroc Jun 01 '15 at 21:03