I am working on a caching strategy for our application, which uses both Redis and Memcached.
We generate fairly long JSON strings of cached data, calculated from our SQL database. Since the cached data is disposable, I’d like to use Memcached so it’ll evict keys that we don’t need anymore.
The problem is that one collection (say, Users), can be accessed from different parameters. In Redis I’d use a Hash, so I could access keys (hget) in that hash for each representation of the collection and still be able to expire all the keys with one command (del). However, I can’t find a way to evict old keys to a given DB size like Memcached would do.
So my question is either:
- How can I set Redis so it keeps a maximum DB size and evicts keys as needed?, or
- How can I model Redis hashes in Memcached, so I can expire a group of keys easily?
To configure Redis so it has a memcached-like cache behavior, you need to update the configuration file as follows:
You should get the behavior you want.