I have seen several sites with large rails that use both memcached and redis. Memcached is used to emphemeral things that are pleasant to store in memory, but can be lost / regenerated, if necessary, and reused for permanent storage. Both are used to unload the main db for heavy read / write operations.
More details:
memcached: used to cache pages / snippets / responses, and itβs normal to hit the memory limit on memcached because it will be LRU (recently used) to obsolete old stuff and is often used to access hotkeys. It is important that something in memcached can be recreated from the database if necessary (this is not your only copy). But you can continue to throw things into it, and memcached will appear, which are used most often and store them in memory. You do not need to worry about removing things from memcached.
redis: you use this for data that you do not want to lose, and are small enough to fit into memory. Typically, these are resque / sidekiq tasks, counters for speed limits, test separation results, or something you would not like to lose / recreate. You don't want to exceed the memory limit here, so you need to be a little more careful about what you store and clean later.
Redis begins to experience performance problems if it exceeds the memory limit (correct me if I am wrong). This can be resolved by configuring redis to act as memcached and LRU so that it does not go to the limit of memory. But you do not want to do this with everything that you keep in redis, for example, with the help of rezki. So instead, people often use the default Rails.cache to use memcached (using dalli pearls). And then they save a separate global variable $ redis = ... for performing redis operations.
# in config/application.rb config.cache_store = :dalli_store
Maybe there is an easy way to do it all in redis - perhaps having two separate instances of redis, one with an LRU hard drive limit similar to memcache, and the other for permanent storage? I have not seen this used, but I assume that it is doable.
Brian Armstrong Sep 21 '12 at 8:40 2012-09-21 08:40
source share