If you're diving into Redis and wondering how to make it behave the way you want, you'll want to get comfortable with its configuration file — redis.conf
. This humble file controls a lot of Redis’s behavior, from how it stores data to how it communicates with the outside world.
What is redis.conf
?
redis.conf
is the configuration file used by the Redis server. It acts like an instruction manual, telling Redis how it should operate once it's started.
When you run the Redis server, it looks for this file (usually located at /etc/redis/redis.conf
or wherever Redis was installed) and applies the settings defined in it.
You can also start the Redis server manually with a specific config file like this:
redis-server /path/to/redis.conf
Why is redis.conf
Important?
By modifying redis.conf
, you can:
- Control how Redis uses memory
- Set up persistence so your data survives restarts
- Choose how Redis handles incoming connections
- Add password protection for security
- Customize logging behavior and more
Whether you're running Redis in production or just experimenting locally, knowing how to tweak redis.conf
gives you greater control and stability.
Key Settings in redis.conf
Let’s look at some of the most important and commonly used settings.
1. maxmemory
maxmemory 256mb
This sets the maximum amount of memory Redis is allowed to use. If your dataset grows larger than this limit, Redis will start evicting keys based on the eviction policy you define (like allkeys-lru
).
This is crucial for keeping Redis within resource limits, especially in environments like cloud servers or containers.
2. save
save 900 1
save 300 10
save 60 10000
These lines define when Redis creates RDB (Redis Database) snapshots.
-
save 900 1
means: after 900 seconds (15 minutes), if at least 1 key has changed, take a snapshot. -
save 300 10
means: after 5 minutes, if 10 or more keys changed, snapshot. -
save 60 10000
means: after 1 minute, if 10,000+ keys changed, snapshot.
You can remove all save
lines to disable RDB snapshots completely (not recommended without another persistence method like AOF).
3. appendonly
appendonly yes
This turns on AOF (Append-Only File) persistence. Redis logs every write operation, ensuring minimal data loss in case of a crash.
You can pair AOF with RDB for better durability.
4. requirepass
requirepass yourStrongPassword
This adds a basic layer of security. Clients must authenticate using this password before they can interact with the server.
Useful in any environment where you don’t want just anyone accessing your Redis instance — which should be all environments!
5. bind and port
bind 127.0.0.1
port 6379
These settings control where Redis listens for connections.
-
bind
restricts Redis to specific IP addresses. -
port
defines which port Redis listens on (default is 6379).
By default, Redis only binds to 127.0.0.1
(localhost), meaning it’s only accessible from the same machine. If you want to allow external access, you’ll need to update the bind
setting and secure your server accordingly.
6. logfile and dir
logfile /var/log/redis/redis-server.log
dir /var/lib/redis/
-
logfile
specifies where to store logs. -
dir
sets the working directory where Redis will save RDB/AOF files.
Make sure these paths exist and are writable by the Redis process.
How to Apply Changes
Redis does not automatically reload redis.conf
changes. If you make edits, you’ll need to:
- Restart the Redis server:
sudo systemctl restart redis
- Or, start it again manually with the updated config:
redis-server /path/to/redis.conf
Wrapping Up
redis.conf
is your main tool for shaping how Redis behaves. By learning just a few key settings, you can:
- Avoid running out of memory
- Control how your data is saved
- Keep your Redis instance secure
- Adjust performance settings based on your environment
If you're a software developer who enjoys exploring different technologies and techniques like this one, check out LiveAPI. It’s a super-convenient tool that lets you generate interactive API docs instantly.
LiveAPI helps you discover, understand and use APIs in large tech infrastructures with ease!
So, if you’re working with a codebase that lacks documentation, just use LiveAPI to generate it and save time!
You can instantly try it out here! 🚀
Top comments (0)