Redis和Memcache的区别分析

  1. Redis中,并非全部的数据都一直存储在内存中的,这是和Memcached相比一个最大的区别。redis

  2. Redis不只仅支持简单的k/v类型的数据,同时还提供list,set,hash等数据结构的存储。数据库

  3. Redis支持数据的备份,即master-slave模式的数据备份。缓存

  4. Redis支持数据的持久化,能够将内存中的数据保持在磁盘中,重启的时候能够再次加载进行使用。安全

Redis在不少方面具有数据库的特征,或者说就是一个数据库系统,而Memcached只是简单的K/V缓存网络

来看下Redis做者对比redis和memcache数据结构

来源:《Is memcached a dinosaur in comparison to Redis?》(相比Redis,Memcached真的过期了吗?)分布式

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.ide

没 有必要过多的关心性能,由于两者的性能都已经足够高了。因为Redis只使用单核,而Memcached可使用多核,因此在比较上,平均每个核上 Redis在存储小数据时Memcached性能更高。而在100k以上的数据中,Memcached性能要高于Redis,虽然Redis最近也在存储 大数据的性能上进行优化,可是比起Memcached,仍是稍有逊色。说了这么多,结论是,不管你使用哪个,每秒处理请求的次数都不会成为瓶颈。(好比 瓶颈可能会在网卡)memcached

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.性能

若是要说内存使用效率,使用简单的key-value存储的话,Memcached的内存利用率更高,而若是Redis采用hash结构来作key-value存储,因为其组合式的压缩,其内存利用率会高于Memcached。固然,这和你的应用场景和数据特性有关。

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.

若是你对数据持久化和数据同步有所要求,那么推荐你选择Redis,由于这两个特性Memcached都不具有。即便你只是但愿在升级或者重启系统后缓存数据不会丢失,选择Redis也是明智的。

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来讲,拥有更多的数据结构和并支持更丰富的数据操做,一般在Memcached里, 你须要将数据拿到客户端来进行相似的修改再set回去。这大大增长了网络IO的次数和数据体积。在Redis中,这些复杂的操做一般和通常的 GET/SET同样高效。因此,若是你须要缓存可以支持更复杂的结构和操做,那么Redis会是不错的选择。

一、 Redis和Memcache都是将数据存放在内存中,都是内存数据库。不过memcache还可用于缓存其余东西,例如图片、视频等等。二、Redis不只仅支持简单的k/v类型的数据,同时还提供list,set,hash等数据结构的存储。三、虚拟内存--Redis当物理内存用完时,能够将一些好久没用到的value 交换到磁盘四、过时策略--memcache在set时就指定,例如set key1 0 0 8,即永不过时。Redis能够经过例如expire 设定,例如expire name 10五、分布式--设定memcache集群,利用magent作一主多从;redis能够作一主多从。均可以一主一从六、存储数据安全--memcache挂掉后,数据没了;redis能够按期保存到磁盘(持久化)七、灾难恢复--memcache挂掉后,数据不可恢复; redis数据丢失后能够经过aof恢复八、Redis支持数据的备份,即master-slave模式的数据备份

相关文章
相关标签/搜索