Redis CLIENT LIST 命令用于返回所有连接到服务器的客户端信息和统计数据。
从 v5.0 起,TYPE type 子命令可以用来过滤客户端类型,type 可以是 normal, master, replica 或pubsub。
注意,被 MONITOR 阻塞的客户端被归类为 normal 类型。
*返回值
- 每个已连接客户端对应一行(以 换行 分割)
- 每行字符串由一系列 属性=值(
property=value) 形式的域组成,每个域之间以空格分开。
各个域 field 的含义解释:
id: 唯一的64位的客户端ID(Redis 2.8.12加入)name: the name set by the client with CLIENT SETNAMEaddr: 客户端的地址和端口fd: 套接字所使用的文件描述符age: 以秒计算的已连接时长idle: 以秒计算的空闲时长flags: 客户端 flag (see below)db:该客户端正在使用的数据库 IDsub: 已订阅频道的数量psub: 已订阅模式的数量multi: 在事务中被执行的命令数量qbuf: 查询缓冲区的长度(字节为单位, 0 表示没有分配查询缓冲区)qbuf-free: 查询缓冲区剩余空间的长度(字节为单位, 0 表示没有剩余空间)obl: 输出缓冲区的长度(字节为单位, 0 表示没有分配输出缓冲区)oll: 输出列表包含的对象数量(当输出缓冲区没有剩余空间时,命令回复会以字符串对象的形式被入队到这个队列里)omem: 输出缓冲区占用的内存总量events: 文件描述符事件 (see below)cmd: 最近一次执行的命令argv-mem: incomplete arguments for the next command (already extracted from query buffer)tot-mem: 客户端所有缓存占用的内存量
客户端 flag 可以是一个或几个组合:
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
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 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
R: the client tracking target client is invalid
文件描述符事件可以是:
r: 客户端套接字(在事件 loop 中)是可读的(readable)
w: 客户端套接字(在事件 loop 中)是可写的(writeable)
*注意
新字段会随着测试有规律的添加。某些字段将来可能会被删除。一个版本安全的Redis客户端使用这个命令时应该根据字段解析相应内容。(比如:处理未知的字段,应跳过该字段)。