Memory Units and General Settings
Redis configuration supports standard memory units. Units are case-insensitive, meaning 1GB, 1Gb, and 1gb are equivalent.
- 1kb = 1024 bytes
- 1k = 1000 bytes
- 1mb = 1024*1024 bytes
- 1m = 1000000 bytes
By default, Redis runs in the foreground. To run as a background daemon, modify the daemonize setting.
daemonize yes
pidfile /var/run/redis_6379.pidNetwork settings define the listening port and interface binding. Binding to a specific IP restricts access, which is crucial for production security.
port 6380
bind 192.168.1.100
protected-mode yesIdle connection handling prevents resource waste. A timeout of 0 disables this feature, keeping connections open indefinitely.
timeout 300Logging Configuration
Log levels dictate the verbosity of system messages. Available levels include debug, verbose, notice, and warning. For production, 'notice' is generally recommended.
loglevel notice
logfile "/var/log/redis/redis-instance.log"
databases 16Snapshotting (RDB Persistence)
Persistence allows Redis to save dataset snapshots to disk based on time and change thresholds. Multiple save rules can coexist.
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename "backup_dump.rdb"
dir "/data/redis/storage"Replication Settings
To set up a replica instance, specify the master's IP and port. The replica will automatically synchronize on startup.
replicaof 10.0.0.5 6379
masterauth <master-password>
replica-serve-stale-data yes
repl-ping-replica-period 10
repl-timeout 60Security Options
Redis is extremely fast, which makes brute-force password attacks feasible. Use a strong, complex password if exposing the instance.
requirepass "Str0ng!P@ssw0rd#123"Dangerous commands can be renamed or disabled entirely to prevent accidental or malicious system modifications.
rename-command FLUSHALL ""
rename-command CONFIG "custom_config_9f8e7d"Resource Limits and Memory Management
Setting a maximum memory limit is critical when using Redis as a cache. Once the limit is reached, the defined eviction policy determines how keys are removed.
maxclients 10000
maxmemory 2gbEviction policies include:
- volatile-lru: Evict least recently used keys with an expire set.
- allkeys-lru: Evict least recently used keys from all keys.
- volatile-lfu: Evict least frequently used keys with an expire set.
- allkeys-lfu: Evict least frequently used keys from all keys.
- noeviction: Return errors when memory limit is reached.
maxmemory-policy allkeys-lru
maxmemory-samples 5Append-Only File (AOF) Settings
AOF provides more durable persistence than RDB by logging every write operation. The fsync policy balances performance and data safety.
appendonly yes
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mbSlow Log
The slow log tracks queries exceeding a specified execution time. Time is measured in microseconds. A negative value disables the log, while zero forces logging of all commands.
slowlog-log-slower-than 10000
slowlog-max-len 128Advanced Memory Optimization
Redis utilizes specialized encoding for small collections to save memory. These thresholds define when Redis transitions from compact storage to standard HashMap or LinkedList structures.
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64Active rehashing helps reclaim memory by incrementally resizing the hash tables. This consumes CPU cycles but improves memory efficiency.
activerehashing yes