Chat Zalo Chat Messenger Phone Number Đăng nhập
How to Edit the Redis Configuration File - redis.conf - InMotion Hosting

How to Edit the Redis Configuration File – redis.conf – InMotion Hosting

Redis is configured by making changes to a configuration file named redis.conf. This file can be found in the root of the directory where you installed Redis. There is no need to edit the configuration file if you are simply going to test Redis, but if you are using it on a production server, you need to ensure that the configuration is optimized for your use. The redis.conf file contains documentation to help you configure it when you edit the file. We’ll show you how to get to the redis.conf file and then go through the first five settings listed within the file to acclimate you with the file.

These instructions require Redis to be installed on your VPS or dedicated server and you will need root access to the server via SSH.

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

Redis configuration file How to make changes to the Redis configuration file How to edit the Redis configuration file

– redis.conf

The

  • Redis
  • configuration

file

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

keyword argument1 argument2 … argumentN The

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

.

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

[email protected] [~] # cd redis-stable [email protected] [~/redis-stable] ls ./ 00-RELEASENOTES CONTRIBUTING deps/ INSTALL MANIFESTO redis.conf runtest-cluster* runtest-sentinel* src/ utils/ .. / COPY ERRORS . GITIGNORE Makefile README.md runtest* runtest-moduleapi* sentinel.conf tests/

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

[email protected] [~/redis-stable] vim redis.config

Redis

configuration settings

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

Includes

###### This is useful if # has a standard template that goes to all Redis servers, but you also need # to customize some configurations per server. Including files can include # other files, so use this wisely. # # The “include” warning option will not be rewritten using the administrator’s “CONFIG REWRITE” # command or Redis Sentinel. Because Redis always uses the last processed # line as the value of a configuration policy, you’d better place includes # at the beginning of this file to avoid overwriting the configuration change at run time. # # If 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 recommended in the previous text, make sure that any include entries are located at the top of the configuration file. This configuration is especially useful if you manage multiple Redis servers in the same way.

Modules

#### If the server cannot load the modules #, it will abort. You can 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. Be sure to read the documentation for the modules you want to use. Redis modules allow you to increase the functionality of Redis. For example, one of the most popular modules used for Redis is RediSearch, which allows full-text search on Redis.

Network

#### # It is possible to listen to only one or more selected interfaces using # the configuration directive “bind”, 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 # Internet, binding to all interfaces is dangerous and will expose instance # to all Internet users. So, by default, we uncheck the #following bind directive, which will force Redis to listen only on # for the IPv4 retrospective interface address (this means that Redis will be able to #accept connections only from clients running on the same computer that # is running). # # IF YOU ARE SURE THAT YOU WANT YOUR INSTANCE TO LISTEN FOR ALL INTERFACES # SIMPLY COMMENT OUT THE FOLLOWING LINE. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ address set using the # “bind” directive. #2) No password is set. # # The server only accepts connections from clients that connect from loopback addresses # IPv4 and IPv6 127.0.0.1 and ::1, and from sockets # of Unix domain. # # By default, protected mode is enabled. You should disable it only if # you are sure that you want clients from other hosts to connect to Redis # even if no authentication is configured, nor is a specific set of interfaces # explicitly enumerated using the “bind” directive. protected mode yes # Accept connections on the specified port, the default value 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 a high delay in order # to avoid slow client connection issues. Note that the Linux kernel # will silently truncate it to the value of /proc/sys/net/core/somaxconn, so # be sure to increase both the value of somaxconn and the tcp_max_syn_backlog# 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 hear # 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 nonzero, use SO_KEEPALIVE to send TCP ACK to clients in the absence of communication #. This is useful for two reasons: ##1) Detect dead pairs. #2) Take the live connection from the point of view of the network # team in the middle. # # On Linux, the specified value (in seconds) is the period used to send ACKs. # Please note that closing the connection takes twice as long. # In other cores the period depends on the configuration of the kernel. # # A reasonable value for this option is 300 seconds, which is the new default # Redis value 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 strongly recommend that you contact your host’s technical team if you are not familiar with performing any of these network configurations.

General

