The Redis configuration file, often named
redis.conf, is the central source for configuring your Redis server. It allows you to set various options and parameters that define how Redis behaves. These include but are not limited to:
Network settings: You can specify the port number on which Redis listens, bind specific IP addresses, and set up password-based authentication.
Data persistence options: You can configure Redis to save data to disk at certain intervals or after a certain number of write operations.
Memory management settings: You can set a max memory limit and specify what happens when this memory limit is reached (e.g., evicting old keys).
Logging and monitoring options: You can set the level of logging and specify a log file location.
Advanced settings: Various options like setting up master-slave replication, enabling append-only file mode, etc.
Here's an example of what some entries in a redis.conf file might look like:
In this example:
bind 127.0.0.1 specifies that Redis will only listen to connections from the local machine.
port 6379 sets the port number that Redis will use.
requirepass mysecretpassword sets a password for clients to authenticate themselves.
save 900 1 configures Redis to persist data every 15 minutes if at least 1 key has changed.
maxmemory 1gb sets the maximum memory usage to 1GB.
maxmemory-policy allkeys-lru specifies that when the max memory is reached, Redis should remove less recently used keys first.
logfile /var/log/redis.log specifies the location of the log file.
You can specify these configurations at startup by providing the path to the configuration file as an argument:
If you need to change some settings without restarting Redis, you can use the
CONFIG SET command directly in Redis. However, note that not all configurations can be changed at runtime.