Redis vs. memcached

Source: Internet
Author: User
Tags memcached mongodb support

Redis is an advanced Key-value database. It is similar to memcached, but the data can be persisted, and the supported data types are rich, with strings, lists, collections, and ordered collections. Supports the calculation of the aggregation of the set on the server side, and the intersection and complement sets. Multiple sorting functions are also supported. So Redis can also be viewed as a data structure server.

All redis data is stored in memory and then occasionally saved to disk asynchronously (semi-persistent mode), and each data change can be written to a append only file (AOF) (full persistence mode).

in Redis, not all data is stored in memory all the time. This is one of the biggest differences compared to memcached . Redis will only cache all key information, and if Redis finds that memory usage exceeds a certain threshold, it will trigger swap operations, Redis according to "swappability = Age*log (size_in_memory)" Calculates which key corresponds to the value that requires swap to disk. The value corresponding to these keys is then persisted to disk and purged in memory. This feature allows Redis to maintain data that is larger than the memory size of its machine itself. Of course, the memory of the machine itself must be able to maintain all the keys, after all, the data will not be swap operations. Also, since Redis swaps the in-memory data to disk, the main thread that provides the service and the sub-thread that is doing the swap will share this memory, so if you update the data that needs swap, REDIS will block the operation until the sub-thread completes the swap operation before it can be modified.

Redis, Memcache, mongodb contrast

1. Performance:

are relatively high, performance should not be a bottleneck for us. In general, the TPS is similar to Redis and Memcache, more than MongoDB;

2, the convenience of operation:

Memcache data Structure single (key-value); Redis is rich, data manipulation, Redis better, less network IO times, but also provides data structures such as list,set,hash storage; MongoDB supports rich data representation, indexing, The most similar relational database, the supported query language is very rich.

3. Size of memory space and amount of data

Redis has added its own VM features after the 2.0 release, breaking the limits of physical memory, and setting an expiration time for key value (similar to memcache);
Memcache can modify the maximum available memory, using the LRU algorithm. Memcached agent software magent, such as the establishment of 10 sets of 4G Memcache cluster, the equivalent of 40g;mongodb suitable for large data storage, relying on operating system VMS do memory management, eating memory is also more severe, services do not and other services together.

4. Availability (single point of issue)

Redis relies on the client to implement distributed read and write, master-slave replication, every time from the node reconnect to the main node to rely on the entire snapshot, no incremental replication, because of performance and efficiency problems, so the single point of the problem is more complex, does not support automatic sharding, need to rely on programs to set the consistent hash mechanism. An alternative is to use your own proactive replication (multiple storage) instead of Redis's own replication mechanism, or change to incremental replication (need to implement it yourself), consistency issues and performance tradeoffs;

Memcache itself has no data redundancy mechanism, it is not necessary, for fault prevention, the use of mature hash or ring algorithm, to solve the single point of failure caused by the jitter problem;

MongoDB Support Master-slave,replicaset (internal use of Paxos election algorithm, automatic fault recovery), auto sharding mechanism, the client shielded the failover and segmentation mechanism;

5. Reliability (persistent)

For data persistence and data recovery: Redis support (snapshot, AOF), snapshot-dependent persistence, AOF enhanced reliability, and performance impact
Memcache not supported, usually used in cache, improve performance;
MongoDB has been using Binlog mode to support the reliability of persistence since the 1.8 release.

6. Data consistency (transactional support)

Redis transaction support is weaker and can only guarantee that each operation in a transaction executes continuously;

Memcache in concurrent scenarios, with CAs to ensure consistency;

MongoDB does not support transactions;

7. Data analysis

MongoDB built-in data analysis features (map-reduce), others do not support

8. Application Scenario

Redis: Operations and operations with a small amount of data;
Memcache: Used to reduce database load in dynamic system, improve performance, cache, improve performance (suitable for read and write less, for a large amount of data, you can use sharding)
MongoDB: The main solution to the massive data access efficiency problem.

Compared to memcached:

1. Redis has a persistence mechanism that can periodically persist the data in memory to the hard disk.

2, Redis has the Binlog function, can write all operations to the log, when the Redis failure, can follow the Binlog data recovery.

3, Redis support virtual memory, can limit the size of RAM, when the data exceeds the threshold, the most infrequently used data in memory is saved to the paging file of the hard disk by an algorithm like LRU.

4. Redis native supports more data types and uses more space for imagination.

5, a friend mentioned in front of a consistent hash, used in Redis sharding, generally in the load is very high need to expand the level of use. We have not used this aspect of the function, the general project, stand alone enough to support the concurrency. Redis 3.0 will launch cluster, which is more powerful.

Redis vs. memcached

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.