Redis

Redis Conf Example

Redis is mainly governed by rules and directives defined in the Redis configuration file. It contains definitions such as the bind address of the Redis server, maximum memory, maximum number of clients, etc.

Although the default configuration is suitable for development and testing purposes, learning how to edit and modify the Redis configuration file can be beneficial, especially in production.

Let us learn about the most fundamental settings in the Redis configuration and modify them.

Where is the Redis.conf Located

The Redis configuration file is located in the root directory where you have Redis installed.

NOTE: This may depend on the method used to install Redis. If you installed Redis via a package manager, the configuration file is located in /etc/redis/redis.conf

The file is a text file but contains configuration directives. You can edit this file from the terminal using a basic text editor such as nano, vim, emacs, etc.

Configuration Format

The configuration file follows a specific format to define the rule and the parameter. The structure is as shown:

keyword argument1 argument2…, argumentN

The command starts with the keyword, which denotes the rule configures and its value or parameter.

The Redis configuration file is heavily documented with descriptive messages on each block.

Each line that starts with a hash sign is treated as a comment. This means that the server will not interpret it as part of the configuration when starting up.

To activate a configuration block that has been deactivated, remove the preceding # sign.

Before activating a configuration block, ensure to read what the documentation states and the effects of modifying it.

Redis Configuration Blocks

The Redis configuration file is organized into specific blocks. Each block contains instructions for a particular feature of the Redis server.

These blocks include:

  • INCLUDES
  • MODULES
  • NETWORK
  • TLS/SSL
  • GENERAL
  • SNAPSHOTTING
  • REPLICATION
  • KEYS TRACKING
  • SECURITY
  • CLIENTS
  • MEMORY MANAGEMENT
  • LAZY FREEING
  • THREADED I/O
  • KERNEL OOM CONTROL
  • APPEND ONLY MODE
  • LUA SCRIPTING
  • REDIS CLUSTER
  • CLUSTER DOCKER/NAT support
  • SLOW LOG
  • LATENCY MONITOR
  • EVENT NOTIFICATION
  • GOPHER SERVER
  • ADVANCED CONFIG
  • ACTIVE DEFRAGMENTATION

Although we cannot discuss each configuration block, it is good to understand what it entails.

INCLUDES

The includes block holds configuration when managing multiple Redis servers. It should be located at the top of the configuration file.

MODULES

The modules block holds the configuration for enabled modules in the Redis server. In addition, you can check the Redis modules page to learn how to use the provided modules.

NETWORK

The network block sets the configuration about how the Redis server starts. Example configuration includes the running address and ports, client timeout, etc.

GENERAL

This block contains general configuration for the Redis server, such as running Redis as a daemon. You can also define a custom location for your log file, log level, number of databases in your Redis cluster, etc.

SNAPSHOTTING

This block holds configuration settings when saving Redis databases to a file. Here you can define rules such as database compression, the location, and name of your save file, etc.

CLIENTS

Defines the rules on how clients connecting to the Redis server are managed. This is where you’ll find settings such as the maximum clients allowed on the server.

MEMORY MANAGEMENT

This block will find Redis memory eviction policies and the maximum memory allowed on the server.

ADVANCED CONFIGURATION

This block holds the non-typical configuration for your Redis databases, such as list compression levels, encoding, etc.

Important Redis Configuration Rules

The following are some critical configurations for your Redis server.

##############GENERAL###############

daemonize yes // run redis server in the background

requirepass <secure_password> // secure your server with a password

pidfile /var/vcap/sys/run/redis.pid // path to the Redis PID file

#############NETWORK################

bind 0.0.0.0 // listen on all addresses

port 6379 // default bind port

timeout 3600s // close connection after client is idle for N seconds

tcp-keepalive 60

###########LOGGING####################

logfile /var/vcap/sys/log/redis/redis.log // path to the log file

###########PERSISTENCE################

dbfilename dump.rdb // name to your database save file

dir /var/vcap/store/redis // directory to database saves

appendonly no // save mode

save 900 1

save 300 10

save 60 10000

##############CLIENTS#############

maxclients 10000

Changing Configuration at Runtime

If you want to change the configuration when the server runs, you can use the CONFIG SET command.

This will set the specified configuration at runtime and reset to the one specified in the configuration file after a restart.

An example of config set command is as shown:

127.0.0.1:6379> config set maxclients 50000

OK

The command will change the number of maxclients during runtime. After restart, Redis will use the one defined in the config file.

Conclusion

This article explored how to work and use the Redis configuration file. We learned various blocks in the Redis conf file and edited them.

We hope you found this article to be helpful. See you in the next one!!

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list