redis.clients.jedis.exceptions.JedisException: Can connect to sentinel, but seems to be not monitored.

在使用Redis的哨兵Sentinel配置时,报错如下:

redis.clients.jedis.exceptions.JedisException: Can connect to sentinel, but myMaster seems to be not monitored.

报错原因:

可能是因为哨兵配置sentinel.conf中的服务器名称,和程序中哨兵连接池配置的服务器名称不一致导致的。

解决方法:

查看哨兵配置 sentinel.conf,如下:

sentinel monitor mymaster 192.168.0.102  6379 2

其中的 哨兵配置中的服务器名称为 mymaster。

接着再看java程序中的JedisSentinelPool配置的哨兵名称:

  JedisSentinelPool sentinelPool=new JedisSentinelPool("myMaster",sentinelSet,jedisPoolConfig);

程序中的服务器名称为myMaster。

可以看到,sentinel.conf中配置的服务器名称和程序中的服务器名称不一样,因此报错。。将程序中的服务器名称改正就解决了。

原文地址:https://www.cnblogs.com/expiator/p/9945180.html