Understanding the Redis Configuration File
In this lesson, we will dive deep into the Redis configuration file (redis.conf). You will learn how to locate it, read it, and customize it to suit your development or production needs.
What is redis.conf?
The redis.conf file is the primary configuration file for Redis. It determines how Redis behaves at runtime, including settings for:
- Memory usage
- Persistence
- Network bindings
- Security
- Logging
- Replication and clustering
Redis loads this file when the server starts, unless you explicitly override configuration options via command-line arguments or environment variables.
You can typically find redis.conf in locations like /etc/redis/, /usr/local/etc/redis/, or the root of the Redis source directory. If you installed Redis via a package manager, use find / -name redis.conf to locate it.
Key Sections in redis.conf
1. General Options
When to enable: Use daemonize yes for production environments so Redis runs in the background.
When to disable: In development, disabling makes logs appear in the terminal.
2. Network Settings
Best practice: Always use bind 127.0.0.1 and protected-mode yes unless you have strict firewall rules.
3. Logging and Debugging
When to use debug: While debugging or troubleshooting.
When to use notice or warning: In production to reduce noise.
4. Persistence Options
Use both AOF and RDB: for a balance of speed and durability.
5. Memory Management
When to set maxmemory: Always in production to prevent server crashes.
Eviction choice: Use allkeys-lru for caching workloads.
6. Security Settings
When to require password: Always if Redis is accessible over a network.
When to rename commands: To protect admin commands like FLUSHALL.
7. Replication and Clustering
When to use replication: For high availability and backups.
When to enable clustering: For large-scale, distributed setups.
Customizing the Configuration
You can launch Redis with a custom configuration file like this:
redis-server /path/to/your/redis.conf
Or override options inline:
redis-server --port 6380 --maxmemory 128mb --requirepass secret123
Some config changes can be made at runtime using CONFIG SET:
redis-cli CONFIG SET maxmemory 512mb
However, not all options are runtime-configurable. Changes made via CLI are not persistent unless saved with:
redis-cli CONFIG REWRITE
- Do not expose Redis to public networks without proper authentication and firewalls.
- Use both RDB and AOF for a balance of durability and performance.
- Tune snapshot intervals (
save) and AOF fsync policy (appendfsync) according to durability needs. - Set reasonable memory limits to avoid OOM crashes.
- Regularly monitor logs and performance using
INFO,MONITOR, andSLOWLOG. - Always back up your configuration before making changes.
Hands-On Task
- Locate the default
redis.confon your system (tryredis-server --helpor check/etc/redis/). - Change the port from
6379to6380, restart the server, and test usingredis-cli -p 6380. - Enable AOF, make some writes, then inspect the contents of
appendonly.aof. - Try using
CONFIG SET maxmemory 100mb, then confirm withCONFIG GET maxmemory.