Redis Configuration
Redis behavior depends on settings such as the port number, memory limit, and saving rules. You control all of them through a plain text file named redis.conf or through commands while the server runs. Good settings keep Redis fast, safe, and predictable.
The Thermostat Analogy
A home thermostat has a default temperature stored inside it, and you can turn the dial at any moment. Redis works the same way. The configuration file holds the permanent settings, and live commands change the dial without a restart.
Settings Priority (lowest to highest)
┌──────────────────────┐
│ Built-in defaults │
└──────────┬───────────┘
▼
┌──────────────────────┐
│ redis.conf file │
└──────────┬───────────┘
▼
┌──────────────────────┐
│ Start-up arguments │
└──────────┬───────────┘
▼
┌──────────────────────┐
│ CONFIG SET at runtime│
└──────────────────────┘
Loading a Configuration File
Pass the file path when you start the server.
$ redis-server /etc/redis/redis.conf
Each line in the file holds one setting name followed by its value. Lines that start with # are comments.
# Sample redis.conf lines port 6379 bind 127.0.0.1 maxmemory 256mb appendonly yes
Important Settings Every Beginner Should Know
Setting Example What It Controls ────────────── ───────────────── ─────────────────────────────── port 6379 TCP port Redis listens on bind 127.0.0.1 Network addresses allowed in requirepass MyStrongPass Password for client access databases 16 Number of numbered databases maxmemory 256mb Memory limit for stored data save 3600 1 Snapshot rule (seconds, changes) appendonly yes Turns on the append-only log loglevel notice Amount of detail in the log timeout 300 Seconds before idle clients close
Reading Settings with CONFIG GET
127.0.0.1:6379> CONFIG GET maxmemory 1) "maxmemory" 2) "0"
A value of 0 for maxmemory means Redis uses no limit. Production servers should always set a limit.
Use a pattern to list many settings at once.
127.0.0.1:6379> CONFIG GET append*
Changing Settings with CONFIG SET
127.0.0.1:6379> CONFIG SET maxmemory 512mb OK
The new limit takes effect at once. Redis keeps it only in memory, so a restart brings back the old value from the file.
Saving Runtime Changes with CONFIG REWRITE
127.0.0.1:6379> CONFIG REWRITE OK
CONFIG REWRITE writes your live settings into redis.conf. The next restart keeps them.
Where Redis Looks for Its Settings File
Package installs on Linux usually place the file at /etc/redis/redis.conf. A source build keeps a sample file in the project folder. Docker images start Redis without any file unless you mount one. Check the live location with this command.
127.0.0.1:6379> INFO server config_file:/etc/redis/redis.conf
Practical Example – Preparing a Small Cache Server
Need: A cache on a server with 2 GB of RAM. Plan: maxmemory 1gb → leaves room for the system maxmemory-policy allkeys-lru → removes old keys when full appendonly no → cache data can be rebuilt bind 10.0.0.5 → listens on the private network only requirepass (long random text) → blocks unknown clients
These five lines turn a default install into a safe and sensible cache.
Common Mistakes
- Leaving bind open to every network address.
- Running without a maxmemory limit on a shared server.
- Changing settings with CONFIG SET and forgetting CONFIG REWRITE.
- Editing the wrong redis.conf copy. Run CONFIG GET dir and INFO server to confirm the active file.
Key Points
- redis.conf stores permanent settings in plain text.
- CONFIG GET reads a setting and CONFIG SET changes it live.
- CONFIG REWRITE saves live changes to the file.
- Set port, bind, requirepass, and maxmemory before you go live.
- Later sources override earlier ones in the priority chain.
