So a friend of mine asked in twitter if he should use redis for caching instead of memcached, when i told, that i'm using redis for caching couchdb views.
I can't answer it benchmark-wise, but i suspect memcached would be faster for simple key-value cache.
But, there's cases where memcached is not enough.
Here they are:
- memcached does not have a simple way to list keys, redis, on the other hand have a KEYS command, which supports wildcards. This come in handy when you need to purge cache, but you don't know exact keys, just mask. For example: you have mappings like user:<email>:login => <login> and user:<email>:display_name, user changes password and you need to purge both keys. This is simple example, but redis sure comes in handy, when keys created from many parameters, and, when you need to purge 'em you don't know all the parameters, just a one.
- cache persistence over daemon/server restart. This guaranties that you application won't work with empty cache and lifts load from server.
- with redis you can perform simple atomic operations on values, like increment/decrement (for example: comments counter for blogpost, etc). Yes, you can do it in memcached too, but that's not all. Due to Lua scripts support you can move all cache managing logic to cache. E.g. create lua function purge_email(email) which will delete all keys containing this email, etc.
- and last, but not least: redis is NoSQL storage, so you can use it not only for cache, but for some data too. With sharding and replication out of the box.