How to Edit the Redis Configuration File

Redis is configured by making changes to a configuration file named redis.conf. This file can be found at the root of the directory where you have installed Redis. It is not necessary to edit the configuration file if you’re simply going to test Redis, but if you’re using it on a production server, then you should make sure that the configuration is optimized for your use. The redis.conf file contains documentation that will help you configure it when you are editing the file. We will show you how to get to the redis.conf file and then go through the first five of the settings listed within the file to get you acclimated with the file.

These instructions require that Redis is installed on your VPS or Dedicated server and you will need root access to the server using SSH.

If you have Legacy WordPress Hosting, this article can be skipped as Redis is only available on VPS and Dedicated platforms.

How to Edit the Redis Configuration File – redis.conf

The Redis configuration file can be modified in a terminal editor like vim and provides much of the documentation on its options within the file. The configuration file that we will be using can also be obtained from Redis (we are using the 4.0 version). The redis.conf file uses the following format:

keyword argument1 argument2 ... argumentN

Your commands would start with the keyword and then a configuration option or argument for that setting followed by a space for the next argument.

The location for your redis.conf file will depend on how you installed it, but generally, it will be located within the root of the folder where you have installed Redis. For example:

root@vps99999 [~] # cd redis-stable
root@vps99999 [~/redis-stable] ls
./   00-RELEASENOTES CONTRIBUTING deps/ INSTALL MANIFESTO redis.conf  runtest-cluster* runtest-sentinel* src/ utils/
 ../  BUGS COPYING .gitignore Makefile README.md runtest* runtest-moduleapi*  sentinel.conf tests/

You can see that the redis.conf file is in the root of the installation. When you first log into the terminal, you use the cd command to change to the folder where you installed Redis. In this case, the folder is “redis-stable.” Once you’re, run your editor command to enter the file. If you’re using vim, then it would look like this:

 root@vps99999 [~/redis-stable] vim redis.config

Redis Configuration Settings

You will find that each configuration setting is documented within the redis.conf file. We will list a duplicate of what you will see in the file and briefly describe each command. Note that the “#” makes the text following it into a comment. To make the setting apply, you simply need to add a line of text without the “#” sign. We will list the first 5 options (of 20) within the Redis configuration file to give you an idea of what to expect for settings. Remember that you can always look in the configuration file for an explanation of the setting as well an example of how the option should be set.

Includes

################################## INCLUDES ###################################
# Include one or more other config files here.  This is useful if you 
# have a standard template that goes to all Redis servers but also need 
# to customize a few per-server settings.  Include files can include 
# other files, so use this wisely. 
# 
# Notice option "include" won't be rewritten by command "CONFIG REWRITE" 
# from admin or Redis Sentinel. Since Redis always uses the last processed 
# line as value of a configuration directive, you'd better put includes 
# at the beginning of this file to avoid overwriting config change at runtime. 
# 
# If instead you are interested in using includes to override configuration 
# options, it is better to use include as the last line. 
# 
# include /path/to/local.conf 
# include /path/to/other.conf 

As they recommend in the text above, make sure that any includes entry should be located at the top of the configuration file. This setting is especially useful if you are managing multiple Redis servers in the same manner.

Modules

################################## MODULES #####################################
# Load modules at startup. If the server is not able to load modules 
# it will abort. It is possible to use multiple loadmodule directives. 
# 
# loadmodule /path/to/my_module.so 
# loadmodule /path/to/other_module.so 

If you want to add an existing module, you can go to the Redis Modules page. Each module listed has a link to its corresponding GitHub repository. Make sure to read the documentation for the modules that you wish to use. Redis modules allow you to add to the functionality of Redis. For example, one of the more popular modules used for Redis is RediSearch which allows full-text search over Redis.

Network

############################ NETWORK#########################################
# By default, if no "bind" configuration directive is specified, Redis listens
# for connections from all the network interfaces available on the server.
# It is possible to listen to just one or multiple selected interfaces using
# the "bind" configuration directive, followed by one or more IP addresses.
#
# Examples:
#
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1 ::1
#
# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
# internet, binding to all the interfaces is dangerous and will expose the
# instance to everybody on the internet. So by default we uncomment the
# following bind directive, that will force Redis to listen only into
# the IPv4 lookback interface address (this means Redis will be able to
# accept connections only from clients running into the same computer it
# is running).
#
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
#   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
bind 127.0.0.1

