Differences and usage scenarios between redis and memcached

When it comes to caching technology, developers with certain experience will definitely think of the two caching technologies redis and memcached. Let's talk about the differences and usage scenarios of these two caching technologies.

the difference

1. Both Redis and Memcache store data in memory, both of which are in-memory databases. However, memcache can also be used to cache other things, such as pictures, videos, etc.;

2. Redis not only supports simple k/v type data, but also provides storage of data structures such as list, set, and hash;

3. Virtual memory – When Redis runs out of physical memory, it can exchange some values ​​that have not been used for a long time to disk;

4. Expiration policy – ​​memcache is specified when set, such as set key1 0 0 8, that is, it will never expire. Redis can be set by, for example, expire, such as expire name 10;

5. Distributed – set up a memcache cluster and use magent to be one master and multiple slaves; redis can be one master and multiple slaves. can be master and slave;

6. Storage data security – after memcache hangs, the data is gone; redis can be regularly saved to disk (persistence);

7. Disaster recovery – after memcache hangs, the data cannot be recovered; after redis data is lost, it can be recovered through aof;

8. Redis supports data backup, that is, data backup in master-slave mode;

9. Different application scenarios: In addition to being used as a NoSQL database, Redis can also be used as a message queue, data stack, and data cache; Memcached is suitable for caching SQL statements, data sets, user temporary data, delayed query data and sessions, etc. .

scenes to be used

1. If there are persistent requirements or requirements for data types and processing, redis should be selected.
2. If simple key/value storage should choose memcached.

Chestnut

In e-commerce sites, there are generally categories and then a list of search results.
In this case, we can use memcached for the classified data, because the classified data generally does not change, read more and write less, and store it directly in memcached, each query only needs to be obtained from memcached.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326357079&siteId=291194637