AOF mode: log every operation
Advantages: the security is much higher than RDB;
Disadvantages: the efficiency is much lower than RDB;
To configure:
Edit redis.conf
[root@localhost redis]# vi redis.conf
Pull down to find:
The following picture:
appendonly no the aof mode is turned off by default. We change it to yes to turn it on
The following is the default aof file name
Pull down again:
The following picture:
Here are three synchronization strategies:
always is to synchronize as soon as changes occur (recommended with the highest practical security)
everysec is synchronized once per second
no is out of sync
We changed it to always
Then save to exit;
Then we restart redis and add a few key s:
You will see: here is an appendonly.aof file; AOF method recovers data
Let's reset the data first
[root@localhost redis]# rm -rf dump.rdb
[root@localhost redis]# ll
//Total consumption 48
drwxr-xr-x. 2 root root 134 7month 18 11:05 bin
-rw-r--r--. 1 root root 46698 7month 18 12:14 redis.conf
Start redis. The database is empty at present:
[root@localhost redis]# ./bin/redis-server ./redis.conf
[root@localhost redis]# ./bin/redis-cli
127.0.0.1:6379> keys *
(empty list or set)
Add data
127.0.0.1:6379> set n1 1
OK
127.0.0.1:6379> set n2 2
OK
127.0.0.1:6379> set n3 3
OK
127.0.0.1:6379> shutdown nosave
not connected> exit
[root@localhost redis]# ll
//Total dosage 52
-rw-r--r--. 1 root root 107 7 Month 1812:17 appendonly.aof
drwxr-xr-x. 2 root root 134 7 Month 1811:05 bin
-rw-r--r--. 1 root root 46698 7 Month 1812:14 redis.conf
[root@localhost redis]#
We cut the aof file to other places and start the test:
No data available;
[root@localhost redis]# mv appendonly.aof /root/
[root@localhost redis]# ll
//Total consumption 48
drwxr-xr-x. 2 root root 134 7month 18 11:05 bin
-rw-r--r--. 1 root root 46698 7month 18 12:14 redis.conf
[root@localhost redis]# ./bin/redis-server ./redis.conf
[root@localhost redis]# ./bin/redis-cli
127.0.0.1:6379> keys *
(empty list or set)
Let's copy the aof file back; we find that we have data
[root@localhost redis]# cp /root/appendonly.aof /usr/local/redis/
cp: Is it covered?"/usr/local/redis/appendonly.aof"? y
[root@localhost redis]# ll
//Total consumption 52
-rw-r--r--. 1 root root 107 7month 18 12:22 appendonly.aof
drwxr-xr-x. 2 root root 134 7month 18 11:05 bin
-rw-r--r--. 1 root root 46698 7month 18 12:14 redis.conf
[root@localhost redis]# ./bin/redis-server ./redis.conf
[root@localhost redis]# ./bin/redis-cli
127.0.0.1:6379> keys *
1) "n1"
2) "n3"
3) "n2"
Summary: we can back up aof files regularly and then copy them to redis for restart when necessary;