Redis Learning (i)

Source: Internet
Author: User

Memcache and Redis are required for project requirements. The main differences between Redis and Memcache are as follows:

1,memcache and Redis are both memory databases that can be used to make K-V databases. But Redis also provides list, hash, set, etc., supported by the rich data types. This is why Sina has selected Redis for various types of support.

But memcache can also be used to cache other things, examples, videos, and so on. (Redis does not support?) )

2,redis supports data persistence, two-way snapshots, AOF, and support for Master-slave data backup. Memcache not support, hang up the data will be gone. Redis takes care to configure the parameters of the snapshot to avoid disk full.

3,redis supports virtual memory, the new version uses the VM mechanism, and when physical memory runs out, you can swap some long-unused value to disk. Memcache cannot exceed memory.

4, are high-performance distributed systems.

5, for data, memcache setting is never expired ... (without understanding what this setting is), Redis can set the expiration time.

Below from Http://blog.163.com/weiwenjuan_bj/blog/static/14035033620135185150979/?latestBlog

From the following several dimensions, the Redis, Memcache, MongoDB made a comparison, welcome to shoot Bricks

1. Performance

are relatively high, performance is not a bottleneck for us

In general, the TPS is about the same as Redis and Memcache, more than MongoDB

2, the convenience of the operation

Memcache Data Structure Single

Redis is rich, data manipulation, Redis better, less network IO times

MongoDB supports rich data expression, index, most similar relational database, support 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; You can set the expiration time for key value (similar to memcache)

Memcache can modify the maximum available memory, using the LRU algorithm

MongoDB is suitable for large data storage, depends on operating system VM to do memory management, eat memory is also very bad, service not with other services together

4. Availability (single point of issue)

For a single point of problem,

Redis, which relies on clients for distributed reads and writes, and master-slave replication relies on the entire snapshot every time the primary node is reconnected from the node, without incremental replication, due to performance and efficiency issues,

Therefore, the single point problem is more complicated, the automatic sharding is not supported, and the dependent program is required 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 (you need to implement it yourself), consistency issues and performance tradeoffs

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

MongoDB supports Master-slave,replicaset (internal using Paxos election algorithm, automatic fault recovery), auto sharding mechanism, blocking the failover and segmentation mechanism to the client.

5. Reliability (persistent)

For data persistence and data recovery,

Redis Support (snapshot, AOF): dependent on snapshots for persistence, AOF enhances reliability while impacting performance

Memcache not supported, usually used in cache, improve performance;

MongoDB supports persistent reliability from the 1.8 release with the binlog approach

6. Data consistency (transactional support)

Memcache in concurrent scenarios, with CAS to ensure consistency

Redis transaction support is weak and can only guarantee continuous execution of each operation in a transaction

MongoDB does not support transactions

7. Data analysis

MongoDB has built-in data analysis capabilities (MapReduce), others do not support

8. Application Scenario

Redis: More performance operations and calculations with smaller data volumes

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

That's what the Redis authors say:

There is no need to pay too much attention to performance. Since Redis uses only single cores, and memcached can use multicore, on average, Redis has a higher performance than memcached for storing small data on a per-core scale. In more than 100k of data, memcached performance is higher than Redis, although Redis has recently been optimized for the performance of storing big data, but it is slightly inferior to memcached. Having said so much, the conclusion is that no matter which one you use, the number of requests per second will not be a bottleneck.

You need to focus on memory utilization. For simple data storage such as Key-value, memcache memory usage is higher. If the hash structure is used, the memory usage of Redis will be higher. Of course, these depend on the specific application scenario.

You need to focus on data persistence and master-slave replication, only Redis has these two features. If your goal is to build a slow-to-exist upgrade or reboot before the data is not lost, then you can only choose Redis.

You should be concerned about the actions you need. Redis supports a lot of complex operations, and even only consider memory usage, you can often do a lot in a single operation, without having to read the data to the client (this will require a lot of IO operations). These complex operations are basically as fast as pure get and post operations, so Redis can play a big role when you don't just need to get/set but do more.

For the choice of the two or to see the specific application scenario, if you need to cache the data is only key-value such a simple structure, I still use memcache in the project, it is also stable and reliable enough. If you are involved in a series of complex operations such as storage, sorting, and so on, Redis is no doubt chosen.

Redis Learning (i)

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.