193

I have worked quite a bit with memcached the last weeks and just found out about Redis. When I read this part of their readme, I suddenly got a warm, cozy feeling in my stomach:

Redis can be used as a memcached on steroids because is as fast as memcached but with a number of features more. Like memcached, Redis also supports setting timeouts to keys so that this key will be automatically removed when a given amount of time passes.

This sounds amazing. I'd also found this page with benchmarks: http://www.ruturaj.net/redis-memcached-tokyo-tyrant-mysql-comparison

So, honestly - Is memcache really that old dinousaur that is a bad choice from a performance perspective when compared to this newcomer called Redis?

I haven't heard lot about Redis previously, thereby the approach for my question!

8
  • Interesting additional reading: nosql.mypopescu.com/post/519078332/memcached-on-top-of-redis
    – Industrial
    May 20, 2010 at 11:37
  • 9
    this ruturaj benchmark is not really worth much attention
    – dsomnus
    Dec 2, 2010 at 22:26
  • 2
    We've started experimenting w/Membase at work, and happy so far. Though, we're coming from Memcache, so having a drop in replacement was a nice plus: membase.org
    – jayshao
    Mar 6, 2011 at 18:32
  • 2
    Redis is as fast as memcached for non-real-world contrived benchmarks. That's not to suggest it's slow -- it's certainly fast enough for most workloads, but things faster than memcached only reveal bugs in memcached. It's almost always bottlenecked by hardware or poor application design.
    – Dustin
    May 25, 2011 at 4:22
  • 4
    I'm surprised the sanctity-of-SO-patrol hasn't closed this question as not-appropriate and not-helpful.
    – Dogweather
    Dec 13, 2013 at 1:54

6 Answers 6

210

Depends on what you need, in general I think that:

  • You should not care too much about performances. Redis is faster per core with small values, but memcached is able to use multiple cores with a single executable and TCP port without help from the client. Also memcached is faster with big values in the order of 100k. Redis recently improved a lot about big values (unstable branch) but still memcached is faster in this use case. The point here is: nor one or the other will likely going to be your bottleneck for the query-per-second they can deliver.
  • You should care about memory usage. For simple key-value pairs memcached is more memory efficient. If you use Redis hashes, Redis is more memory efficient. Depends on the use case.
  • You should care about persistence and replication, two features only available in Redis. Even if your goal is to build a cache it helps that after an upgrade or a reboot your data are still there.
  • You should care about the kind of operations you need. In Redis there are a lot of complex operations, even just considering the caching use case, you often can do a lot more in a single operation, without requiring data to be processed client side (a lot of I/O is sometimes needed). This operations are often as fast as plain GET and SET. So if you don't need just GET/SET but more complex things Redis can help a lot (think at timeline caching).

Without an use case is hard to pick the right now, but I think that for a lot of things Redis makes sense since even when you don't want to use it as a DB, being a lot more capable you can solve more problems, not just caching but even messaging, ranking, and so forth.

P.s. of course I could be biased since I'm the lead developer of the Redis project.

3
  • 6
    I'm not sure if this is a language mistake, but if you lead your argument with "in general I think that you should not care too much about performance", that's serious cause for concern. Redis may be very good for certain classes of problems but, traditionally, memcache has been used specifically to solve issues of performance with persistant databases. I also think a glaring omission from your list is product maturity. Memcache is a mature product with around a decade of experience. Redis is promising, but has only been around for 3 years or so.
    – DougW
    Sep 21, 2012 at 20:56
  • 1
    @DougW You are taking this phrase out of context. It makes a lot more sense when you read the phrase closing the paragraph right after: "The point here is: nor one or the other will likely going to be your bottleneck for the query-per-second they can deliver"
    – Dinei
    Feb 6, 2017 at 0:16
  • @antirez Is the first point still valid in 2022?
    – piepi
    Feb 1, 2022 at 1:33
83

So, honestly - Is memcache really that old dinousaur that is a bad choice from a performance perspective when compared to this newcomer called Redis?

  • Comparing features set then Redis has way more functionality;
  • Comparing ease of installation Redis is also a lot easier. No dependencies required;
  • Comparing active development Redis is also better;
  • I believe memcached is a little bit faster than Redis. It does not touch the disc at all;
  • My opinion is that Redis is better product than memcached.