# Protected mode is a layer of security protection, in order to avoid that
# Redis instances left open on the internet are accessed and exploited.
#
# When protected mode is on and if:
#
# 1) The server is not binding explicitly to a set of addresses using the
# "bind" directive.
# 2) No password is configured.
#
# The server only accepts connections from clients connecting from the
# IPv4 and IPv6 loopback addresses 127.0.0.1 and ::1, and from Unix domain
# sockets.
#
# By default protected mode is enabled. You should disable it only if
# you are sure you want clients from other hosts to connect to Redis
# even if no authentication is configured, nor a specific set of interfaces
# are explicitly listed using the "bind" directive.
protected-mode yes

# Accept connections on the specified port, default is 6379 (IANA #815344).
# If port 0 is specified Redis will not listen on a TCP socket.

 port 6379
# TCP listen() backlog.
#
# In high requests-per-second environments you need an high backlog in order
# to avoid slow clients connections issues. Note that the Linux kernel
# will silently truncate it to the value of /proc/sys/net/core/somaxconn so
# make sure to raise both the value of somaxconn and tcp_max_syn_backlog
# in order to get the desired effect.
tcp-backlog 511

# Unix socket.
#
# Specify the path for the Unix socket that will be used to listen for
# incoming connections. There is no default, so Redis will not listen
# on a unix socket when not specified.
#
# unixsocket /tmp/redis.sock
# unixsocketperm 700

# Close the connection after a client is idle for N seconds (0 to disable)
# timeout 0
# TCP keepalive.
#
# If non-zero, use SO_KEEPALIVE to send TCP ACKs to clients in absence
# of communication. This is useful for two reasons:
#
# 1) Detect dead peers.
# 2) Take the connection alive from the point of view of network
# equipment in the middle.
#
# On Linux, the specified value (in seconds) is the period used to send ACKs.
# Note that to close the connection the double of the time is needed.
# On other kernels the period depends on the kernel configuration.
#
# A reasonable value for this option is 300 seconds, which is the new
# Redis default starting with Redis 3.2.1.
tcp-keepalive 300

The network section of the Redis configuration file contains many options for the network connection used by Redis. Here you can see several live commands that are not commented out: bind 127.0.0.1, port 6379, and tcp-keepalive 300. We highly recommend that you contact your host’s technical team if you are not familiar with making any of these network settings.

General

################################# GENERAL ##################################### 
# By default Redis does not run as a daemon. Use 'yes' if you need it. 
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized. 
daemonize no 

# If you run Redis from upstart or systemd, Redis can interact with your 
# supervision tree. Options: 
#   supervised no      - no supervision interaction 
#   supervised upstart - signal upstart by putting Redis into SIGSTOP mode 
#   supervised systemd - signal systemd by writing READY=1 to $NOTIFY_SOCKET 
#   supervised auto    - detect upstart or systemd method based on 
#                        UPSTART_JOB or NOTIFY_SOCKET environment variables 
# Note: these supervision methods only signal "process is ready." 
# They do not enable continuous liveness pings back to your supervisor. 
supervised no

# If a pid file is specified, Redis writes it where specified at startup 
# and removes it at exit. 
# 
# When the server runs non daemonized, no pid file is created if none is 
# specified in the configuration. When the server is daemonized, the pid file 
# is used even if not specified, defaulting to "/var/run/redis.pid". 
# 
# Creating a pid file is best effort: if Redis is not able to create it 
# nothing bad happens, the server will start and run normally. 
pidfile /var/run/redis_6379.pid 

# Specify the server verbosity level. 
# This can be one of: 
# debug (a lot of information, useful for development/testing) 
# verbose (many rarely useful info, but not a mess like the debug level) 
# notice (moderately verbose, what you want in production probably) 
# warning (only very important / critical messages are logged) 
loglevel notice 

# Specify the log file name. Also the empty string can be used to force 
# Redis to log on the standard output. Note that if you use standard 
# output for logging but daemonize, logs will be sent to /dev/null 
logfile "" 

