# ROLE

> Return whether this server is a primary or a replica, with its replication state.

URL: https://docs.hotkv.com/commands/role/

```
ROLE
```

- Group: Server
- Complexity: O(N) where N is the number of replicas
- HotKV Cloud: all plans
- On-Premise: no license needed

`ROLE` tells a client whether it is talking to a primary or a replica, and
gives the replication details that go with it. Client libraries and proxies
use it to find the primary. As in Redis, the roles are reported as `master`
and `slave`.

## Return value

An array, in RESP2 and RESP3, whose first element is the role.

On a primary, three elements:

1. `master`
2. The replication offset, an integer.
3. An array with one entry per connected replica: its IP address, the port
   its clients use, and its acknowledged offset, all as bulk strings.

On a replica, five elements:

1. `slave`
2. The primary's host.
3. The primary's client port, an integer.
4. The link state: `connecting` (connecting to the primary), `sync` (receiving
   the full data set), `connected` (streaming changes), or `connect` (not
   connected).
5. The replication offset applied, an integer.

## Examples

On a primary with one replica:

```
127.0.0.1:6379> ROLE
1) "master"
2) (integer) 3129659
3) 1) 1) "10.0.0.6"
      2) "6379"
      3) "3129545"
```

On its replica:

```
10.0.0.6:6379> ROLE
1) "slave"
2) "10.0.0.5"
3) (integer) 6379
4) "connected"
5) (integer) 3129659
```

## Compatibility

Same reply shapes as Redis 7 and Valkey 8 for primaries and replicas. HotKV
has no Sentinel, so the `sentinel` role never appears.

## See also

[INFO](https://docs.hotkv.com/commands/info/index.md) (`replication`), [REPLICAOF](https://docs.hotkv.com/commands/replicaof/index.md),
[WAIT](https://docs.hotkv.com/commands/wait/index.md), [replication](https://docs.hotkv.com/operate/replication/index.md)

In a cluster: [Replicas and failover](https://docs.hotkv.com/clustering/replicas-and-failover/index.md)