Question: How can I retrieve replication information in Redis?
Answer
In Redis, you can retrieve replication information using the INFO
command with the replication
section. This command returns details about the Redis instance, including various types of statistics and status data.
Here's how you can use it:
127.0.0.1:6379> INFO replication
The output will provide detailed information about the state of replication. It includes the role of the instance (master or slave), the number of connected slaves if it's a master, or the master's IP and port if it's a slave. Here is a sample output for a master:
# Replication
role:master
connected_slaves:1
slave0:ip=127.0.0.1,port=6380,state=online,offset=42,lag=1
master_replid:5c2d42772bfa7fb3dd27a432809dad09270e33ed
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:42
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:42
This output contains important details about the state of replication:
role
: The role of this Redis instance (master
orslave
).connected_slaves
: The number of connected slaves to this master.slave<n>
: One line per connected slave showing their IP, port, state, data offset, and lag in data received.master_replid
: The replication ID of the master. It changes when the data that is not in the backlog of any slave is modified.
Remember to replace "127.0.0.1:6379" with your Redis instance's IP address and port if it's different.
Was this content helpful?
Other Common Redis Questions (and Answers)
Free System Design on AWS E-Book
Download this early release of O'Reilly's latest cloud infrastructure e-book: System Design on AWS.
Start building today
Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement.