CLIENT LIST

列出打开的连接。

语法

CLIENT LIST [TYPE ] [ID client-id [client-id ...]]

引入版本:2.4.0

复杂度摘要:O(N)

CLIENT LIST 命令以大多数人类可读的格式返回有关客户端连接服务器的信息和统计信息。

您可以使用可选子命令之一来过滤列表。 TYPE type 子命令按客户端类型过滤列表,其中 类型 是 normal、master、replica 和 pubsub 之一。请注意,被 MONITOR 命令阻止的客户端属于 normal 类。

ID 过滤器仅返回 ID 与 client-id 参数匹配的客户端条目。

可选参数

TYPE NORMAL | MASTER | REPLICA | PUBSUB

仅列出给定类型的客户端。

ID client-id [client-id ...]

仅列出具有给定 ID 的客户端。

详细说明

返回信息

  • id:唯一的 64 位客户端 ID。
  • addr:客户端的地址/端口。
  • laddr:客户端连接的本地地址/端口(绑定地址)。
  • fd:socket对应的文件描述符。
  • name:客户端用CLIENT SETNAME设置的名称。
  • age:连接的总持续时间(以秒为单位)。
  • idle:连接的空闲时间(以秒为单位)。
  • flags:客户端标志(见下文)。
  • db:当前数据库ID。
  • sub:频道订阅数。
  • psub:模式匹配订阅的数量。
  • ssub:分片通道订阅数量。 Redis 7.0.3 中添加。
  • multi:MULTI/EXEC 上下文中的命令数量。
  • watch:该客户端当前正在观看的键数量。 Redis 7.4 中添加。
  • qbuf:查询缓冲区长度(0 表示没有查询待处理)。
  • qbuf-free:查询缓冲区的可用空间(0 表示缓冲区已满)。
  • argv-mem:下一个命令的参数不完整(已从查询缓冲区中提取)。
  • multi-mem:内存被缓冲的多重命令用完。 Redis 7.0 中添加。
  • obl:输出缓冲区长度。
  • oll:输出列表长度(当缓冲区已满时,回复将在此列表中排队)。
  • omem:输出缓冲存储器使用情况。
  • tot-mem:该客户端在其各个缓冲区中消耗的总内存。
  • events:文件描述符事件(见下文)。
  • cmd:最后播放的命令。
  • user:经过验证的客户端用户名。
  • redir:当前客户端跟踪重定向的客户端ID。
  • resp:客户端RESP协议版本。 Redis 7.0 中添加。
  • rbp:自客户端连接以来客户端读取缓冲区的峰值大小。 Redis 7.0 中添加。
  • rbs:客户端读取缓冲区的当前大小(以字节为单位)。 Redis 7.0 中添加。
  • lib-name - 正在使用的客户端库的名称。
  • lib-ver - 客户端库的版本。
  • io-thread:分配给客户端的I/O线程的id。 Redis 8.0 中添加。
  • tot-net-in:从此客户端读取的总网络输入字节数。
  • tot-net-out:发送到该客户端的网络输出字节总数。
  • tot-cmds:该客户端执行的命令总数。
  • read-events:该客户端的读取事件数。 Redis 8.8 中添加
  • parse-batch-cmd-sum:该客户端的所有解析批次中解析的命令的累积数量。 Redis 8.8 中添加
  • parse-batch-cnt:该客户端的解析批次总数。将 parse-batch-cmd-sum 除以该值即可得到每批客户端的平均命令。 Redis 8.8 中添加

客户端标志可以是以下组合:

A: connection to be closed ASAP
b: the client is waiting in a blocking operation
c: connection to be closed after writing entire reply
d: a watched keys has been modified - EXEC will fail
e: the client is excluded from the client eviction mechanism
g: the client is responsible for migrating slots (atomic slot migration)
i: the client is waiting for a VM I/O (deprecated)
M: the client is a master
N: no specific flag set
o: the client is responsible for importing slots (atomic slot migration)
O: the client is a client in MONITOR mode
P: the client is a Pub/Sub subscriber
r: the client is in readonly mode against a cluster node
S: the client is a replica node connection to this instance
u: the client is unblocked
U: the client is connected via a Unix domain socket
x: the client is in a MULTI/EXEC context
t: the client enabled keys tracking in order to perform client side caching
T: the client will not touch the LRU/LFU of the keys it accesses
R: the client tracking target client is invalid
B: the client enabled broadcast tracking mode

文件描述符事件可以是:

r: the client socket is readable (event loop)
w: the client socket is writable (event loop)

定期添加新字段以用于调试目的。有些可能会在将来被删除。使用此命令的版本安全 Redis 客户端应相应地解析输出(即优雅地处理缺失字段、跳过未知字段)。

Redis Software 与 Redis Cloud 兼容性

Redis
软件
Redis
Cloud
说明
✅ 标准
✅ 主动-主动
✅ 标准
✅ 主动-主动

返回值

RESP2

批量字符串回复:有关客户端连接的信息和统计信息。

RESP3

批量字符串回复:有关客户端连接的信息和统计信息。

资料来源:Redis 官方 CLIENT LIST 文档;中文内容参考 Redis 文档许可。