Redis Config rewrite 命令

Redis 服務器

Redis Config rewrite 命令對啟動 Redis 服務器時所指定的 redis.conf 配置文件進行改寫。

CONFIG SET 命令可以對服務器的當前配置進行修改, 而修改后的配置可能和 redis.conf 文件中所描述的配置不一樣, CONFIG REWRITE 的作用就是通過盡可能少的修改, 將服務器當前所使用的配置記錄到 redis.conf 文件中。

語法

redis Config rewrite 命令基本語法如下:

redis 127.0.0.1:6379> CONFIG REWRITE parameter

可用版本

>= 2.8.0

返回值

一個狀態(tài)值:如果配置重寫成功則返回 OK ,失敗則返回一個錯誤。

實例

以下是執(zhí)行 CONFIG REWRITE 前, 被載入到 Redis 服務器的 redis.conf 文件中關(guān)于 appendonly 選項的設置:

# ... 其他選項

appendonly no

# ... 其他選項

在執(zhí)行以下命令之后:

127.0.0.1:6379> CONFIG GET appendonly           # appendonly 處于關(guān)閉狀態(tài)
1) "appendonly"
2) "no"

127.0.0.1:6379> CONFIG SET appendonly yes       # 打開 appendonly
OK

127.0.0.1:6379> CONFIG GET appendonly
1) "appendonly"
2) "yes"

127.0.0.1:6379> CONFIG REWRITE                  # 將 appendonly 的修改寫入到 redis.conf 中
OK

重寫后的 redis.conf 文件中的 appendonly 選項將被改寫:

# ... 其他選項

appendonly yes

# ... 其他選項

Redis 服務器