Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

asyncio_redis.Pool.create error ? #103

Open
rfyiamcool opened this issue Dec 29, 2016 · 1 comment
Open

asyncio_redis.Pool.create error ? #103

rfyiamcool opened this issue Dec 29, 2016 · 1 comment
Labels

Comments

@rfyiamcool
Copy link

import asyncio
import asyncio_redis

connection = asyncio_redis.Pool.create(host='localhost', port=6379, poolsize=10)

@asyncio.coroutine
def example():
    # Set a key
    yield from connection.set('my_key', 'my_value')
    # When finished, close the connection pool.
    connection.close()

[root@ubuntu:~]#python3.5 r.py
Traceback (most recent call last):
File "r.py", line 15, in
loop.run_until_complete(example())
File "/usr/lib/python3.5/asyncio/base_events.py", line 387, in run_until_complete
return future.result()
File "/usr/lib/python3.5/asyncio/futures.py", line 274, in result
raise self._exception
File "/usr/lib/python3.5/asyncio/tasks.py", line 239, in _step
result = coro.send(None)
File "r.py", line 9, in example
yield from connection.set('my_key', 'my_value')
AttributeError: 'generator' object has no attribute 'set'

why cann't put asyncio_redis.Pool.create in other places ? thanks you .

@jonathanslenders
Copy link
Owner

Pool.create is a coroutine. This means that you need to put "await" in front of it to get the actual result.

connection = await asyncio_redis.Pool.create(host='localhost', port=6379, poolsize=10)

Of course, this means also that this line has to be moved inside another coroutine. (E.g, in the "example" function.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants