Skip to content

Redis - Configuration

Redis can be configured in two primary ways: by editing the redis.conf file for persistent settings, or by using the CONFIG command to modify the configuration at runtime. The redis.conf file is heavily commented and serves as excellent documentation for all available directives.

You can inspect the current server configuration directly from a client using the CONFIG GET command.

> CONFIG GET <parameter>

To retrieve the value of the loglevel parameter:

127.0.0.1:6379> CONFIG GET loglevel
1) "loglevel"
2) "notice"

You can use a glob-style pattern to get all configuration parameters. Using * will return everything.

127.0.0.1:6379> CONFIG GET *

Note: The output will be extensive, listing all directives supported by your Redis version. It is often more practical to query specific groups, like CONFIG GET *memory*.

For persistent changes that survive a server restart, you should edit the redis.conf file. For temporary, on-the-fly changes, use the CONFIG SET command.

> CONFIG SET <parameter> <value>
127.0.0.1:6379> CONFIG SET maxmemory "2gb"
OK
127.0.0.1:6379> CONFIG GET maxmemory
1) "maxmemory"
2) "2147483648"

To make runtime changes persistent, you can use the CONFIG REWRITE command, which will atomically update your redis.conf file with the current in-memory configuration. This requires that a configuration file was used to start the server initially.

While Redis has over 100 configuration directives, here are some of the most critical ones you should be familiar with.

  • requirepass <password>: Sets a password that clients must use to authenticate using the AUTH command. This is the first line of defense for your Redis instance.
  • protected-mode yes: A crucial security layer. When enabled (the default), Redis only accepts connections from the loopback interface (127.0.0.1) unless a password is set or the bind directive is explicitly configured. This prevents accidental exposure to the internet.
  • bind 127.0.0.1 -::1: Binds the server to specific network interfaces. The default binds to localhost for both IPv4 and IPv6. To make Redis accessible from other servers, you would change this to bind <private_ip_address> or bind 0.0.0.0 (use with caution and a firewall).
  • save <seconds> <changes>: Configures RDB snapshotting. For example, save 60 1000 tells Redis to save the dataset to disk if at least 1000 keys have changed in the last 60 seconds.
  • appendonly yes: Enables Append-Only File (AOF) persistence. Instead of snapshots, Redis logs every write operation. This provides much better durability than RDB but can result in a larger persistence file.
  • maxmemory <bytes>: Sets an upper limit on how much memory Redis can use. When this limit is reached, Redis will start evicting keys based on the configured policy.
  • maxmemory-policy <policy>: Defines the eviction policy. Common values include allkeys-lru (evicts least recently used keys), volatile-lru (evicts least recently used keys with an expiry set), and noeviction (returns errors on write commands when memory is full).