pottery
pottery copied to clipboard
Crash with RedisCluster and RedisDict's update
When using RedisDict with an instance of redis.cluster.RedisCluster() - a crash occurs in base.py:
Fraceback (most recent call last):
File "/app/poc3.py", line 28, in <module>
demo()
File "/app/poc3.py", line 24, in demo
data.update({'key': 'value'})
File "/usr/local/lib/python3.9/site-packages/pottery/dict.py", line 144, in update
with self._watch(arg) as pipeline:
File "/usr/local/lib/python3.9/contextlib.py", line 119, in __enter__
return next(self.gen)
File "/usr/local/lib/python3.9/site-packages/pottery/base.py", line 232, in _watch
for context_manager in self.__context_managers(*others):
File "/usr/local/lib/python3.9/site-packages/pottery/base.py", line 220, in __context_managers
redises[connection_args(container.redis)].append(container)
File "/usr/local/lib/python3.9/site-packages/pottery/base.py", line 89, in connection_args
redis.connection_pool.connection_kwargs['host'],
AttributeError: 'RedisCluster' object has no attribute 'connection_pool'
To Reproduce
here is simple code to reproduce:
import os
from pottery import RedisDict
from redis.cluster import RedisCluster
env = os.environ
redis = RedisCluster(
host=env.get('REDIS_HOST'),
port=int(env.get('REDIS_PORT')),
username=env.get('REDIS_USER'),
password=env.get('REDIS_PASSWORD'),
charset='utf-8',
ssl_cert_reqs='none',
ssl=True,
skip_full_coverage_check=True
)
def demo():
data = RedisDict(key=f"data:test", redis=redis)
data.update({'key': 'value'})
if __name__ == "__main__":
demo()
Expected behavior
I expect it to work same regardless if it is a cluster or a single Redis instance :-/
Environment (please complete the following information):
- OS: Linux
- Python version 3.9.18
- Redis version : AWS MemoryDB 6.x cluster with a single node