Sentinel

Redis Sentinel

Sentinel allows us to run Redis in a self-healing configuration, where a number of Sentinels monitor a set of Redis Servers. Between them the Sentinels determine the availability of each Server node and will coordinate the election of a replacement master in the event that the active one becomes unavailable.

Redis clients must be additionally aware of the Sentinel nodes, connecting first to one or more of these nodes to query the current master and replicas. They must then send their writes to the current master and can send their reads to any of the replicas. For applications that don't natively support Sentinel we must use a tunnel that can.

Determining the current master

In order to direct clients to the current master we run Sentinel. To determine the current master, log in to one of the application servers and run the following:

$ redis-cli -p 26379 sentinel get-master-addr-by-name master
1) "10.146.32.68"
2) "6379"

Further information can be obtained with the master command:

$ redis-cli -p 26379 sentinel master master
 1) "name"
 2) "master"
 3) "ip"
 4) "10.146.16.52"
 5) "port"
 6) "6379"
 7) "runid"
 8) "5349d5d25901b295e47deceaf12dad531db7bb4d"
 9) "flags"
10) "master"
11) "link-pending-commands"
12) "0"
13) "link-refcount"
14) "1"
15) "last-ping-sent"
16) "0"
17) "last-ok-ping-reply"
18) "407"
19) "last-ping-reply"
20) "407"
21) "down-after-milliseconds"
22) "30000"
23) "info-refresh"
24) "9506"
25) "role-reported"
26) "master"
27) "role-reported-time"
28) "700638782"
29) "config-epoch"
30) "0"
31) "num-slaves"
32) "1"
33) "num-other-sentinels"
34) "1"
35) "quorum"
36) "2"
37) "failover-timeout"
38) "180000"
39) "parallel-syncs"
40) "1"

Listing active replicas

We can also query the state of any replicas.

$ redis-cli -p 26379 sentinel slaves master
127.0.0.1:26379> sentinel slaves master
1)  1) "name"
    2) "10.146.16.53:6379"
    3) "ip"
    4) "10.146.16.53"
    5) "port"
    6) "6379"
    7) "runid"
    8) "723e1415e7ddf4002fecd215840a9758d71e8c3e"
    9) "flags"
   10) "slave"
   11) "link-pending-commands"
   12) "0"
   13) "link-refcount"
   14) "1"
   15) "last-ping-sent"
   16) "0"
   17) "last-ok-ping-reply"
   18) "857"
   19) "last-ping-reply"
   20) "857"
   21) "down-after-milliseconds"
   22) "30000"
   23) "info-refresh"
   24) "7138"
   25) "role-reported"
   26) "slave"
   27) "role-reported-time"
   28) "700643454"
   29) "master-link-down-time"
   30) "0"
   31) "master-link-status"
   32) "ok"
   33) "master-host"
   34) "10.146.16.52"
   35) "master-port"
   36) "6379"
   37) "slave-priority"
   38) "100"
   39) "slave-repl-offset"
   40) "32233866458"