To effectively run Redis, understanding your options for persisting data to disk is an important consideration that depends on your intended use of Redis. Redis also provides a number of helpful commands for operating a running instance.
Redis has four different persistence modes made up of:
fsyncto 1 second means at most 1 second would be lost if a failure occurs
The SAVE will save a RDB snapshot of the running Redis instance to disk, the BGSAVE does a similar RDB snaphot only running in the background while the active Redis instance still can respond to client commands.
127.0.0.1:6379> SAVE OK 127.0.0.1:6379> BGSAVE Background saving started 127.0.0.1:6379>
Listed below is a snippet from a Redis 3.0 configuration file some of the important parameters and default values for setting both RDB and AOF persistence in Redis.
# Accept connections on the specified port, default is 6379. # If port 0 is specified Redis will not listen on a TCP socket. port 6379 # Close the connection after a client is idle for N seconds (0 to disable) timeout 0 # Specify the server verbosity level. loglevel notice # Specify the log file name. Also the empty string can be used to force # Redis to log on the standard output. logfile "" save 900 1 save 300 10 save 60 10000 # RDB files created with checksum disabled have a checksum of zero that will # tell the loading code to skip the check. rdbchecksum yes # The filename where to dump the DB dbfilename dump.rdb # The working directory. dir /. appendonly no # The name of the append only file (default: "appendonly.aof") appendfilename "appendonly.aof" # Max execution time of a Lua script in milliseconds. lua-time-limit 5000
The CONFIG SET allows you to set a configuration parameter at runtime while the CONFIG GET command retrieves a parameter.
127.0.0.1:6379> CONFIG GET appendonly 1) "appendonly" 2) "no" 127.0.0.1:6379> CONFIG GET asfdsf (empty list or set) 127.0.0.1:6379> CONFIG GET port 1) "port" 2) "6379" 127.0.0.1:6379> CONFIG SET appendonly yes OK
The MONITOR command will display all incoming client commands to the monitored Redis instance
127.0.0.1:6379> MONITOR OK 1418623217.197721 [0 127.0.0.1:53288] "DBSIZE" 1418623241.973480 [0 127.0.0.1:53288] "SET" "Book:3" "Pride and Prejudice" 1418623264.670176 [0 127.0.0.1:53288] "GET" "Book:3"
The BGREWRITEAOF command will compact and rewrite the AOF log file in the background while the instance can still accept client commands.
127.0.0.1:6379> BGREWRITEAOF Background append only file rewriting started 127.0.0.1:6379>