Summary of differences between Redis and Memcache

The cluster:

Redis and memcached both support clustering

The data type

Redis not only supports simple K/V type data, but also provides the storage of String, List,Set,Hash,Sorted Set,pub/sub and Transactions data structures. Where Set is implemented by HashMap and value is always null

Memcache supports simple data types, requiring clients to handle complex k/ V objects themselves

persistence

Redis supports data landing persistent storage, which can keep the data in the memory in the disk and can be loaded again for use upon restart.

Memcache does not support data persistence

Distributed storage

Redis supports master-slave replication

Memcache can use consistent hashes for distribution

Different value sizes

Memcache is a memory cache. The key length is less than 250 characters ** and each item store is less than 1 MB **. Memcache is not suitable for VMS

Different data consistency

Redis uses only one core, while Memcached can use multiple cores, so Redis performs better than Memcached on average for storing small data on each core. For data over 100K, Memcached outperforms Redis, which has recently been optimized for storing large data, but still lags behind Memcached.

Redis uses a single-threaded model to ensure that data is submitted sequentially.

Memcache requires cas to ensure data consistency. Check and Set (CAS) is a mechanism to ensure concurrent consistency and belongs to the category of optimistic locking. The principle is simple: take the version number, do the operation, compare the version number, if the same operation, do not do anything

CPU utilization

The Redis single-threaded model can only use one CPU, and multiple Redis processes can be started

(1) What is Redis? / function points/advantages/disadvantages

Memory-based high performance database/pure memory operation with excellent performance/can handle more than 100,000 read/write operations per second /

Multiple data structures are supported. A maximum of 1GB/ value is supported

Memory database/Received physical memory limit/Cannot perform high-performance read/write for massive data

(2) Supported data types

Redis is distinguished by the different single-value types of key-value. The following types are supported: Sorted (using HashMap and SkipList, sort by score in HashMap) hashes

(3) Why does Redis need to put all data in memory?

Redis reads data to memory for the fastest read/write speed and writes data to disk asynchronously. So Redis is characterized by fast and persistent data. If data is not kept in memory, disk I/O speed severely affects Redis performance. As memory gets cheaper and cheaper, Redis will become more and more popular. If the maximum memory usage is set, new values cannot be inserted after the number of existing records reaches the memory limit.

(4) Redis is single-process single-thread

Redis uses queue technology to turn concurrent access into serial access, eliminating the overhead of traditional database serial control

(5) Virtual memory

Using a VM works better when your key is small and your value is large. Because it saves a lot of memory. When your key is small, you can use some unusual methods to turn large keys into large values. For example, you can consider combining key and value into a new value. The vM-max-threads parameter is used to set the number of threads that can access the swap file. The value should not exceed the number of cores on the machine. If set to 0, all operations on the swap file will be serial. There may be long delays, but data integrity is well guaranteed.

In my own tests, VIRTUAL memory also performed well. If you have a large amount of data, consider a distributed or other database

(6) Distributed

Redis supports a master-slave mode. Principle: The Master synchronizes data to the slave, but the slave does not synchronize data to the Master. The Slave starts up with the master to synchronize data.

This is a typical distributed read-write separation model. We can use master to insert data, slave to provide retrieval services. This effectively reduces the number of concurrent accesses to a single machine

(7) Read/write separation model

By increasing the number of Slave DBS, the read performance increases linearly. To avoid a single point of failure of the Master DB, two Master DBS are deployed in the cluster in dual-system hot backup mode, ensuring high read and write availability in the entire cluster. The disadvantage of read/Write separation architecture is that each node, whether Master or Slave, must store complete data. In case of a large amount of data, the expansion capability of the cluster is limited by the storage capacity of a single node. Moreover, for write-intensive applications, read/Write separation architecture is not suitable.