Returns the replication role.
ROLE
Provide information on the role of a Valkey instance in the context
of replication, by returning if the instance is currently a
master
, slave
, or sentinel
. The
command also returns additional information about the state of the
replication (if the role is primary or replica) or the list of monitored
primary names (if the role is sentinel).
The command returns an array of elements. The first element is the role of the instance, as one of the following three strings:
The additional elements of the array depends on the role.
An example of output when ROLE
is called in a primary
instance:
1) "master"
2) (integer) 3129659
3) 1) 1) "127.0.0.1"
2) "9001"
3) "3129242"
2) 1) "127.0.0.1"
2) "9002"
3) "3129543"
The primary output is composed of the following parts:
master
.An example of output when ROLE
is called in a replica
instance:
1) "slave"
2) "127.0.0.1"
3) (integer) 9000
4) "connected"
5) (integer) 3167038
The replica output is composed of the following parts:
slave
, because of Redis OSS compatibility
(see note at the end of this page).connect
(the instance needs to connect to its
primary), connecting
(the primary-replica connection is in
progress), sync
(the primary and replica are trying to
perform the synchronization), connected
(the replica is
online).An example of Sentinel output:
1) "sentinel"
2) 1) "resque-master"
2) "html-fragments-master"
3) "stats-master"
4) "metadata-master"
The sentinel output is composed of the following parts:
sentinel
.Array reply: where the
first element is one of master
, slave
, or
sentinel
, and the additional elements are role-specific as
illustrated above.
O(1)
@admin @dangerous @fast
127.0.0.1:6379> ROLE
1) "master"
2) (integer) 0
3) (empty array)
A note about the word slave used in this man page: If not for backward compatibility, the Valkey project no longer uses the words “master” and “slave”. Unfortunately in the given commands these words are part of the protocol, so we’ll be able to remove such occurrences only when this API will be naturally deprecated.
ACL, ACL CAT, ACL DELUSER, ACL DRYRUN, ACL GENPASS, ACL GETUSER, ACL HELP, ACL LIST, ACL LOAD, ACL LOG, ACL SAVE, ACL SETUSER, ACL USERS, ACL WHOAMI, BGREWRITEAOF, BGSAVE, COMMAND, COMMAND COUNT, COMMAND DOCS, COMMAND GETKEYS, COMMAND GETKEYSANDFLAGS, COMMAND HELP, COMMAND INFO, COMMAND LIST, CONFIG, CONFIG GET, CONFIG HELP, CONFIG RESETSTAT, CONFIG REWRITE, CONFIG SET, DBSIZE, DEBUG, FAILOVER, FLUSHALL, FLUSHDB, INFO, LASTSAVE, LATENCY, LATENCY DOCTOR, LATENCY GRAPH, LATENCY HELP, LATENCY HISTOGRAM, LATENCY HISTORY, LATENCY LATEST, LATENCY RESET, LOLWUT, MEMORY, MEMORY DOCTOR, MEMORY HELP, MEMORY MALLOC-STATS, MEMORY PURGE, MEMORY STATS, MEMORY USAGE, MODULE, MODULE HELP, MODULE LIST, MODULE LOAD, MODULE LOADEX, MODULE UNLOAD, MONITOR, PSYNC, REPLCONF, REPLICAOF, RESTORE-ASKING, SAVE, SHUTDOWN, SLOWLOG, SLOWLOG GET, SLOWLOG HELP, SLOWLOG LEN, SLOWLOG RESET, SWAPDB, SYNC, TIME.