html role w3c,role_Redis_w3cschool

本文介绍Redis中的ROLE命令,用于查询实例的角色(主、从或哨兵)。文章详细解释了不同角色下返回的数据格式及含义,并提供了具体的输出示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ROLE

ROLE

Available since 2.8.12.

Provide information on the role of a Redis 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 master or slave) or the list of monitored master names (if the role is sentinel).

Output format

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.

Master output

An example of output when ROLE is called in a master instance: 1) .html?lang=en"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 master output is composed of the following parts: The string master.

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.

Slave output

An example of output when ROLE is called in a slave instance: 1) .html?lang=en"slave"

2) "127.0.0.1"

3) (integer) 9000

4) "connected"

5) (integer) 3167038

The slave output is composed of the following parts: The string slave.

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 connect (the instance needs to connect to its master), connecting (the slave-master connection is in progress), sync (the master and slave are trying to perform the synchronization), connected (the slave is online).

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

Sentinel output

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: The string sentinel.

An array of master names monitored by this Sentinel instance.

Return value

Array reply: where the first element is one of master, slave, sentinel 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

redis> ROLE 1) "master"

2) (integer) 0

3) (empty list or set)

© 2009–2017 Salvatore Sanfilippo

Licensed under the Creative Commons Attribution-ShareAlike License 4.0.

https://redis.io/commands/role

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值