Runtime Configuration

Difficulty: Intermediate

Question

How do you change a Redis configuration setting without restarting the server, and how do you make sure the change survives a restart?

Answer

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.

The CONFIG family

CommandPurpose
CONFIG GET maxmemory*Read settings, glob patterns allowed
CONFIG SET maxmemory 4gbChange a setting at runtime
CONFIG SET a 1 b 2Set several at once, atomically (7.0+)
CONFIG REWRITEPersist running config into the config file
CONFIG RESETSTATReset 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.

Settings commonly changed live

  • 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.

What you cannot change, or should not

  • Some parameters are immutable at runtime, such as daemonize and databases. CONFIG SET returns an error for them.
  • Since Redis 7.0, protected configs such as 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.
  • On managed services (AWS ElastiCache, Azure Cache, Google Memorystore), CONFIG is usually disabled. You change settings through parameter groups or the console instead.

Doing it safely in production

  1. Check the current value first: CONFIG GET maxmemory-policy.
  2. Apply the change on one node and watch metrics, for example evicted_keys and latency.
  3. Run CONFIG REWRITE so a restart does not silently roll back. Note that it rewrites the file in place and may reformat it.
  4. Apply to replicas too. CONFIG SET is not replicated, so each node needs the change.
  5. Commit the change to your config management (Ansible, Helm values) so the next deploy does not overwrite it.

Locking it down

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.

Safe runtime config change. Change, verify, persist, and propagate.
  1. Read current value: CONFIG GET maxmemory-policy
  2. Apply live: CONFIG SET maxmemory-policy allkeys-lfu
  3. Watch metrics: Check evictions, latency, errors.
  4. Persist to file: CONFIG REWRITE updates redis.conf.
  5. Repeat on replicas: CONFIG SET is not replicated.

Code examples

Changing settings at runtime

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.

Removing CONFIG from the app user with ACL

# 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.

Key points

  • CONFIG SET changes most settings live; it is lost on restart unless persisted.
  • CONFIG REWRITE writes the running config back to redis.conf.
  • CONFIG SET is not replicated; apply it to every node.
  • Redis 7.0 protects dir, dbfilename and similar configs from CONFIG SET by default.
  • Managed services usually disable CONFIG; use parameter groups instead.
  • Restrict CONFIG with ACLs (-@dangerous) for application users.

Common follow-up questions

  • What happens if you run CONFIG SET appendonly yes on a live server?
  • Why were dir and dbfilename made protected configs?
  • How do you change Redis configuration on AWS ElastiCache?
  • How would you roll out a config change across a Redis Cluster?

Interview tips

  • Always mention CONFIG REWRITE; forgetting persistence is the most common real mistake.
  • Point out that CONFIG SET is per node and not replicated.
  • Bringing up ACLs and protected configs shows security awareness.

Concepts covered

CONFIG SET, CONFIG GET, CONFIG REWRITE, Protected Configs, ACL

More Redis & Caching questions