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

当前命令将会产生如下行为:

  • 停止与所有客户端(Client)的连接。
  • 如果配置了至少一个保存点(Save point),则进行一次阻塞式(Blocking)保存操作。
  • 如果开启了 AOF 机制,更新 AOF 文件。
  • 停止(Quit)服务端(Server)
The command behavior is the following:
  • Stop all the clients.
  • Perform a blocking SAVE if at least one save point is configured.
  • Flush the Append Only File if AOF is enabled.
  • Quit the server.

如果开启了持久化(Persistence),当前命令保证 Redis 在被关闭掉时,不丢失任何数据。如果客户端仅仅通过先使用命令 SAVE 然后使用命令 QUIT 将不能保证该点,因为在两条命令中间,可能会有其它客户端修改了数据库。

If persistence is enabled this commands makes sure that Redis is switched off without the lost of any data. This is not guaranteed if the client uses simply SAVE and then QUIT because other clients may alter the DB data between the two commands.

注意 如果一个实例被配置为非持久化(未配置 AOF,且无 save 指令),在执行 SHUTDOWN 时,将不会 dump RDB 文件,因为你通常不想仅仅用作缓存的 Redis 实例在关闭时阻塞你的应用。

Note: A Redis instance that is configured for not persisting on disk (no AOF configured, nor "save" directive) will not dump the RDB file on SHUTDOWN, as usually you don't want Redis instances used only for caching to block on when shutting down.
  • 出错时返回简单字符串响应,一旦成功,将不会返回任何信息,因为这个时候服务端已经退出,所有连接已被关闭。

    Simple string reply on error. On success nothing is returned since the server quits and the connection is closed.
  • 可以指定可选修饰符以修改当前命令的行为:

    • SHUTDOWN SAVE 强制进行一次数据库保存操作,即使未配置任何保存点。
    • SHUTDOWN NOSAVE 阻止数据库进行保存操作,即使配置了一个或多个保存点。
    It is possible to specify an optional modifier to alter the behavior of the command. Specifically:
    • SHUTDOWN SAVE will force a DB saving operation even if no save points are configured.
    • SHUTDOWN NOSAVE will prevent a DB saving operation even if one or more save points are configured. (You can think at this variant as an hypothetical ABORT command that just stops the server).
  • 版本支持

    1.0.0+