关于redis与memcached区别(转载自stackoverflow)

转载自:http://stackoverflow.com/questions/10558465/memcached-vs-redis

Updated 10/9/2014

Today marks the day that memcached no longer has any significant advantages over redis, while redis continues to have many distinct advantages over memcached. Today, redis 3.0, which includes Redis Cluster, entered the Release Candidate stage. Previously when looking at memcached vs redis you might have been inclined to choose memcached due to the 3rd party clustering tools available. Now redis offers clustering, and unlike memcached support is provided out-of-the-box. Being built-in provides a more robust solution that is easier to administrate. Combined with other high availability tools in-the-box like replication and Sentinel (monitoring), redis clearly has the more compelling scaling story today.

As of today every major feature and strength memcached offers are now a subset of redis‘ features and strengths. Any use case you might use memcached for redis can solve equally well. They are both lightning fast as volatile caches. While that‘s all that memcached is its only the tip of the redis iceberg.

Memcached is a volatile in-memory key/value store. Redis can act like one (and do that job as well as memcached), but it is a data structure server.

The Redis Superset

Here are a few of the features that redis offers which memcached doesn‘t and allows redis to be used as a "real" data store instead of just a cache.

  • Powerful data types and powerful commands to leverage them. Hashes, Sorted Sets, Lists, and more.
  • Persistence to disk, by default.
  • Transactions with optimistic locking (WATCH/MULTI/EXEC)
  • Pub/sub. Extremely fast.
  • Values up to 512MB in size (memcached limited to 1MB per key)
  • Lua scripting (as of 2.6)
  • Built in clustering (as of 3.0)
  • Extremely fast at everything. Benchmarks are often conflicting, but this much is clear: when used like memcached Redis falls somewhere between nearly as fast or maybe even a little faster. Like memcached it is often bound by available network or memory bandwidth instead of CPU or other bottlenecks and will rarely be the culprit when your app is slowing down.

The powerful data types are particularly important. They allow redis to provide a fantastic shared queue (lists), a great messaging solution (pub/sub), a good place for storing sessions (hashes), and a compelling place for high score tracking (sorted sets). These are just a few examples that scratch the surface.

Conclusion

To answer your original question: The performance and memory usage of Redis compared to memcached should be relatively similar. Close enough that for most uses any performance difference in either direction is academic as neither is likely to be the bottleneck.

Unless you already have a large investment in memcached, going forward redis is the obvious solution. For solutions both tools would solve, go with the one that offers more flexibility for new use cases and also provides better out-of-the-box availability, scalability, and administration: redis.

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。