-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Closed
Labels
Description
Version: What redis-py and what redis version is the issue happening on?
Redis-py version 4.4.0
Redis version 6.2.7
Platform: What platform / version? (For example Python 3.5.1 on Windows 7 / Ubuntu 15.10 / Azure)
Python 3.10 on Archlinux
Description: Description of your issue, stack traces from errors and code that reproduces the issue*
I have a Redis + Sentinel setup and I'm trying to listen for messages (full code below):
channel = redis.pubsub()
await channel.psubscribe("foo*")
async for msg in channel.listen():
print(msg)This works with redis-py 4.3.5, but fails on version 4.4.0 with an unexpected argument timeout.
Also, this seems to work fine when instantiating a regular Redis client instead of getting one via Sentinel.
Traceback (most recent call last):
File "fail.py", line 41, in <module>
main()
File "fail.py", line 37, in main
asyncio.run(foobar())
File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/usr/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
return future.result()
File "fail.py", line 32, in foobar
async for msg in channel.listen():
File "virtualenvs/fail/lib/python3.10/site-packages/redis/asyncio/client.py", line 891, in listen
response = await self.handle_message(await self.parse_response(block=True))
File "virtualenvs/fail/lib/python3.10/site-packages/redis/asyncio/client.py", line 784, in parse_response
response = await self._execute(conn, conn.read_response, timeout=read_timeout)
File "virtualenvs/fail/lib/python3.10/site-packages/redis/asyncio/client.py", line 764, in _execute
return await conn.retry.call_with_retry(
File "virtualenvs/fail/lib/python3.10/site-packages/redis/asyncio/retry.py", line 59, in call_with_retry
return await do()
File "virtualenvs/fail/lib/python3.10/site-packages/redis/asyncio/client.py", line 765, in <lambda>
lambda: command(*args, **kwargs),
TypeError: SentinelManagedConnection.read_response() got an unexpected keyword argument 'timeout'
Full code (MRE)
import asyncio
import os
from redis.asyncio import Sentinel
REDIS_PASSWORD = os.getenv("REDIS_PASSWORD", "")
REDIS_DB = int(os.getenv("REDIS_DB", 0))
SENTINEL_PASSWORD = os.getenv("SENTINEL_PASSWORD", "")
SENTINEL_URLS = [
s.strip() for s in os.getenv("SENTINEL_URLS", "127.0.0.1:26379").split(",") if s.strip()
]
async def foobar() -> None:
stnl = Sentinel(
[s.split(":") for s in SENTINEL_URLS],
sentinel_kwargs={"password": SENTINEL_PASSWORD},
password=REDIS_PASSWORD,
db=REDIS_DB,
)
redis = stnl.master_for("mymaster")
# So far so good:
await redis.set("foo", "bar")
await redis.expire("foo", 10)
print("GET foo:", await redis.get("foo"))
# This is where it fails:
channel = redis.pubsub()
await channel.psubscribe("foo*")
async for msg in channel.listen():
print(msg)
def main() -> None:
asyncio.run(foobar())
if __name__ == "__main__":
main()