Using python 3.6.12 and aioredis 2.0.0, asyncio 3.4.3
Tried to use the snippet from the aioredis for testing pub/sub:
import asyncio
import aioredis
async def reader(ch):
while (await ch.wait_message()):
msg = await ch.get_json()
print("Got Message:", msg)
async def main():
pub = await aioredis.create_redis(
'redis://:password@localhost:6379')
sub = await aioredis.create_redis(
'redis://:password@localhost:6379')
res = await sub.subscribe('chan:1')
ch1 = res[0]
tsk = asyncio.ensure_future(reader(ch1))
res = await pub.publish_json('chan:1', ["Hello", "world"])
assert res == 1
await sub.unsubscribe('chan:1')
await tsk
sub.close()
pub.close()
if __name__ == '__main__':
loop = asyncio.get_event_loop()
result = loop.run_until_complete(main())
but the following error keeps popping up.
Traceback (most recent call last):
File "tests/test_async_redis.py", line 32, in <module>
result = loop.run_until_complete(main())
File "/Users/dustinlee/.pyenv/versions/3.6.12/lib/python3.6/asyncio/base_events.py", line 488, in run_until_complete
return future.result()
File "tests/test_async_redis.py", line 12, in main
pub = await aioredis.create_redis(
AttributeError: module 'aioredis' has no attribute 'create_redis'
Can anyone tell me what I am doing wrong? Probably something obvious but I'm just not seeing it. Thanks!
aioredis
as of version 2.0 now follows the public API implementation of the libraryredis-py
.From the
aioredis
doc pageSo the method
aioredis.create_redis
is no longer a public API you can use to establish a connection in version 2.0. Use version less than 2 if you want thecreate_redis
method to work.You can refer the new pub sub example.
Code copied here in case link does not work in future.
You can maybe also refer the
redis-py
docs as it is supposed to be whataioredis
2.0 now follows closely.