11
  • 31
    redis only touches disk if you tell it to. Usually, it does an fsync every other second or so -> you won't notice it Jul 14, 2010 at 8:51
  • 1
    @Marc yup. I also believe you can tell it to not touch disc at all, but standard i believe it always fsyncs right now?
    – Alfred
    Jul 14, 2010 at 9:07
  • 3
    Also, in my experience Redis is a bit faster than Memcached (when using Redis in memory-only mode). Antirez made a test here antirez.com/post/redis-memcached-benchmark.html Jan 4, 2011 at 10:52
  • 11
    BIG DIFFERENCE: Memcached is multi-threaded and Redis is not. So while the latency of a single request is comparable, Memcached can serve many more requests when concurrency is high. Redis on the other hand will reach it's performance peak with only a few concurrent requests since it only makes use of 1 cpu core/thread. The suggested method of circumventing this is to run multiple instances of Redis on one machine with consistent hashing, but this is a really poor solution. So if you need high concurrency and have multi-core CPU (who doesn't), Memcached is MUCH faster.
    – ColinM
    Mar 27, 2012 at 0:46
  • 2
    @Alfred, it is not a hidden fact that Redis is single-threaded, it is a design decision (simplicity over robustness) by the author. The article Dustin linked to above is solid evidence that it has a real impact. Also I have confirmed this in my own benchmarks using Redis as a Zend_Cache backend; as concurrency increases Redis will plateau rather quickly compared to memcached.
    – ColinM
    Apr 16, 2012 at 18:59
74

Memcache is an excellent tool still and VERY reliable.

instead of looking at this issue from the perspective getting down the who is faster at the < 100 ms range, look at the performance per "class" of the software.

  • Does it use only local ram? -> fastest
  • Does it use remote ram? -> fast
  • Does it use ram plus hardddisk -> oh hurm.
  • Does it use only harddisk -> run!
5
  • 3
    There is no facility to handle replication with memcache that I know of. Memcache is purely meant to be a cache. If the item is purged/lost, then it needs to be rebuilt. I have not used this before nor have I evaluated it, but this may be of interest to you. code.google.com/p/memagent
    – Daniel
    May 23, 2010 at 17:22
  • 1
    Membase supports the memcached protocol but also persistence and replication. May 25, 2011 at 3:37
  • 1
    Recently I saw bonded ethernet, across 4 ports. 4 x 44MB/s. This makes ram even more valuable, assuming you can get bonded ethernet going!
    – Daniel
    Jul 2, 2011 at 1:59
  • 1
    For the sake of future reference, Facebook open source'd mcrouter recently, which adds replication to memcached. Other things are also dated (redis is super fast now, etc), but FYI if you're here five years later...
    – dannysauer
    Mar 11, 2015 at 16:02
  • well whats the point? both cant store a simple json array direclty, the most WIDELY used DATA interchange format on the web, i have no idea what they were thinking...oh wait maybe i should add ReJSON because natively no one cares about JSON in the world right
    – PirateApp
    Dec 20, 2017 at 12:12
47

What memcached does that Redis doesn't do is least-recently-used eviction of values from the cache. With memcached, you can safely set as many values as you like, and when they overflow memory, the ones you haven't used recently will be deleted. With Redis, you can only approximate this, by setting a timeout on everything; when it needs to free up memory, it will look at three random keys and delete the one that's the closest to expiring.

That's the main difference, if you're just using it as a cache.

1
13

You may also want to look at Membase.

http://www.northscale.com/products/membase_server.html

I have not used it, but it appears to be similar to Redis in that it is a memory-centric KV store with persistence. The major differences from what I can see are:

  • Redis has significantly more data manipulation capability (ordered sets, etc.)
  • Redis has a pending Redis Cluster project to add horizontal scalability
  • Redis has a single tier of data offload to disk (VM) based on a hybrid algorithm that considers both LRU and the size of the object.

  • Membase uses the memcached wire protocol - useful as an upgrade path for existing applications

  • Membase is set up to scale horizontally using a distributed hashtable approach
  • Membase can support multiple tiers of data offload using an LRU approach (very seldom used goes to disk, somewhat seldom stuff goes to SSD, frequent stuff stays in RAM)
  • Not sure about TTL capability in Membase.

The choice may depend on the degree to which your application can leverage the extra data manipulation functionality in Redis.

3
0

Hazelcast supports the memcached protocol natively

https://web.archive.org/web/20140601010929/http://hazelcast.org/docs/latest/manual/html-single/hazelcast-documentation.html

and thus is a modern alternative to memcached. You should try all the solutions to see what works best for you.

Not the answer you're looking for? Browse other questions tagged or ask your own question.