Search code examples
pythoncachingdocker-composeredisredis-cluster

AttributeError: module 'redis' has no attribute 'Redis'


Problem

Installed redis module and I cannot establish the client according documentation. This is a Redis client in a Redis cluster hosted on Docker container.

Following documentation, as you can see:

>>> import redis
>>> r = redis.Redis(host='localhost', port=6379, db=0)
>>> r.set('foo', 'bar')
True
>>> r.get('foo')
b'bar'

Error

backend-web-1        |     from redis.conversation_memory import redis_client, initiate_user_memory
backend-web-1        |   File "/app/redis/conversation_memory.py", line 5, in <module>
backend-web-1        |     redis_client = redis.Redis(host='localhost', port=6379, db=0, decode_responses=True)
backend-web-1        |                    ^^^^^^^^^^^
backend-web-1        | AttributeError: module 'redis' has no attribute 'Redis'

Question

What's wrong with my implementation?


Solution

  • This was a rookie move.

    Never name a folder after an official Python module

    I wrongly named it after my redis module, which I am inherently using.

    Lesson

    Name your folder uniquely, if they are to be used as modules.