Turn: Redis and Memcache difference, comparative advantages and disadvantages

Primer: https://www.cnblogs.com/JavaBlackHole/p/7726195.html

1, Redis Memcache and the data are stored in memory, all memory database. But it can also be used to cache memcache other things, such as pictures, videos and so on. 
2, Redis only support simple k / v types of data, while also providing a storage list, set, hash and other data structures. 
3, the virtual memory -Redis when the physical memory is used up, move some long useless to the value swapped to disk 
4, the expiration policy -memcache the designation in the set, for example, set key1 0 0 8, ie never expire. Redis expire setting by, for example, name 10 e.g. expire 
. 5, distributed - memcache cluster set, using a magent made from multi-master; Redis can be done from a multi-master. Can be a master-slave 
6, after the data storage security -memcache hang up, not the data; redis can be saved to disk periodically (persistent) 
7, disaster recovery -memcache hang up after the data unrecoverable; after data loss can redis recovery by aof 
8, Redis supports the backup data, i.e., data backup master-slave mode.

About different memcache and redis, the following lists some relevant argument for record:

and in that memecache different redis [2]: 
1, storage: 
memecache all the data present in the memory, will hang power failure, data can not exceed the memory size 
redis portions have on the hard disk, this will ensure that persistent data persistence of and support data (author note: there are two kinds of snapshots and logs AOF persistent way, when in actual use, paying particular attention to the profile snapshot parameters, or on the server is likely to make frequent full load dump). 
2, data types supported: 
Redis memecache much more than on the data support. 
3, using different underlying model: 
the new version of redis directly own built VM mechanism, because most of the system call system function, it will waste some time to move and requests. 
4, different operating environment: 
Redis currently only supports LINUX official line up, thus eliminating the need for support for other systems, so you can better used to focus on the optimization of the system environment, although there is a group for which Microsoft later He wrote a patch. But not put on the trunk

Personal sum up, there is persistent demand or data structures and processes have advanced application requirements, selection redis, other simple key / value store, select memcache.

Memcached and Redis focuses on the following two options: 
Memcached introduce 
Memcached is a high-performance, distributed memory object caching system, used for dynamic Web applications to alleviating database load. By reducing it to cache data in memory and the number read from the database objects to provide a dynamic, speed of the database-driven websites, it is now being used LiveJournal, hatena, Facebook, Vox, LiveJournal and other companies.

Memcached works analyze 
many Web applications will save the data to RDBMS, application server and data read from the display in the browser. But with the increasing amount of data, centralized access, there will be a heavier burden RDBMS database in response to the deterioration of the site show a significant impact on delay. Memcached is a high-performance, distributed memory cache server, caching database query results by reducing the number of database access, to improve the speed of dynamic Web applications, improve scalability. The following figure shows the cooperative work memcache database side: 
Write pictures described here 
wherein the process is as follows: 
Data 1. Check the user requesting whether there exists in the cache, if present, only direct the data request is returned, without having to query the database . 
2. If the requested data is not found in the cache, this time to go to query the database. At the same time return the requested data, the data stored in the cache copy. 
3. (such as the case of the data has been modified, or deleted) "freshness", whenever the data changes to keep the cache, the cache synchronization information to be updated to ensure that users do not get to the cache of old data.

Memcached cache server as a distributed high-speed operation, has the following features: 
1. Simple protocol 
2. The event processing based libevent 
3. The internal memory storage 
distributed 4.memcached not communicate with each other

How to implement distributed scalability? 
Memcached distributed is not implemented on the server side, but implemented in the client application, i.e., the development of target nodes through the built-in algorithms of data, as shown below: 
Write pictures described here

Redis 介绍 
Redis是一个key-value存储系统。和Memcached类似,它支持存储的value类型相对更多,包括string(字符串)、 list(链表)、set(集合)和zset(有序集合)。这些数据类型都支持push/pop、add/remove及取交集并集和差集及更丰富的操作,而且这些操作都是原子性的。在此基础上,redis支持各种不同方式的排序。与memcached一样,为了保证效率,数据都是缓存在内存中。区别的是redis会周期性的把更新的数据写入磁盘或者把修改操作写入追加的记录文件,并且在此基础上实现了master-slave(主从)同步,当前 Redis的应用已经非常广泛,国内像新浪、淘宝,国外像 Flickr、Github等均在使用Redis的缓存服务。

