3636import redis .clients .jedis .JedisCluster ;
3737import redis .clients .jedis .JedisPooled ;
3838import redis .clients .jedis .JedisPubSub ;
39+ import redis .clients .jedis .JedisSentineled ;
3940import redis .clients .jedis .Protocol ;
4041import redis .clients .jedis .UnifiedJedis ;
4142
4849 */
4950public class RedisMessenger implements Messenger {
5051 private static final String CHANNEL = "luckperms:update" ;
52+ private static final int SENTINEL_DEFAULT_PORT = 26379 ;
5153
5254 private final LuckPermsPlugin plugin ;
5355 private final IncomingMessageConsumer consumer ;
@@ -70,6 +72,13 @@ public void init(String address, String username, String password, boolean ssl)
7072 this .init (new JedisPooled (parseAddress (address ), jedisConfig (username , password , ssl )));
7173 }
7274
75+ public void init (String masterName , List <String > sentinelAddresses , String username , String password , boolean ssl , String sentinelUsername , String sentinelPassword ) {
76+ Set <HostAndPort > sentinels = sentinelAddresses .stream ()
77+ .map (addr -> parseAddress (addr , SENTINEL_DEFAULT_PORT ))
78+ .collect (Collectors .toSet ());
79+ this .init (new JedisSentineled (masterName , jedisConfig (username , password , ssl ), sentinels , jedisConfig (sentinelUsername , sentinelPassword , ssl )));
80+ }
81+
7382 private void init (UnifiedJedis jedis ) {
7483 this .jedis = jedis ;
7584 this .sub = new Subscription (this );
@@ -86,9 +95,13 @@ private static JedisClientConfig jedisConfig(String username, String password, b
8695 }
8796
8897 private static HostAndPort parseAddress (String address ) {
98+ return parseAddress (address , Protocol .DEFAULT_PORT );
99+ }
100+
101+ private static HostAndPort parseAddress (String address , int defaultPort ) {
89102 me .lucko .luckperms .common .util .HostAndPort hostAndPort = new me .lucko .luckperms .common .util .HostAndPort (address )
90103 .requireBracketsForIPv6 ()
91- .withDefaultPort (Protocol . DEFAULT_PORT );
104+ .withDefaultPort (defaultPort );
92105 String host = hostAndPort .getHost ();
93106 int port = hostAndPort .getPort ();
94107 return new HostAndPort (host , port );
@@ -162,6 +175,8 @@ private boolean isRedisAlive() {
162175 return !((JedisPooled ) jedis ).getPool ().isClosed ();
163176 } else if (jedis instanceof JedisCluster ) {
164177 return !((JedisCluster ) jedis ).getClusterNodes ().isEmpty ();
178+ } else if (jedis instanceof JedisSentineled ) {
179+ return true ;
165180 } else {
166181 throw new RuntimeException ("Unknown jedis type: " + jedis .getClass ().getName ());
167182 }
0 commit comments