Difference between memcache and Redis

Data structure: memcache only supports simple key-value form, Redis supports more data (string string, set collection, list list, hash hash, zset ordered collection);

Multithreading: memcache supports multithreading, Redis supports single threading
Persistence: Redis supports persistence, memcache does not support persistence
Distributed: Redis is the master-slave structure, and the memcache server needs to support the master-slave structure through hash consistency

In actual application, redis and memcache can be combined. Memcache can be used as a way of session storage. Sessions are all KV type key-value pairs.

In Redis, not all data is always stored in memory, which is the biggest difference compared to Memcache.

Redis has database characteristics in many aspects, or is a database system, while Memcache is just a simple K/V cache.

Their expansion needs to be clustered; implementation methods: master-slave, Hash.

In data above 100k, Memcache performance is higher than Redis.

If you want to talk about memory usage efficiency, if you use simple key-value storage, Memcached’s memory utilization is higher, and if Redis uses hash structure for key-value storage, due to its combined compression, its memory utilization will be high. on Memcache. Of course, this is related to your application scenario and data characteristics.

If you have requirements for data persistence and data synchronization, it is recommended that you choose Redis, because Memcache does not have these two features. Even if you just want cache data not to be lost after an upgrade or reboot, choosing Redis is wise.

Redis and Memcache have little difference in write performance. Memcache is stronger in read performance, especially in batch read performance.

Redis provides several different levels of persistence:

RDB persistence can generate point-in-time snapshots of datasets at specified time intervals.
AOF persistently records all write commands performed by the server and restores the dataset by re-executing these commands when the server starts. The commands in the AOF file are all saved in the Redis protocol format, and new commands will be appended to the end of the file. Redis can also rewrite AOF files in the background, so that the size of the AOF file does not exceed the actual size required to save the state of the dataset.
Redis can also use both AOF persistence and RDB persistence. In this case, when Redis restarts, it will use the AOF file to restore the dataset in preference, because the AOF file usually saves a more complete dataset than the RDB file.
You can even turn off persistence so that the data only exists while the server is running.

en_USEnglish