Skip to content

AttributeError: 'Redis' object has no attribute 'sentinel_masters' #1714

@sculley

Description

@sculley

Version: 4.0.0

Platform: Python 3.7.12 / alpine / Kubernetes 1.20 / AWS / Redis server v=6.0.16 sha=00000000:0 malloc=jemalloc-5.1.0 bits=64 build=cb8b7c1889d3b7df

Description: Unable to call sentinel.discover_master()

When attempting to return the redis master from the sentinel hosts using py-redis 4.0.0 using the discover_master SentinelCommand I receive the following Attribute error.

AttributeError: 'Redis' object has no attribute 'sentinel_masters'

I would expect to see a list of tuples containing the list of redis master ip/port

[('10.10.10.10', 6379)]

It looks like the Redis client object returned when setting up the Sentinel class doesn't have access to the sentinel_master command found here https://github.com/redis/redis-py/blob/master/redis/commands/sentinel.py#L20 or any of the commands in that class.

I have taken a look at the Redis class and can't find where sentinel.py is passing through the sentinel commands or where the Redis class in client.py is loading them.

Example:

Python 3.7.12 (default, Nov 13 2021, 04:28:59)
[GCC 10.3.1 20210424] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from redis.sentinel import Sentinel
/usr/local/lib/python3.7/site-packages/redis/connection.py:77: UserWarning: redis-py works best with hiredis. Please consider installing
  warnings.warn(msg)
>>> sentinel = Sentinel([('localhost', 5000)], socket_timeout=0.1)
>>> master = sentinel.discover_master('mymaster')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/site-packages/redis/sentinel.py", line 234, in discover_master
    masters = sentinel.sentinel_masters()
AttributeError: 'Redis' object has no attribute 'sentinel_masters'

I tried using version 3.5.3 and I don't get the error and the master host/port is returned in a tuple, so it would seem the problem is specific to version 4.0.0. I have tried with some of the RC releases and they have the problem. The only strange thing is that I was using the same code last week (and presumebly py-redis 4.0.0) and the code worked.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions