Skip to main content

How do you tell whether a Redis node is a master or a replica?

There are several ways to find out whether a Redis node is a master or a replica:

1. Via the INFO replication command

This is the main and most reliable way.

Example:

bash
redis-cli INFO replication

Output:

javascript
# Replication role:master connected_slaves:1 slave0:ip=127.0.0.1,port=6380,state=online,offset=1203,lag=0

or

javascript
# Replication role:slave master_host:127.0.0.1 master_port:6379 master_link_status:up

The role: field shows what this node is:

  • role:master, this is the primary node.
  • role:slave (or role:replica in newer versions), this is a replica.

2. Via the ROLE command

A more concise alternative.

Example:

bash
redis-cli ROLE

Possible responses:

  • For a master:

    javascript
    1) "master" 2) (integer) 12345 3) (array) ...
  • For a replica:

    javascript
    1) "slave" 2) "127.0.0.1" 3) (integer) 6379 4) "connected" 5) (integer) 12345

3. Via Redis Sentinel (if it's in use)

If you have Sentinel configured:

bash
redis-cli -p 26379 SENTINEL masters

This shows the current master and its replicas.

In short: → The fastest way is redis-cli INFO replication and checking the role: field.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.