Get redis master sentinels
Asked Answered
K

2

5

I am trying to get a list of all sentinels which are currently monitoring the redis master.

I know that if I have one sentinel I can use sentinel sentinels mymaster but if I don't have any of the Sentinel's addresses how can I get them?

Key answered 6/9, 2017 at 11:26 Comment(0)
P
4

There is no direct command to get the list of sentinels from a master/slave node. To get the sentinels' list, you need to subscribe to any node's pub/sub (master or slave doesn't matter) "__sentinel__:hello" channel and wait for the messages. Messages passing through that hello channel are from sentinels that are listening that cluster. If you parse those, you get the sentinels' addresses. The messages are in form: "sentinel_ip,sentinel_port,sentinel_runid,sentinel_current_epoch,master_name,master_ip,master_port,master_config_epoch" (e.g. 127.0.0.1,26380,07fabf3cbac43bcc955588b1023f95498b58f8f2,16,mymaster,127.0.0.1,6381,16). See: https://redis.io/topics/sentinel#sentinels-and-slaves-auto-discovery about sentinel details. If you need more to know about how sentinel works, take a look at https://github.com/antirez/redis/blob/unstable/src/server.c

Pipestone answered 5/11, 2017 at 12:24 Comment(2)
Got this far, and I was hoping for something more elegant, but I guess this will have to do for now. Thanks!Key
subscribe __sentinel__:hello is the command to read __sentinel__:hello channel.Craggy
S
2

In order to explore more about this instance, you may want to try the following two commands:

SENTINEL slaves mymaster
SENTINEL sentinels mymaster

https://redis.io/topics/sentinel#asking-sentinel-about-the-state-of-a-master

Shy answered 5/8, 2018 at 11:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.