zoukankan      html  css  js  c++  java
  • redis 缓存技术与memcache的区别

    1 什么是redis
    
    redis是一个key-value存储系统。和Memcached类似,它支持存储的value类型相对更多,包括string(字符串)、list(链表)、set(集合)和zset(有序集合)。这些数据类型都支持push/pop、add/remove及取交集并集和差集及更丰富的操作,而且这些操作都是原子性的。在此基础上,redis支持各种不同方式的排序。与memcached一样,为了保证效率,数据都是缓存在内存中。区别的是redis会周期性的把更新的数据写入磁盘或者把修改操作写入追加的记录文件,并且在此基础上实现了master-slave(主从)同步。
    
    下面对应的资料,是来自redis作者的说法(stackoverflow上面)。
    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).
    
        有网友翻译如下[1]:
    
        没有必要过多的关注性能。由于Redis只使用单核,而Memcached可以使用多核,所以在比较上,平均每一个核上Redis在存储小数据时比Memcached性能更高。而在100k以上的数据中,Memcached性能要高于Redis,虽然Redis最近也在存储大数据的性能上进行优化,但是比起Memcached,还是稍有逊色。说了这么多,结论是,无论你使用哪一个,每秒处理请求的次数都不会成为瓶颈。
    
        你需要关注内存使用率。对于key-value这样简单的数据储存,memcache的内存使用率更高。如果采用hash结构,redis的内存使用率会更高。当然,这些都依赖于具体的应用场景。
    
        你需要关注关注数据持久化和主从复制时,只有redis拥有这两个特性。如果你的目标是构建一个缓存在升级或者重启后之前的数据不会丢失的话,那也只能选择redis。
    
        你应该关心你需要的操作。redis支持很多复杂的操作,甚至只考虑内存的使用情况,在一个单一操作里你常常可以做很多,而不需要将数据读取到客户端中(这样会需要很多的IO操作)。这些复杂的操作基本上和纯GET和POST操作一样快,所以你不只是需要GET/SET而是更多的操作时,redis会起很大的作用。
    
        对于两者的选择还是要看具体的应用场景,如果需要缓存的数据只是key-value这样简单的结构时,我在项目里还是采用memcache,它也足够的稳定可靠。如果涉及到存储,排序等一系列复杂的操作时,毫无疑问选择redis。
    
    2 性能怎么样 
    
    Redis是一个高性能的key-value内存数据库。官方性能测试结果: set操作每秒110000次,get操作每秒81000次。 
    
    3 可不可以存对象 
    
    和Memcached类似,它支持存储的value类型相对更多,包括string(字符串)、list(链表)、set(集合)和zset(有序集合)。这些数据类型都支持push/pop、add/remove及取交集并集和差集及更丰富的操作。 
    
    4 Redis与memcache的最大区别
       存储方式:
        memecache 把数据全部存在内存之中,断电后会挂掉,数据不能超过内存大小
        redis有部份存在硬盘上,这样能保证数据的持久性,支持数据的持久化(笔者注:有快照和AOF日志两种持久化方式,在实际应用的时候,要特别注意配置文件快照参数,要不就很有可能服务器频繁满载做dump)。
        数据支持类型:
        redis在数据支持上要比memecache多的多。(String、Lists、Sorted Sets、Hashes) persistence (snapshot、aof)
        使用底层模型不同:
        新版本的redis直接自己构建了VM 机制 ,因为一般的系统调用系统函数的话,会浪费一定的时间去移动和请求。
        Libevent和Memcached不同:
        Redis并没有选择libevent。Libevent为了迎合通用性造成代码庞大(目前Redis代码还不到libevent的1/3)及牺牲了在特定平台的不少性能。Redis用libevent中两个文件修改实现了自己的epoll event loop(4)。业界不少开发者也建议Redis
    

      此文来自:http://blog.csdn.net/sunmenggmail/article/details/36176029,http://www.tuicool.com/articles/MnqAji

  • 相关阅读:
    Nginx之负载均衡配置(二)
    Nginx之负载均衡配置(一)
    Nginx之反向代理配置(二)
    Nginx之反向代理配置(一)
    Nginx之常用基本配置(三)
    Nginx之常用基本配置(二)
    Nginx之常用基本配置(一)
    Linux系统WEB服务之Nginx基础入门
    Linux系统之LVS+Keepalived实现
    Linux系统之网络文件共享与数据实时同步实践
  • 原文地址:https://www.cnblogs.com/cqmy/p/6201607.html
Copyright © 2011-2022 走看看