Learn how to use the Redis CLI set, get, and write commands to update the Redis Server configurations.
Redis is an open-source NoSQL database boasting quick transactions and low latency. This guide shows you how to make and adjust settings for your Redis server from the command line.
How Redis Configurations Work
Redis comes with an extensive configuration file by default, listing all of its configuration options. But Redis can also operate without any explicit configuration, using a default configuration suited for development and testing. However, it is recommended that you adjust the default configuration to suit your needs, especially before you start using Redis in a production setting.
Typically, you can find your Redis instance's configuration file at
/etc/redis/redis.conf on Debian and Ubuntu and at
/etc/redis.conf on CentOS and Fedora.
Each setting in Redis is controlled using a configuration directive. A directive is a line with:
- A configuration keyword
- One or more arguments for the configuration
The file below includes an example configuration directive. This example is taken from a configuration directive used in the first of our guides in this series on Redis — Connecting to Redis and Using Redis Databases:
[...] user example-user +@all allkeys on >password [...]
This directive uses the keyword
user to start defining a Redis user. The keyword is then followed by a series of arguments defining the username and a series of ACL (security) rules, including the user's password.
Available Configuration Directives
The full list of available configuration directives for Redis can be found in the default
redis.conf file which comes with each Redis installation.
You can also find links to copies of these files in Redis's configuration documentation. The page lists configuration files for various past Redis versions, so you can select the version applicable to you.
How to Change Configurations via the Command Line
The default route for configuring your Redis instance is through edits to the configuration file covered above. However, Redis comes with several commands to let you work with configuration directives directly from the command line.
There are a few primary reasons for doing so:
- Verifying current configurations on the fly
- Making temporary configuration changes
- Testing particular configurations
- Writing those configurations automatically to the configuration file
The remaining sections of this tutorial walk you through the various configuration commands for the Redis command-line interface (CLI). These commands can help you accomplish the goals listed above and many more when it comes to fine-tuning your Redis server.
You cannot manipulate all of the Redis's configuration directives from the command line. The sections below include a few that can be manipulated from the command line.
Check the Existing Redis Configuration
CONFIG GET command to fetch the current value of configuration directives matching a given pattern.
The command below fetches exactly and only the configuration directive you name.
CONFIG GET bind
127.0.0.1:6379> config get bind 1) "bind" 2) "127.0.0.1 ::1"
The command also supports wildcards (
*). With these, you can fetch all configuration directives matching particular patterns. This feature is especially useful when you want to see all of the settings related to a certain subject, like TLS:
CONFIG GET tls-*
1) "tls-client-cert-file" 2) "" 3) "tls-key-file-pass" 4) "" 5) "tls-session-caching" 6) "yes" 7) "tls-port" 8) "0" 9) "tls-ciphersuites" 10) "" 11) "tls-session-cache-size" 12) "20480" 13) "tls-ca-cert-file" 14) "" 15) "tls-client-key-file" 16) "" 17) "tls-prefer-server-ciphers" 18) "no" 19) "tls-session-cache-timeout" 20) "300" 21) "tls-dh-params-file" 22) "" 23) "tls-ca-cert-dir" 24) "" 25) "tls-auth-clients" 26) "yes" 27) "tls-protocols" 28) "" 29) "tls-client-key-file-pass" 30) "" 31) "tls-replication" 32) "no" 33) "tls-key-file" 34) "" 35) "tls-cert-file" 36) "" 37) "tls-ciphers" 38) "" 39) "tls-cluster" 40) "no"
You can use the wildcard by itself to fetch your Redis server's current (in-memory) configuration directives.
CONFIG GET *
127.0.0.1:6379> config get * 1) "always-show-logo" 2) "no" 3) "stream-node-max-entries" 4) "100" 5) "masterauth" 6) "" 7) "socket-mark-id" 8) "0" 9) "tls-key-file-pass" 10) "" 11) "tls-ciphersuites" 12) "" 13) "aof-use-rdb-preamble" 14) "yes" 15) "protected-mode"
CONFIG GET * is especially useful since it shows all of the configuration directives supported for fetching, setting, and writing from the command line.
Make Changes to the Redis Configuration
CONFIG SET command to make or alter a configuration directive.
The command below takes the name of a directive followed by the directive's argument. Here, the
repl-timeout directive is set to
70 seconds, from its default of
CONFIG SET repl-timeout 70
Multiple arguments, or arguments with spaces, can be handled using quotes. The example below adds an address template to the
bind directive shown above. The added template is the default for loop-back connections on Redis.
CONFIG SET bind "127.0.0.1 192.0.2.0 -::1"
Configuration changes made in this way take effect immediately. For that reason,
CONFIG SET works extraordinarily well for testing settings for your Redis server.
Further, configurations made with
CONFIG SET are in memory. Resetting any changes you make only requires restarting your Redis server, which you can typically do with the following command:
sudo systemctl restart redis-server
sudo systemctl restart redis
Write Redis Configuration Changes
After testing some settings with
CONFIG SET, you may want to make those settings persistent. You can do that using the
CONFIG REWRITE command.
This command has Redis write your in-memory configuration directives, like those created or changed with
CONFIG SET, to the configuration file.
The command does not take any arguments, so you can execute it using the following command:
The command attempts to preserve, as much as is feasible, the original structure of the configuration file while writing only the necessary lines to it. This means that:
- Modifications to existing directives are typically written in their original places in the file
- Directives created with default values do not actually get written to the configuration file (default values do not need to be explicitly stated)
- New directives are added to the end of the configuration file
You now have the tools you need to start working with Redis configurations from the command line. As mentioned in this tutorial, these tools work exceptionally well when you want to test various settings on the fly.
To learn more about Redis and how to use Redis databases, be sure to read our other guides in this series.