In this article, we discuss all the settings and check Redis’ configurations. We have finally discussed important Redis configurations, in detail.
Here are the important Redis configuration and their detail-
Snapshotting
This section contains all the configurations related to data backup or taking DB snapshots.
dir – working directory
Here is an example of “dir” configuration in the Redis config file.
dir <path_to_directory>
INIThis is the working directory of Redis. Data will be written in this directory.
For example-
dir /var/lib/redis
INIMake sure to set a directory here (not a file).
dbfilename – db dump file name
Name of the dump file where the database data is saved. The Redis dump file name has the extension “.rdb“.
dbfilename <file_name_with_rdb_extension>
INIThis file name is used while saving data for data persistency and also for database backup(when SAVE or BGSAVE command is used). The file name has “.rdb” extension.
This configuration is combined with the “dir” configuration for the full path of the database dump file.
Example:
dbfilename dump.rdb
INIThe default database file name is “dump.rdb“.
save – save db to disk
Defines the rule for saving data to disk.
save <interval_in_seconds> <number_of_changes> [<interval_in_seconds> <number_of_changes> ...]
INIWe can define the interval of saving data and the number of changes. Depending on this configuration Redis will check data after each interval of <interval_in_seconds> and if at least the <number_of_changes> are done, the data is saved to disk.
Multiple combinations of interval and number of changes can be defined. These multiple set changes are in “OR” condition with each other. If any of the condition is true, then changes are written to disk.
For example-
save 120 1 30 10
INIHere the changes are saved to disk if any of the following conditions are true-
- At least 1 change is made in 120 seconds. Redis will check every 120 seconds, if at least 1 change is done to the data or not.
- At least 10 changes are made in the last 30 seconds. Redis will check every 30 seconds, if 10 or more changes are made to data or not.
We can disable snapshotting by providing an empty string to save. like below-
save ""
INISecurity
Check the following configuration elements required for Redis security-
requirepass – default user password
Set the password for the default user-
requirepass <your_password_string_here>
INIThis config sets the password for the default user. The name of the default user in Redis is – “default“
aclfile – external file path for ACL config
Use a separate file to define the ACL rule for users-
aclfile /etc/redis/users.acl
INIWe can write the ACL permission information in the redis.conf file. But this configuration enables us to use a separate file just for the ACL permission for users.
As this is a standalone file, so the configuration will be separate and easier to maintain.
The file name does have to be user.acl. Name of the file can be anything as we want.
The format of writing configuration is the same as the format of writing ACL permissions in redis.conf–
user firstuser on >somepass ~* +@all &*
user seconduser on >someotherpass ~user* +get
INIWe can use only of the ACL configuration process, either in the redis.conf or in the external file. If user ACL permission are define in redis.conf and also in the external ACL config file at path defined as “aclfile”, then the server will fail to start.