本文内容为 http://redis.io/commands/config-set 的翻译、注解、例子扩充及其它修改。感谢 Redis 作者 Antirez 为开源社区作出的贡献,本文保证最新、最准、最全以表示对其的敬意。欢迎留言纠错、提示更新或支持。
CONFIG SET parameter value

当前命令用于对正在运行的服务端进行动态重配置(Reconfigure),而不需要重启 Redis

The CONFIG SET command is used in order to reconfigure the server at run time without the need to restart Redis.

你可以用它来修改一些无关紧要的配置,也可以用它来修改复杂配置,比如将一个持久化(Persistence )选项切换到另一个选项。

You can change both trivial parameters or switch from one to another persistence option using this command.

可以通过命令 CONFIG GET * 获得所有支持 CONFIG SET 的配置参数。

所有使用 CONFIG SET 修改的配置参数将会被立即加载进 Redis,且直接影响下一条命令的执行。

All the configuration parameters set using CONFIG SET are immediately loaded by Redis and will take effect starting with the next command executed.

所有已支持的参数与配置文件 redis.conf 中的对应配置参数有相同的含义,除了以下几处重要的不同:

  • 对于配置指令中的基本单位,比如描述字节(Bytes)或其它数量(Quantity)时,不能够像 redis.conf 中那样使用缩写格式(10k20gb),需全部使用格式良好(Well-formed)的 64 位整数。
  • 指令 save 的参数为由空格所分隔的整数所组成的字符串。每对整数代表一个秒数/修改(Seconds/Modifications)阀值(Threshold)
All the supported parameters have the same meaning of the equivalent configuration parameter used in the redis.conf file, with the following important differences:
  • Where bytes or other quantities are specified, it is not possible to use the redis.conf abbreviated form (10k 2gb ... and so forth), everything should be specified as a well-formed 64-bit integer, in the base unit of the configuration directive.
  • The save parameter is a single string of space-separated integers. Every pair of integers represent a seconds/modifications threshold.

比如在 redis.conf 文件中存在如下配置:

save 9001
save 30010

CONFIG GET 将返回 “900 1 300 10”。

可以通过当前命令将持久化模式从 RDB 快照切换到 AOF 模式(反之亦然)。

It is possible to switch persistence from RDB snapshotting to append-only file (and the other way around) using the CONFIG SET command. For more information about how to do that please check the persistence page.

此时你需要注意:

In general what you should know is that setting the appendonly parameter to yes will start a background process to save the initial append-only file (obtained from the in memory data set), and will append all the subsequent commands on the append-only file, thus obtaining exactly the same effect of a Redis server that started with AOF turned on since the start.

You can have both the AOF enabled with RDB snapshotting if you want, the two options are not mutually exclusive.

  • 当配置被正常写入时,返回 OK

    否则,将会返回一个错误。

    Simple string reply: OK when the configuration was set properly. Otherwise an error is returned.
  • 版本支持

    2.0.0+