##### Use ‘yes’ if you need to. # Note that Redis will write a pid file to /var/run/redis.pid when daemonice. daemonize no # If you run Redis from upstart or systemd, Redis can interact with your # monitoring tree. Options: # supervised no – no supervision interaction # supervised upstart – signal upstart putting Redis in SIGSTOP mode # systemd supervised – systemd signal writing READY=1 to $NOTIFY_SOCKET # self-supervised – detect upstart or systemd method based on # UPSTART_JOB or NOTIFY_SOCKET environment variables # Note: These monitoring methods only indicate “the process is ready”. # They do not allow continuous life pings to their supervisor. monitored no # If a pid file is specified, Redis writes it where it is specified at startup # and deletes it on exit. # # When the server is running without daemons, no pid file is created if # is not specified in the configuration. When the server is demonized, the pid# file is used even if it is not specified, by default “/var/run/redis.pid”. # # Creating a pid file is the best effort: if Redis is not able to create it # nothing bad happens, the server will start and function normally. pidfile /var/run/redis_6379.pid # Specify the level of verbosity for the server. # This can be one of: # debug (lots of information, useful for development/testing) # verbose (a lot of information rarely useful, but not a disaster like debug level) # warning (moderately verbose, what you want in production probably) # warning (only very important/critical messages are logged) log level notice # Specify the name of the log file. Also the empty string can be used to force #Redis to log in to the standard output. Note that if you use the standard output # for logging but daemonize, the logs will be sent to /dev/null logfile “” # To enable logging at the system logger, simply set ‘syslog-enabled’ to yes, #, and optionally update the other syslog parameters to meet your needs. # syslog-enabled no # Specify the syslog identity. # syslog-ident redis # Specify the syslog function. It 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 per connection using SELECT <dbid> where # dbid is a number between 0 and ‘databases’-1 databases 16 # By default, Redis displays an ASCII art logo only when you start logging into standard output # and if the standard output is TTY. Basically this means # that normally a logo is displayed only in interactive sessions. # # However, it is possible to force the behavior prior to 4.0 and always display an art logo # ASCII in the startup records 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 log file location, log file verbosity, and many other settings that affect the Redis server.

Is your WordPress site running slow? Check out InMotion Hosting’s optimized WordPress Hosting solutions! You’ll find a solution that fits your budget and performance needs.

Snapshots

#### # Save the database to disk: # # save <seconds> <changes> # # You will save the database if the given number of seconds and the given # number of write operations to the database occurred. # # In the following example, the behavior will be saved: # after 900 seconds (15 minutes) if at least 1 key changed # after 300 seconds (5 minutes) if at least 10 keys changed # after 60 seconds 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 previously configured save # points by adding a save directive with a single empty string argument # as 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 last background save failed. # This will make the user aware (in a difficult way) that the data does not persist # on the disk properly, otherwise it is likely that no one will notice and some # disaster will occur. # # If the background save process starts working again, Redis # will automatically allow writes again. # # However, if you have configured your proper Redis server monitoring # and persistence, you may want to disable this feature so that Redis # continues to work as usual, even if there are problems with disk, # permissions, etc. stop-writes-on-bgsave-error yes # Compress string objects using LZF when dumping .rdb databases? # By default, that’s set to ‘yes’, as it’s almost always a win. # If you want to save some CPU in the child keeper, set it to ‘no’ but # the dataset will probably be larger if it has compressible values or keys. rdbcompression yes # Since RDB version 5 a CRC64 checksum is placed at the end of the file. # This makes the format more resistant to corruption, but there is a # hit to pay performance (around 10%) when saving and uploading RDB files, so you can disable it # for maximum performance. # # RDB files created with checksum disabled have a zero checksum that # will tell the upload code to skip verification. rdbchecksum yes # The file name where to dump the database dbfilename dump.rdb # The working directory. # # The database will be written within this directory, with the file name specified # above using the ‘dbfilename’ configuration directive. # # The Append Only file will also be created within this directory. # # Note that you must specify a directory here, not a file name. dir./

In simple terms, snap-shotting is a way of backing up data used by Redis. This part of the configuration file allows you to configure options for snapshots that Redis can create.

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!

Contact US