CLIENT TRACKING ON|OFF [REDIRECT client-id] [PREFIX prefix [PREFIX prefix ...]] [BCAST] [OPTIN] [OPTOUT] [NOLOOP]

Redis CLIENT TRACKING 命令启用Redis服务器的跟踪功能,该功能用于服务器辅助的客户端缓存

启用跟踪后,Redis会记住连接请求过的key,以便在修改此类key时发送无效消息给客户端。

无效消息在同一连接中发送(仅在使用RESP3协议时可用)或在另一个不同的连接中(也可在RESP2和Pub / Sub中使用)。

特殊的广播模式,参与此协议的客户端仅订阅给定的key前缀就可以接收每个通知,而与他们请求的key无关。

考虑到参数的复杂性,请参考客户端缓存文档了解详细信息。

为了启用跟踪,请使用:

CLIENT TRACKING on ... options ...

使用 CLIENT TRACKING off 停止跟踪。

参数详解:

  • REDIRECT <id>: send redirection messages to the connection with the specified ID. The connection must exist, you can get the ID of such connection using CLIENT ID. If the connection we are redirecting to is terminated, when in RESP3 mode the connection with tracking enabled will receive tracking-redir-broken push messages in order to signal the condition.
  • BCAST: enable tracking in broadcasting mode. In this mode invalidation messages are reported for all the prefixes specified, regardless of the keys requested by the connection. Instead when the broadcasting mode is not enabled, Redis will track which keys are fetched using read-only commands, and will report invalidation messages only for such keys.
  • PREFIX <prefix>: for broadcasting, register a given key prefix, so that notifications will be provided only for keys starting with this string. This option can be given multiple times to register multiple prefixes. If broadcasting is enabled without this option, Redis will send notifications for every key.
  • OPTIN: when broadcasting is NOT active, normally don't track keys in read only commands, unless they are called immediately after a CLIENT CACHING yes command.
  • OPTOUT: when broadcasting is NOT active, normally track keys in read only commands, unless they are called immediately after a CLIENT CACHING no command.
  • NOLOOP: don't send notifications about keys modified by this connection itself.

*返回值

字符串: OK 连接进入跟踪模式,或退出跟踪模式。其它情况返回错误。