Understanding the Core Redis Configuration File
Redis behavior is controlled through the redis.conf file. This file defines everything from basic daemon settings to advanced memory management and replication policies. Below is a comprehensive guide organized by functional area.
General Operation Settings
# Run Redis as a daemon (background process)
daemonize yes
# PID file location
pidfile /var/run/redis/redis-server.pid
# Network port
port 6379
# TCP backlog - set this higher under heavy load
tcp-backlog 511
# Bind to specific interfaces (uncomment to restrict)
# bind 127.0.0.1
# Unix socket path and permissions
# unixsocket /var/run/redis/redis.sock
# unixsocketperm 700
# Idle timeout (seconds) - 0 disables
timeout 0
# TCP keepalive interval (0=disable)
tcp-keepalive 0
# Log level: debug, verbose, notice, warning
loglevel notice
# Log file location (empty = stdout)
logfile /var/log/redis/redis-server.log
# Number of databases
databases 16
# Protected mode - restricts external access when no bind/password set
protected-mode yes
Persistence: RDB Snapshots
Redis can persist data to disk using periodic snapshots (RDB). The following rules define when a snapshot is triggered:
# save <seconds> <changes>
save 900 1 # At least 1 key change in 15 minutes
save 300 10 # At least 10 key changes in 5 minutes
save 60 10000 # At least 10000 key changes in 1 minute
# Stop accepting writes if RDB fails
stop-writes-on-bgsave-error yes
# Compress RDB file using LZF
rdbcompression yes
# CRC64 checksum at end of RDB file (adds ~10% overhead)
rdbchecksum yes
# RDB file name
dbfilename dump.rdb
# Data directory (RDB, AOF, and other files)
dir /data
Persistence: Append-Only File (AOF)
# Enable AOF
appendonly no
# AOF file name
appendfilename "appendonly.aof"
# fsync policy: always, everysec, or no
appendfsync everysec
# Disable fsync during rewrites to avoid blocking
no-appendfsync-on-rewrite no
# Auto-rewrite when file grows 100% from last rewrite and exceeds 64MB
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
# Load truncated AOF when possible
aof-load-truncated yes
Replication (Master-Slave)
# Make this instance a replica of a master
# slaveof <masterip> <masterport>
# Password for master authentication
# masterauth <password>
# Serve stale data while reconnecting
slave-serve-stale-data yes
# Replica is read-only by default
slave-read-only yes
# Diskless sync: transfer RDB via socket instead of disk
repl-diskless-sync no
# Delay before starting diskless sync (allow more replicas to connect)
repl-diskless-sync-delay 5
# Ping interval between master and replica
# repl-ping-slave-period 10
# Replication timeout (must be > ping interval)
# repl-timeout 60
# Disable TCP_NODELAY on replication socket (yes = less bandwidth, more latency)
repl-disable-tcp-nodelay no
# Backlog size for partial resynchronization
# repl-backlog-size 5mb
# Time to retain backlog when no replicas connected
# repl-backlog-ttl 3600
# Replica priority for election (lower = higher priority, 0 = never promoted)
slave-priority 100
# Minimum healthy replicas for master to accept writes
# min-slaves-to-write 3
# min-slaves-max-lag 10
Security
# Require password authentication
# requirepass very_strong_password
# Rename dangerous commands
# rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52
# Disable a command entirely
# rename-command CONFIG ""
Connection & Memory Limits
# Maximum simultaneous client connections
# maxclients 10000
# Maximum memory limit
# maxmemory <bytes>
# Eviction policy when limit is reached:
# volatile-lru, allkeys-lru, volatile-random, allkeys-random,
# volatile-ttl, noeviction
# maxmemory-policy noeviction
# LRU sample size for eviction
# maxmemory-samples 5
Lua Scripting
# Maximum execution time in milliseconds
lua-time-limit 5000
Cluster
# Enable cluster mode
# cluster-enabled yes
# Cluster configuration file (auto-generated)
# cluster-config-file nodes-6379.conf
# Node timeout (milliseconds)
# cluster-node-timeout 15000
# Replica validity factor (controls stale replica promotion)
# cluster-slave-validity-factor 10
# Minimum replicas per master for migration
# cluster-migration-barrier 1
# Require full slot coverage for cluster to operate
# cluster-require-full-coverage yes
Slow Log & Monitoring
# Commands slower than this (microseconds) are logged
slowlog-log-slower-than 10000
# Maximum number of slow log entries
slowlog-max-len 128
# Latency monitor threshold (0 = disabled)
latency-monitor-threshold 0
# Key-space event notification (empty = disabled)
notify-keyspace-events ""
Advanced Data Structure Tuning
# Hash: switch from ziplist to hash when exceeding limits
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
# List: ziplist threshold
list-max-ziplist-entries 512
list-max-ziplist-value 64
# Set: intset threshold
set-max-intset-entries 512
# Sorted set: ziplist threshold
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
# HyperLogLog: sparse <-> dense switch
hll-sparse-max-bytes 3000
# Active rehashing (1ms per 100ms CPU)
activerehashing yes
# Client output buffer limits
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
# Redis background tasks frequency (hz)
hz 10
# Incremental fsync during AOF rewrite (every 32MB)
aof-rewrite-incremental-fsync yes
Inspecting Configuration at Runtime
Use the CONFIG GET command to retrieve current values. The syntax is:
redis> CONFIG GET parameter_name
Example:
redis 127.0.0.1:6379> CONFIG GET loglevel
1) "loglevel"
2) "notice"
To change a parameter dynamically without restarting, use CONFIG SET:
redis> CONFIG SET loglevel debug
OK
Quick Reference Table
The following table summarizes critical configuration parameters and their purposes:
| Parameter | Default | Description |
|---|---|---|
daemonize |
no | Run as background process (Windows: always no) |
pidfile |
/var/run/redis.pid | PID file location |
port |
6379 | Listening port |
bind |
127.0.0.1 | IP addresses to listen on |
timeout |
0 | Client idle timeout (seconds) |
loglevel |
notice | Logging verbosity |
logfile |
stdout | Log file path |
databases |
16 | Number of logical databases |
save |
900 1 / 300 10 / 60 10000 | RDB snapshot triggers |
rdbcompression |
yes | Compress RDB with LZF |
dbfilename |
dump.rdb | RDB file name |
dir |
./ | Working directory for data files |
slaveof |
— | Master address for replication |
masterauth |
— | Master password |
requirepass |
— | Authentication password |
maxclients |
10000 | Max simultaneous cleints |
maxmemory |
— | Max memory limit |
appendonly |
no | Enable AOF persistence |
appendfsync |
everysce | AOF fsync policy |
vm-enabled |
no | Virtual memory (legacy, not recommedned) |
hash-max-ziplist-entries |
64 | Hash ziplist threshold |
activerehashing |
yes | Dynamic rehashing |