################################ GENERAL #####################################
# By default Redis does not run as a daemon. Use 'yes' if you need it. # Note that Redis will write a pid file in /var/run/redis.pid when daemonized. daemonize yes
# When running daemonized, Redis writes a pid file in /var/run/redis.pid by # default. You can specify a custom pid file location here. pidfile /var/run/redis-6379.pid
# Accept connections on the specified port, default is 6379. # If port 0 is specified Redis will not listen on a TCP socket. port 6379 ... # Specify the log file name. Also the empty string can be used to force # Redis to log on the standard output. Note that if you use standard # output for logging but daemonize, logs will be sent to /dev/null logfile "6379.log"
...
# save ""
#save 900 1 #save 300 10 #save 60 10000
...
# The filename where to dump the DB dbfilename dump-6379.rdb
# The working directory. # # The DB will be written inside this directory, with the filename specified # above using the 'dbfilename' configuration directive. # # The Append Only File will also be created inside this directory. # # Note that you must specify a directory here, not a file name. dir /root/redis/redis/data
...
其他配置保持默认
执行如下操作:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
127.0.0.1:6379> dbsize (integer) 0 127.0.0.1:6379> set k1 1 OK 127.0.0.1:6379> set k2 2 OK 127.0.0.1:6379> set k3 2 OK 127.0.0.1:6379> set k4 2 OK 127.0.0.1:6379> set k5 2 OK 127.0.0.1:6379> save OK 127.0.0.1:6379>
# Note that if the AOF file will be found to be corrupted in the middle # the server will still exit with an error. This option only applies when # Redis will try to read more data from the AOF file but not enough bytes # will be found. //如果aof文件不完整,有错误,当重启aof时是否忽略错误 aof-load-truncated yes
127.0.0.1:6379> config get appendonly 1) "appendonly" 2) "no" 127.0.0.1:6379> config set appendonly yes OK 127.0.0.1:6379> config rewrite OK 127.0.0.1:6379> exit
...
127.0.0.1:6379> set hello world OK 127.0.0.1:6379> set hello java OK 127.0.0.1:6379> set hello redis OK 127.0.0.1:6379> incr counter (integer) 1 127.0.0.1:6379> incr counter (integer) 2 127.0.0.1:6379> incr counter (integer) 3 127.0.0.1:6379> rpush list a (integer) 1 127.0.0.1:6379> rpush list b (integer) 2 127.0.0.1:6379> rpush list c (integer) 3 127.0.0.1:6379> exit
(3)、可以查看,已经生成了appendonly.aof文件
1 2 3 4 5 6 7
[root@promote config]# cd ../data/ [root@promote data]# ll total 24 -rw-r--r--. 1 root root 5412 Jun 8 02:57 6379.log -rw-r--r--. 1 root root 4753 Jun 7 09:24 6382.log -rw-r--r--. 1 root root 467 Jun 8 03:02 appendonly.aof -rw-r--r--. 1 root root 50 Jun 7 09:32 dump-6379.rdb