Get the App
SLTechnology News&Howtos  ›  Database  › 

The difference between redis and memcached

Shulou Source: shulou.com Published: 2022-06-01 03:44:14 09月14日 Update

Simply comparing Redis with Memcached, most people will get the following idea:

1 Redis not only supports simple k/v type data, but also provides storage of list, set, hash and other data structures.

2 Redis supports data backup, namely master-slave mode data backup.

3 Redis supports data persistence, can keep the data in memory in disk, restart time can be loaded again for use.

Despite this, you can dive into the internal structure of Redis to observe more essential differences and understand the design of Redis.

In Redis, not all data is always stored in memory. This is the biggest difference between Memcached and Memcached. Redis will only cache all key information. If Redis finds that the memory usage exceeds a certain threshold, it will trigger swap operation. Redis calculates which key corresponding values need to be swapped to disk according to "swappability = age*log(size_in_memory)". Then persist the values corresponding to these keys to disk and clear them in memory.

This feature allows Redis to hold data that exceeds the size of the machine's own memory. Of course, the memory of the machine itself must be able to hold all the keys, after all, these data will not swap operations. At the same time, because Redis swaps the data in memory to disk, the main thread providing the service and the child thread performing the swap operation will share this part of memory, so if the data that needs swap is updated, Redis will block this operation until the child thread completes the swap operation.

Tags: Data memory disk simultaneous thread support backup time machine storage maximum not only usage information again size data backup data structure essence pattern Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Xiaomi Huawei Microsoft vpn