Redis - Configuration
Redis - Configuration
Section titled “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.
Reading Configuration at Runtime
Section titled “Reading Configuration at Runtime”You can inspect the current server configuration directly from a client using the CONFIG GET command.
Syntax
Section titled “Syntax”> CONFIG GET <parameter>Example: Get a specific parameter
Section titled “Example: Get a specific parameter”To retrieve the value of the loglevel parameter:
127.0.0.1:6379> CONFIG GET loglevel1) "loglevel"2) "notice"Example: Get all parameters
Section titled “Example: Get all parameters”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*.
Editing Configuration
Section titled “Editing Configuration”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.
Syntax
Section titled “Syntax”> CONFIG SET <parameter> <value>Example
Section titled “Example”127.0.0.1:6379> CONFIG SET maxmemory "2gb"OK
127.0.0.1:6379> CONFIG GET maxmemory1) "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.
Key Configuration Directives
Section titled “Key Configuration Directives”While Redis has over 100 configuration directives, here are some of the most critical ones you should be familiar with.
Security
Section titled “Security”requirepass <password>: Sets a password that clients must use to authenticate using theAUTHcommand. 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 thebinddirective 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 tobind <private_ip_address>orbind 0.0.0.0(use with caution and a firewall).
Persistence
Section titled “Persistence”save <seconds> <changes>: Configures RDB snapshotting. For example,save 60 1000tells 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.
Memory Management
Section titled “Memory Management”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 includeallkeys-lru(evicts least recently used keys),volatile-lru(evicts least recently used keys with an expiry set), andnoeviction(returns errors on write commands when memory is full).