命令介绍
Server 族命令用于服务端状态查询、配置管理与运维操作,是 DBA 和运维人员日常管理实例的核心工具集。其核心命令按功能可分为以下六类:
服务端状态查询
INFO:返回服务器各模块的运行统计信息(内存、CPU、客户端连接数、持久化状态、复制状态等),是最常用的全量诊断入口。
DBSIZE:返回当前数据库的键总数。
TIME:返回服务器当前时间戳。
LASTSAVE:返回最后一次 RDB 持久化的时间戳。
ROLE:返回当前节点在复制拓扑中的角色信息。
配置与参数管理
CONFIG GET / CONFIG SET:在运行时读取或动态修改服务端配置参数(SET 在管控类实例中通常受限)。
CONFIG REWRITE:将运行时修改的配置持久化写入配置文件。
CONFIG RESETSTAT:重置 INFO 统计计数器。
性能诊断与慢查询分析
SLOWLOG GET / SLOWLOG LEN / SLOWLOG RESET:查询、统计或清空慢查询日志,是排查性能问题的核心工具。
LATENCY(DOCTOR / GRAPH / HELP / HISTORY / LATEST / RESET):分析延迟事件,辅助性能调优。
命令信息查询
COMMAND / COMMAND COUNT / COMMAND INFO / COMMAND GETKEYS / COMMAND GETKEYSANDFLAGS / COMMAND DOCS / COMMAND LIST:查询命令列表、命令参数、键提取规则和命令文档等元信息。
数据库级别操作
FLUSHDB / FLUSHALL:清空当前数据库或全部数据库(在管控类实例中通常受限)。
MONITOR:实时输出服务端接收到的每一条命令(仅标准架构,适用于调试阶段)。
持久化与客户端管理
BGSAVE / BGREWRITEAOF / SAVE:触发后台或前台持久化操作。
CLIENT LIST / CLIENT KILL / CLIENT PAUSE / CLIENT REPLY / CLIENT ID:管理客户端连接,查询或中断指定客户端。
命令支持概览
基础命令:
client list、client getname、client setname、command count、command info、command、config rewrite、config resetstat、config get、role、lastsave、dbsize、info、time、flushdb、flushall,Redis 2.8标准架构及4.0、5.0、6.2、7.0版本、Valkey 8.0、9.0的标准架构与集群架构均支持。高版本新增命令:
command getkeysandflags、command docs、command list,仅 Redis 7.0 版本及 Valkey 8.0、9.0版本支持。仅标准架构支持:
memory、slowlog 仅在标准架构下支持,集群架构不支持。monitor 在 Redis 6.2 版本暂不支持,其他版本仅标准架构支持。仅集群架构支持:
cluster keyslot、cluster nodes、cluster getkeysinslot、cluster slots、cluster info、cluster countkeysinslot 仅集群架构支持。cluster shards 仅 Redis 7.0 及 Valkey 8.0、9.0的标准与集群架构支持。其他 cluster 子命令在所有版本均不支持。版本限定命令:
command getkeys 在 Redis 2.8 不支持;lolwut 仅 Redis 5.0 及以上版本支持。全局不支持的命令:
bgrewriteaof、bgsave、client kill、sync、psync、client pause、client reply、slaveof、config set、debug object、debug segfault、save、shutdown、module、failover、slowlog help 及全部 acl 系列命令。跨 Slot 限制:Server 族命令不存在跨 Slot 访问场景。
命令兼容性矩阵
Server 族命令在各版本与架构下的支持情况如下表所示(✓ 表示支持,✗ 表示不支持,— 表示该命令不存在跨 Slot 访问场景)。
说明:
monitor 命令在 Redis 6.2 版本中暂停支持,6.2之前的版本(4.0、5.0、2.8)标准架构支持。memory 与 slowlog 仅在标准架构下可用。cluster shards 仅在 Redis 7.0 及 Valkey 8.0、9.0 中支持。全部
acl 系列命令在所有版本与架构中均不支持。命令 | Valkey 9.0标准架构 | Valkey 9.0集群架构 | Redis 7.0/Valkey 8.0标准架构 | Redis 7.0/Valkey 8.0集群架构 | Redis 6.2标准架构 | Redis 6.2集群架构 | Redis 5.0标准架构 | Redis 5.0集群架构 | Redis 4.0标准架构 | Redis 4.0集群架构 | Redis 2.8标准架构 | 集群架构跨 Slot 支持 |
bgrewriteaof | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | — |
bgsave | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | — |
client kill | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | — |
sync | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | — |
psync | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | — |
client list | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | — |
client getname | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | — |
client pause | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | — |
client reply | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | — |
client setname | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | — |
command count | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | — |
command getkeys | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✗ | — |
command info | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | — |
command getkegysandflags | ✓ | ✓ | ✓ | ✓ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | — |
command docs | ✓ | ✓ | ✓ | ✓ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | — |
command list | ✓ | ✓ | ✓ | ✓ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | — |
slaveof | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | — |
config rewrite | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | — |
config set | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | — |
config resetstat | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | — |
debug object | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | — |
debug segfault | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | — |
role | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | — |
save | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | — |
lastsave | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | — |
shutdown | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | — |
memory | ✗ | ✗ | ✗ | ✗ | ✓ | ✗ | ✓ | ✗ | ✓ | ✗ | ✗ | — |
command | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | — |
dbsize | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | — |
info | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | — |
time | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | — |
config get | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | — |
monitor | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✓ | ✓ | ✓ | ✓ | ✓ | — |
flushdb | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | — |
flushall | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | — |
slowlog | ✓ | ✗ | ✓ | ✗ | ✓ | ✗ | ✓ | ✗ | ✓ | ✗ | ✓ | — |
module | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | — |
lolwut | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✗ | ✗ | ✗ | — |
acl cat | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | — |
acl deluser | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | — |
acl genpass | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | — |
acl help | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | — |
acl list | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | — |
acl load | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | — |
acl log | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | — |
acl save | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | — |
acl setuser | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | — |
acl users | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | — |
acl whoami | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | — |
failover | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | — |
slowlog help | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | — |