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

CLIENT PAUSE 是一条连接控制命令,它能够将所有 Redis 客户端挂起指定的一段时间(以毫秒为单位)。

CLIENT PAUSE is a connections control command able to suspend all the Redis clients for the specified amount of time (in milliseconds).

该命令将会进行以下几步操作:

  • 停止处理所有正在挂起的普通或 pub/sub 命令。然而,与从节点(Slave)之前的交互仍然会继续进行。
  • 命令以最快的速度直接返回 OK,所以其不会被自身所停止。
  • 当指定的过期时间到期时,所有客户端将被解除阻塞(Unblock):这个时候将会触发对各个客户端的请求缓存中所有累积命令的执行。
  • It stops processing all the pending commands from normal and pub/sub clients. However interactions with slaves will continue normally.
  • However it returns OK to the caller ASAP, so the CLIENT PAUSE command execution is not paused by itself.
  • When the specified amount of time has elapsed, all the clients are unblocked: this will trigger the processing of all the commands accumulated in the query buffer of every client during the pause.

这条命令非常有用,因为它使得能够按一种可控的方式将客户端从一个 Redis 实例(Instance)切按到另一个实例。

This command is useful as it makes able to switch clients from a Redis instance to another one in a controlled way.

比如在一次实例升级过程中,管理员可以进行以下操作:

  • Pause the clients using CLIENT PAUSE
  • Wait a few seconds to make sure the slaves processed the latest replication stream from the master.
  • Turn one of the slaves into a master.
  • Reconfigure clients to connect with the new master.
It is possible to send CLIENT PAUSE in a MULTI/EXEC block together with the INFO replication command in order to get the current master offset at the time the clients are blocked. This way it is possible to wait for a specific offset in the slave side in order to make sure all the replication stream was processed.
  • 简单字符串响应,可能返回 OK 或当 timeout 无效时返回一个错误。

    Simple string reply: The command returns OK or an error if the timeout is invalid.
  • 版本支持

    2.9.50+

    时间复杂度(Time complexity)

    O(1)