# To enable logging to the system logger, just set 'syslog-enabled' to yes, 
# and optionally update the other syslog parameters to suit your needs. 
# syslog-enabled no 

# Specify the syslog identity. 
# syslog-ident redis 

# Specify the syslog facility. Must be USER or between LOCAL0-LOCAL7. 
# syslog-facility local0

# Set the number of databases. The default database is DB 0, you can select 
# a different one on a per-connection basis using SELECT <dbid> where 
# dbid is a number between 0 and 'databases'-1 
databases 16 

# By default Redis shows an ASCII art logo only when started to log to the 
# standard output and if the standard output is a TTY. Basically this means 
# that normally a logo is displayed only in interactive sessions. 
# 
# However it is possible to force the pre-4.0 behavior and always show a 
# ASCII art logo in startup logs by setting the following option to yes. 
always-show-logo yes 

The general section contains many options including the ability to run as a “daemon” or background process. This is also where you can set the location of the log file, the log file verbosity and many other settings that affect your Redis server.

Is your WordPress site running slow? Checkout the optimized WordPress Hosting solutions from InMotion Hosting! You will find a solution that fits your budget and performance needs.

Snapshotting

################################ SNAPSHOTTING  ################################ 
# 
# Save the DB on disk: 
# 
#   save <seconds> <changes> 
# 
#   Will save the DB if both the given number of seconds and the given 
#   number of write operations against the DB occurred. 
# 
#   In the example below the behaviour will be to save: 
#   after 900 sec (15 min) if at least 1 key changed 
#   after 300 sec (5 min) if at least 10 keys changed 
#   after 60 sec if at least 10000 keys changed 
# 
#   Note: you can disable saving completely by commenting out all "save" lines. 
# 
#   It is also possible to remove all the previously configured save 
#   points by adding a save directive with a single empty string argument 
#   like in the following example: 
# 
#   save "" 
save 900 1 
save 300 10 
save 60 10000 

# By default Redis will stop accepting writes if RDB snapshots are enabled 
# (at least one save point) and the latest background save failed. 
# This will make the user aware (in a hard way) that data is not persisting 
# on disk properly, otherwise chances are that no one will notice and some 
# disaster will happen. 
# 
# If the background saving process will start working again Redis will 
# automatically allow writes again.
# 
# However if you have setup your proper monitoring of the Redis server 
# and persistence, you may want to disable this feature so that Redis will 
# continue to work as usual even if there are problems with disk, 
# permissions, and so forth. 
stop-writes-on-bgsave-error yes 

# Compress string objects using LZF when dump .rdb databases? 
# For default that's set to 'yes' as it's almost always a win. 
# If you want to save some CPU in the saving child set it to 'no' but 
# the dataset will likely be bigger if you have compressible values or keys. 
rdbcompression yes 

# Since version 5 of RDB a CRC64 checksum is placed at the end of the file. 
# This makes the format more resistant to corruption but there is a performance 
# hit to pay (around 10%) when saving and loading RDB files, so you can disable it 
# for maximum performances. 
# 
# RDB files created with checksum disabled have a checksum of zero that will 
# tell the loading code to skip the check. 
rdbchecksum yes 

# The filename where to dump the 
DB dbfilename dump.rdb 

# The working directory. 
# 
# The DB will be written inside this directory, with the filename specified 
# above using the 'dbfilename' configuration directive. 
# 
# The Append Only File will also be created inside this directory. 
# 
# Note that you must specify a directory here, not a file name. 
dir ./ 

In layman’s terms, snap-shotting is a form of data backup of the data used by Redis. This part of the configuration file allows you to configure the options for the snapshots that Redis can make.

Congratulations! You can now navigate to the location of the Redis configuration file and understand how the options are formatted. With this information, you can edit the file to meet your needs. If you’re looking to use Redis for WordPress, check out how to use Redis Object Cache for WordPress!

AC
Arnel Custodio Content Writer I

As a writer for InMotion Hosting, Arnel has always aimed to share helpful information and provide knowledge that will help solve problems and aid in achieving goals. He's also been active with WordPress local community groups and events since 2004.

More Articles by Arnel

Was this article helpful? Join the conversation!

Server Madness Sale
Score Big with Savings up to 99% Off

X