Home  >  Article  >  Database  >  How is redis persisted?

How is redis persisted?

(*-*)浩
(*-*)浩Original
2019-11-28 09:23:391952browse

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.

How is redis persisted?

There are strings, linked lists, sets and ordered 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. (Recommended learning: Redis video tutorial)

All data in Redis is stored in memory and then saved to disk asynchronously from time to time (this is called "semi-persistent" Mode"); you can also write every data change to an append only 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 appended manner).

So what is the difference between these two persistence methods, and how to choose? Most of what I read on the Internet introduces how to configure and use these two methods, but there is no introduction to the difference between the two and what application scenarios they are used in.

The difference between the two

RDB persistence refers to writing a snapshot of the data set in memory to disk within a specified time interval. The actual operation process is to fork a sub-process and first write the data set into a temporary file. After the writing is successful, the previous file is replaced and stored using binary compression.

Trigger conditions

The triggering of RDB persistence is divided into two types: manual triggering and automatic triggering.

AOF persistenceRecord every write, delete and other change operations processed by the server in the form of logs. Query operations will not be recorded, but will be recorded in the form of text, which can be seen by opening the file. Detailed operation records. (append)

For more Redis-related technical articles, please visit the Redis Getting Started Tutorial column to learn!

The above is the detailed content of How is redis persisted?. 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