Redis 工作方式分析 
Redis作为一个高性能的key-value数据库具有以下特征: 
1.多样的数据模型 
2.持久化 
3.主从同步 
Redis支持丰富的数据类型,最为常用的数据类型主要由五种:String、Hash、List、Set和Sorted Set。Redis通常将数据存储于内存中,或被配置为使用虚拟内存。Redis有一个很重要的特点就是它可以实现持久化数据,通过两种方式可以实现数据持久化:使用RDB快照的方式,将内存中的数据不断写入磁盘;或使用类似MySQL的AOF日志方式,记录每次更新的日志。前者性能较高,但是可能会引起一定程度的数据丢失;后者相反。 Redis支持将数据同步到多台从数据库上,这种特性对提高读取性能非常有益。

Redis如何实现分布式可拓展性? 
2.8以前的版本:与Memcached一致,可以在客户端实现,也可以使用代理,twitter已开发出用于Redis和Memcached的代理Twemproxy 。 
3.0 以后的版本:相较于Memcached只能采用客户端实现分布式存储,Redis则在服务器端构建分布式存储。Redis Cluster是一个实现了分布式且允许单点故障的Redis高级版本,它没有中心节点,各个节点地位一致,具有线性可伸缩的功能。如图给出Redis Cluster的分布式存储架构,其中节点与节点之间通过二进制协议进行通信,节点与客户端之间通过ascii协议进行通信。在数据的放置策略上,Redis Cluster将整个 key的数值域分成16384个哈希槽,每个节点上可以存储一个或多个哈希槽,也就是说当前Redis Cluster支持的最大节点数就是16384。 
Write pictures described here

综合结论

应该说Memcached和Redis都能很好的满足解决我们的问题,它们性能都很高,总的来说,可以把Redis理解为是对Memcached的拓展,是更加重量级的实现,提供了更多更强大的功能。具体来说:

1.性能上: 
性能上都很出色,具体到细节,由于Redis只使用单核,而Memcached可以使用多核,所以平均每一个核上Redis在存储小数据时比 
Memcached性能更高。而在100k以上的数据中,Memcached性能要高于Redis,虽然Redis最近也在存储大数据的性能上进行优化,但是比起 Memcached,还是稍有逊色。

2.内存空间和数据量大小: 
MemCached可以修改最大内存,采用LRU算法。Redis增加了VM的特性,突破了物理内存的限制。

3. The operation of the handy: 
single MemCached data structure for the data cache only, and Redis support richer data type, the data may be rich operation is directly on the server side, thus reducing the volume of the data network and the number of IO.

4. Reliability: 
MemCached does not support data persistence, disappearance of data after power off or restart, but the stability is guaranteed. Redis supports data persistence and data recovery, allows a single point of failure, but will also pay for performance.

5. Application scenarios: 
Memcached: a dynamic system to reduce the database load, improve performance; as cache for read more write less, a large amount of data situation (such as a large number of inquiries for all network user information, friend information, articles, information, etc.). 
Redis: suitable are high, and data processing services to the complex system with high security requirements (e.g. Xinlang micro-Bo counting and reading and writing efficiency requirements of the system, data security, are required to read and write high).

Part needs careful consideration 
1.Memcached single key-value size is limited, only support a maximum value 1MB, and the maximum support Redis 512MB 
2.Memcached only a memory cache, no requirement for reliability; Redis prefer the memory database, pairs of relatively high reliability 
3. essentially, the Memcached just a single key-value the cache memory; Redis the data structure is a database memory, supports five data types, so in addition to the simple cache Redis effect, further can handle some simple logic operations, not only Redis cache, but also as a database 
4. the new version (3.0) in a distributed cluster Redis means, i.e. the cluster balancing client requests itself, each node can communicate, be expand the line, maintainability stronger.

Guess you like

Origin www.cnblogs.com/x-jingxin/p/11431307.html