Home >Database >Redis >How to achieve persistence in redis

How to achieve persistence in redis

silencement
silencementOriginal
2019-06-06 14:16:0416163browse

How to achieve persistence in redis

Redis is an advanced key-value database. It is similar to memcached, but data can be persisted and supports a wide range of data types. There are strings, linked lists, sets and sorted sets. It supports calculating the union, intersection and complement (difference) of sets on the server side, and also supports a variety of sorting functions. So Redis can also be regarded as a data structure server.
All data in Redis is stored in memory and then asynchronously saved to disk from time to time (this is called "semi-persistent mode"); each data change can also be written to an append only inside file(aof) (this is called "full persistence mode").

Since Redis data is stored in memory, if persistence is not configured, all data will be lost after redis restarts. Therefore, you need to enable the persistence function of redis and save the data to the disk. When redis restarts, Afterwards, the data can be recovered from the disk. Redis provides two methods for persistence, one is RDB persistence (the principle is to periodically dump Reids database records in memory to RDB persistence on disk), and the other is AOF (append only file) persistence ( The principle is to write Reids' operation log to the file in an appending manner).

The difference between Redis and memcache is that the data stored in Redis is persistent, and the data will not be lost after a power outage or restart. Because Redis's storage is divided into three parts: memory storage, disk storage and log files, after restarting, Redis can reload data from the disk into the memory. These can be configured through the configuration file. Because of this, Redis can achieve persistence. change.

The above is the detailed content of How to achieve persistence in redis. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What is redis used for?Next article:What is redis used for?