天天看点

ROLE

Provide information on the role of a Redis instance in the context of replication, by returning if the instance is currently a <code>master</code>, <code>slave</code>, or <code>sentinel</code>. The command also returns additional information about the state of the replication (if the role is master or slave) or the list of monitored master 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:

“master”

“slave”

“sentinel”

The additional elements of the array depends on the role.

An example of output when <code>ROLE</code> is called in a master instance:

The master output is composed of the following parts:

The string <code>master</code>.

The current master replication offset, which is an offset that masters and slaves share to understand, in partial resynchronizations, the part of the replication stream the slave needs to fetch to continue.

An array composed of three elements array representing the connected slaves. Every sub-array contains the slave IP, port, and the last acknowledged replication offset.

An example of output when <code>ROLE</code> is called in a slave instance:

The slave output is composed of the following parts:

The string <code>slave</code>.

The IP of the master.

The port number of the master.

The state of the replication from the point of view of the master, that can be <code>connect</code> (the instance needs to connect to its master), <code>connecting</code> (the slave-master connection is in progress), <code>sync</code> (the master and slave are trying to perform the synchronization), <code>connected</code> (the slave is online).

The amount of data received from the slave so far in terms of master replication offset.

An example of Sentinel output:

The sentinel output is composed of the following parts:

The string <code>sentinel</code>.

An array of master names monitored by this Sentinel instance.

@return

@array-reply: where the first element is one of <code>master</code>, <code>slave</code>, <code>sentinel</code> and the additional elements are role-specific as illustrated above.

@history

This command was introduced in the middle of a Redis stable release, specifically with Redis 2.8.12.

@examples

本文作者:陈群

本文来自云栖社区合作伙伴rediscn,了解相关信息可以关注redis.cn网站。

继续阅读