Skip to content
This repository has been archived by the owner on Feb 21, 2023. It is now read-only.

'RedisConnection' object has no attribute 'publish' #730

Closed
bitnom opened this issue Apr 6, 2020 · 3 comments
Closed

'RedisConnection' object has no attribute 'publish' #730

bitnom opened this issue Apr 6, 2020 · 3 comments
Labels
question resolved-via-latest This indicates this issue is either resolved or invalid as of the latest version.

Comments

@bitnom
Copy link

bitnom commented Apr 6, 2020

AIOREDIS: Version: 1.3.1

I'm trying to use a connection pool to do pub/sub for a websocket server. I have used example code for the subscribe but I am having trouble with publish. In my AIOHTTP main.py I have:

redis_pool = await create_pool((host, port),
                                       password=redis_pass)
app['redis'] = redis_pool

And I have a test route with:

async def redis_test(request):
    test_data = {
        'hello': 'world'
    }
    with await request.app['redis'] as conn:
        conn.publish('user:8', ujson.dumps(test_data))
    #await request.app['redis'].publish('user:8', ujson.dumps(test_data))
    response = web.Response(body='test')
    return response

But I get: 'RedisConnection' object has no attribute 'publish'

@0xfadeef
Copy link

Hi! As far as I can tell, ConnectionsPool doesn't implement Redis commands per se. Try using create_redis_pool instead of create_pool. In this case you'll get your pool wrapped with Redis interface.

@Andrew-Chen-Wang
Copy link
Collaborator

Yea you'll want to make sure assert type(conn) == Redis or type(conn) == ContextRedis. Follow what 0xfadeef said (or the docs) and you should be good to go.

@seandstewart seandstewart added the resolved-via-latest This indicates this issue is either resolved or invalid as of the latest version. label Mar 18, 2021
@seandstewart
Copy link
Collaborator

This issue should be resolved as of #891 - please feel free to pull in the latest master and test to ensure this is the case.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question resolved-via-latest This indicates this issue is either resolved or invalid as of the latest version.
Projects
None yet
Development

No branches or pull requests

4 participants