什么时候使用Redis,什么时候使用memcache,下面是redis作者的说法
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).
精炼结果
-
Redis只使用单核,而Memcached可以使用多核
- 平均到每一个核上,Redis存储小数据时比Memcached性能要高
- 但是在100k以上的数据中,Memcached性能高于Redis
-
对于Key-Value这样简单的数据储存,Memcached的内存使用率更高
- 如果采用hash结构,Redis的内存使用率更高
-
Redis的特殊优势:数据持久化(RDB和AOF)和主从复制(如哨兵模式),Memcached没有
-
如果需要缓存的数据只是key-value这样简单的结构时,采用Memcached,但是如果需要涉及到存储和排序等复杂的操作时,选择Redis
Redis和Memcached的不同点
-
存储方式
- memcache将数据全部存在内存中,断电就会挂掉,数据不能超过内存大小
- redis会使用RDB/AOF将部分数据存在硬盘上,可以保证数据的持久化
-
数据支持类型
- redis在数据类型上比memcache多(String、List、Set、Hash、Zset、Geo、hyperloglog、bitmap…)