skip to Main Content

I’m facing a MasterNotFoundError when I try to connect to the master node by following the deployment guide here: https://docs.bitnami.com/tutorials/deploy-redis-sentinel-production-cluster/

My code to connect to the master Redis Sentinel node is:

from redis.sentinel import Sentinel

redis_host = 'redis.default.svc.cluster.local'
redis_port = 26379
sentinel = Sentinel([(redis_host, redis_port)], socket_timeout=0.1, password='abc')
redis_client = sentinel.master_for('mymaster', password='abc')

In their GitHub repo, I see that the config for sentinel.masterSet is set to mymaster by default. But when I try to increment using the code below:

redis_client.incr('counter', 1)

I face the redis.sentinel.MasterNotFoundError: No master found for ‘mymaster’ error.

How can I solve this? Thanks.

2

Answers


  1. Where are you executing that code? If you are trying to connect from outside the cluster you will need to set the service as LoadBalancerIP.
    Have you tested if you have direct connection to that host before executing the code? using, for example, ping.
    Here you can see how to deploy the sentinel service as LoadBalancer: https://github.com/bitnami/charts/tree/master/bitnami/redis.
    You will need to set sentinel.service.type to LoadBalancerIP.
    I hope this will help you.

    Login or Signup to reply.
  2. As reported here https://github.com/andymccurdy/redis-py/issues/1125 setting a low socket_timeout can cause a MasterNotFound error as each instance is polled but doesn’t respond in time. You could increase the timeout or remove it to see if that fixes it.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search