Redis Server Configuration

Source: Internet
Author: User
Tags unsupported

The redis server provides some configuration options. By modifying the values of these options, you can change the functions of the options.

For example, when we introduced the SELECT command, we once said that by default, the redis server will create a total of 16 databases from 0 to 15 for users to use. However, the number of databases on the redis server is not static, redis provides the databases option, which defaults to 16. By modifying the value of this option, we can ask the server to create a specified number of databases, for example, five, ten, 32, and 100,

When a Lua script is used, if it takes too long to run, you can use the script kill command to force the script to stop, the value of the LUA-time-limit option determines the maximum number of milliseconds that the script can run without interruption. If the value of this option is 5000, then, the server will begin to accept the script kill command only after the script running time exceeds 5000 milliseconds, allowing the user to end the running script. If necessary, you can reduce or increase the value of this option.

 

Modify and obtain the value of configuration options

Method 1: Specify parameters

When starting the server, you can set a value for the configuration options by specifying the parameters. The format is:

$ redis-server --<option1> <value1> --<option2> <value2> --<option3> <value3> ...

For example, if the following parameters are specified to start the redis server, the server will create 32 databases:

$ redis-server --databases 32

Given the following parameters, the server can create 100 databases and set the server port to 10086:

$ redis-server --databases 100 --port 10086

Method 2: Specify the configuration file

The values of the configuration options and options to be modified are recorded in a configuration file and loaded to the configuration file when the server is started. Format:

$ redis-server <path-to-config-file>

We can create a configuration file redis. conf that contains the following content:

databases 128port 10086

When the server is started, let the server load the file:

$ redis-server redis.conf

Then, the started server will create 128 databases and use port 10086 to listen to client connection requests.

Method 3: Use the config command

Both methodsThe configuration option value can only be modified when the server is started.By using the config commands, You can dynamically modify the value of the option when the server is running, or obtain the current value of the option through the command.
You can use the config GET command to obtain the current value of the option. The format of this command is:

CONFIG GET <option>

For example, run the following command to return the maximum normal execution time of the Lua script currently set on the server:

redis> CONFIG GET lua-time-limit1) "lua-time-limit"2) "5000"

You can use the config set command to modify the value of the configuration option. The format of this command is:

CONFIG SET <option> <value>

For example, run the following command to change the maximum normal execution time of the Lua script from 5000 to 3000:

redis> CONFIG SET lua-time-limit 3000OK

Run the config GET command to check whether the setting is successful:

redis> CONFIG GET lua-time-limit1) "lua-time-limit"2) "3000"

Note:
Note the following when using config set,Not all configuration options can be set dynamically during server running.Some configuration options can be set only when the server is started.
For example, because database creation is performed at server startup, the number of databases must be specified at server startup. During server running, it is not feasible to try to use config set to modify the number of databases:

redis> CONFIG SET databases 100(error) ERR Unsupported CONFIG parameter: databases

Another example is the listening port number used by the server. This option cannot be set even if the server is already running:

redis> CONFIG SET port 10086(error) ERR Unsupported CONFIG parameter: port

In config set, note the following,The option value set in config set takes effect only when the server is running.Once the server is shut down, the option value set in config set will be lost.
For example, the default value of the LUA-time-limit option is 5000. Although you can change the value of the option to 3000 through config set LUA-time-limit 3000, however, this modification will only be valid in the current running of the server. Once the server is shut down and restarted, the value of the luatime-limit option will be changed back to the default value of 5000.

Redis> config set LUA-time-limit 3000 okredis> config get lua-time-limit1) "LUA-time-limit" 2) "3000" redis> config get LUA-time-limit # execute 1 After restarting the server) "LUA-time-limit" 2) "5000"

Config rewrite command
IfThe server loads the configuration file at startup.And use config set to modify the value of configuration options when the server is running. Then, run the config rewrite command to write the modified configuration options and values to the configuration file.
For example, if the server is started with a configuration file containing the following content:

databases 32lua-time-limit 5000

If the user executes the config set LUA-time-limit 3000 command while the server is running and intends to record the modification to the configuration file, then, you can run the config rewrite command to modify the content of the configuration file:

databases 32lua-time-limit 3000

In this way, the server will continue to set the maximum normal running time of the Lua script to 3000 milliseconds when the configuration file is started and loaded next time.

 

Some basic configuration options

For more configuration information, see the redis. conf configuration file.

 

Summary

Three methods for setting configuration options:

1) when the server is started, it is set by parameters in the format of $ redis-server -- <option> <value>;

2) When the server is started, specify the configuration file in the format of $ redis-server <path-to-config-File>;

3) when running on the server, use the config set <option> <value> command.

Note that,Not all configuration options are availableConfig setTo modifySome options can only be set when the server is started. If config rewrite is not used, the options set by config set will be lost after the server is disabled.

Use the config get <option> command to obtain the current value of the configuration option.

If the server loads the configuration file at startup and you use config set to modify the values of some options during server running, you only need to use the config rewrite command, you can record the configuration set changes to the configuration file so that the server can be used at the next startup.

 

 

 

 

Reference: huangz

Redis Server Configuration

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.