redis client for Python asyncio (has support for redis server, sentinel and cluster)
|pypi-ver| |circleci-status| |python-ver|
An efficient and user-friendly async redis client ported from redis-py <https://github.com/andymccurdy/redis-py>
_
(which is a Python interface to the Redis key-value)
To get more information please read full document
_
.. _full document: http://aredis.readthedocs.io/en/latest/
aredis requires a running Redis server.
To install aredis, simply:
.. code-block:: bash
$ pip3 install aredis[hiredis]
or from source:
.. code-block:: bash
$ python setup.py install
More examples
_
.. _More examples: https://github.com/NoneGG/aredis/tree/master/examples
Tip: since python 3.8 you can use asyncio REPL:
.. code-block:: bash
$ python -m asyncio
single node client ^^^^^^^^^^^^^^^^^^
.. code-block:: python
import asyncio
from aredis import StrictRedis
async def example():
client = StrictRedis(host='127.0.0.1', port=6379, db=0)
await client.flushdb()
await client.set('foo', 1)
assert await client.exists('foo') is True
await client.incr('foo', 100)
assert int(await client.get('foo')) == 101
await client.expire('foo', 1)
await asyncio.sleep(0.1)
await client.ttl('foo')
await asyncio.sleep(1)
assert not await client.exists('foo')
loop = asyncio.get_event_loop()
loop.run_until_complete(example())
cluster client ^^^^^^^^^^^^^^
.. code-block:: python
import asyncio
from aredis import StrictRedisCluster
async def example():
client = StrictRedisCluster(host='172.17.0.2', port=7001)
await client.flushdb()
await client.set('foo', 1)
await client.lpush('a', 1)
print(await client.cluster_slots())
await client.rpoplpush('a', 'b')
assert await client.rpop('b') == b'1'
loop = asyncio.get_event_loop() loop.run_until_complete(example())
Please run test script in benchmarks dir to confirm the benchmark.
For benchmark in my environment please see: benchmark
_
.. _benchmark: http://aredis.readthedocs.io/en/latest/benchmark.html
.. |circleci-status| image:: https://img.shields.io/circleci/project/github/NoneGG/aredis/master.svg :alt: CircleCI build status :target: https://circleci.com/gh/NoneGG/aredis/tree/master
.. |pypi-ver| image:: https://img.shields.io/pypi/v/aredis.svg :target: https://pypi.python.org/pypi/aredis/ :alt: Latest Version in PyPI
.. |python-ver| image:: https://img.shields.io/pypi/pyversions/aredis.svg :target: https://pypi.python.org/pypi/aredis/ :alt: Supported Python versions
Enhancement, bug reports and Pull requests are welcomed, please make an issue to let me know. Fork me please~