Difficulty: Intermediate
How do you change a Redis configuration setting without restarting the server, and how do you make sure the change survives a restart?
Use CONFIG SET parameter value to change most settings on a running server; the change takes effect immediately with no restart. That change lives only in memory, so run CONFIG REWRITE afterwards to write it back to redis.conf, or update the file yourself, or the server will revert on its next restart.
| Command | Purpose |
|---|---|
CONFIG GET maxmemory* | Read settings, glob patterns allowed |
CONFIG SET maxmemory 4gb | Change a setting at runtime |
CONFIG SET a 1 b 2 | Set several at once, atomically (7.0+) |
CONFIG REWRITE | Persist running config into the config file |
CONFIG RESETSTAT | Reset INFO counters like hits and misses |
Since Redis 7.0, setting multiple parameters in one CONFIG SET is atomic: if one value is invalid, none are applied.
maxmemory and maxmemory-policy when a cache is under pressure.slowlog-log-slower-than (microseconds) to catch slow commands during an incident.appendonly yes to enable AOF on a running instance; Redis starts an AOF rewrite in the background.save "3600 1 300 100" to change RDB snapshot rules.loglevel to temporarily increase logging.client-output-buffer-limit to give Pub/Sub or replicas more headroom.daemonize and databases. CONFIG SET returns an error for them.dir and dbfilename cannot be changed with CONFIG SET unless enable-protected-configs allows it. This blocks a well-known attack where an attacker pointed dir at an SSH folder and wrote files via SAVE.CONFIG is usually disabled. You change settings through parameter groups or the console instead.CONFIG GET maxmemory-policy.evicted_keys and latency.CONFIG REWRITE so a restart does not silently roll back. Note that it rewrites the file in place and may reformat it.CONFIG SET is not replicated, so each node needs the change.CONFIG is a dangerous command. Use ACLs so application users cannot call it: ACL SETUSER app on >pass ~* +@all -@dangerous removes CONFIG, FLUSHALL, KEYS and other risky commands for that user, while an admin user keeps them. The older rename-command CONFIG "" approach still works but ACLs are the modern way.
redis-cli CONFIG GET 'maxmemory*'
# Apply two changes atomically (Redis 7.0+)
redis-cli CONFIG SET maxmemory 4gb maxmemory-policy allkeys-lru
# Log commands slower than 5 ms during an incident
redis-cli CONFIG SET slowlog-log-slower-than 5000
# Persist the running config to redis.conf
redis-cli CONFIG REWRITE
# Protected config is refused by default on 7.0+
redis-cli CONFIG SET dir /tmp
maxmemory 0 means no limit. The exact error text for protected configs can differ slightly between versions.
# App user: all keys, all commands except the dangerous category
redis-cli ACL SETUSER app on '>appPass#2026' '~*' '+@all' '-@dangerous'
# Check what the user can do
redis-cli ACL GETUSER app
# Persist ACL changes if using an ACL file
redis-cli ACL SAVE
The @dangerous category includes CONFIG, FLUSHALL, KEYS, DEBUG and similar, so a leaked app password cannot reconfigure the server.
CONFIG SET, CONFIG GET, CONFIG REWRITE, Protected Configs, ACL