Introduction to Redis

Redis Persistence

Redis has four different persistence modes made up of:

  • RDB a periodical snap-shot in time
  • AOF data is saved on every write command
  • No on-disk persistence
  • Both RDB and AOF



  • Compact single-file snapshot of the Redis data
  • Restores easily from a single-file snapshot backup
  • Faster restart when loading large datasets


  • Potential data loss between snapshots
  • Needs to fork child process to create snapshot, forking may take a lot of time if large dataset and slow processor preventing client access in the meantime.

AOF (Append Only File)


  • More durable, setting fsync to 1 second means at most 1 second would be lost if a failure occurs
  • AOF log append-only, no seeks and if last write command fails, easy to fix with the redis-check-aof utility
  • AOF is automatically written in background, allowing Redis to continue to serve clients
  • Contains a log of all operations of each write operation, easy to export format


  • AOF files are usually bigger than equivalent RDB files
  • Can be slower than RDB depending on fsync policy

Configuring redis.conf

Exercise: Saving RDB snapshot & redis.conf parameters

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.> SAVE
Background saving started>

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

Operating a live Redis instance

Critical Commands for configuring a running Redis instance

Exercise: Configuration & other Commands

The CONFIG SET allows you to set a configuration parameter at runtime while the CONFIG GET command retrieves a parameter.> CONFIG GET appendonly
1) "appendonly"
2) "no"> CONFIG GET asfdsf
(empty list or set)> CONFIG GET port
1) "port"
2) "6379"> CONFIG SET appendonly yes

The MONITOR command will display all incoming client commands to the monitored Redis instance> MONITOR
1418623217.197721 [0] "DBSIZE"
1418623241.973480 [0] "SET" "Book:3" "Pride and Prejudice"
1418623264.670176 [0] "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.> BGREWRITEAOF 
Background append only file rewriting started> 

References and Resources

  1. From the website, topic on