asyncio (PEP 3156) Redis support
asyncio (3156) Redis client library.
The library is intended to provide simple and clear interface to Redis based on asyncio.
| Feature | Supported |
|---|---|
| hiredis parser | :white_check_mark: |
| Pure-python parser | :white_check_mark: |
| Low-level & High-level APIs | :white_check_mark: |
| Pipelining support | :white_check_mark: |
| Multi/Exec support | :white_check_mark: |
| Connections Pool | :white_check_mark: |
| Pub/Sub support | :white_check_mark: |
| Sentinel support | :white_check_mark: |
| ACL support | :white_check_mark: |
| Streams support | :white_check_mark: |
| Redis Cluster support | :no_entry_sign: |
| Tested Python versions | 3.6, 3.7, 3.8, 3.9, 3.10 |
| Tested for Redis servers | 5.0, 6.0 |
| Support for dev Redis server | through low-level API |
The easiest way to install aioredis is by using the package on PyPi:
pip install aioredis
Recommended with hiredis for performance and stability reasons:
pip install hiredis
Benchmarks can be found here: https://github.com/popravich/python-redis-benchmark
Feel free to file an issue or make pull request if you find any bugs or have some suggestions for library improvement.
The aioredis is offered under a MIT License.
Port redis-py's client implementation to aioredis.
(see #891)
Make hiredis an optional dependency.
(see #917)
pool.wait_closed() upon create_pool() exception.loop argument.
Throw warning in Python 3.8+ if explicit loop is passed to methods.xdel and xtrim method which missed in commands/streams.py & also added unit test code for themcount argument to spop commandzpopmax and zpopmin redis commandstowncrier: change notes are now stored in CHANGES.txtBZPOPMAX and BZPOPMINCH and INCR options of the ZADD commandno_ack parameter to xread_group streams method in commands/streams.pywait_closed implementationencode_command() cost about 60%sendto syscallsINFO command result parsingConnectionsPool._drop_closed methodwait, touch, swapdb, unlinkasync_op argument to flushall and flushdb commandsminsize
greater than 1SentinelPool.discover_timeout usageReceiver hang on disconnectsubscribe/psubscribe with empty poolStreamReader's feed_data is called before set_parserImportant! Drop Python 3.3, 3.4 support
(see #321, #323, #326)
Important! Connections pool has been refactored; now create_redis
function will yield Redis instance instead of RedisPool
(see #129)
Important! Change sorted set commands reply format:
return list of tuples instead of plain list for commands
accepting withscores argument
(see #334)
Important! Change hscan command reply format:
return list of tuples instead of mixed key-value list
(see #335)
Implement Redis URI support as supported address argument value
(see #322)
Dropped create_reconnecting_redis, create_redis_pool should be
used instead
Implement custom StreamReader
(see #273)
Implement Sentinel support
(see #181)
Implement pure-python parser
(see #212)
Add migrate_keys command
(see #187)
Add zrevrangebylex command
(see #201)
Add command, command_count, command_getkeys and
command_info commands
(see #229)
Add ping support in pubsub connection
(see #264)
Add exist parameter to zadd command
(see #288)
Add MaxClientsError and implement ReplyError specialization
(see #325)
Add encoding parameter to sorted set commands
(see #289)
CancelledError in conn._reader_taskCancelledError,
use explicit exception instead of calling cancel() methodbytearray support as command argumentcreate_redis and create_redis_pool__aiter__()with (yield from pool) as conn:asyncio.CancelledErrorzrevrangebylex commandChannel instancesaioredis.pubsub.Receiveraioredis.abc module providing abstract base classes
defining interface for basic lib components (see #176)async/await syntax
also keeping yield from examples for historyEXISTS commandINFO command argument validationnext()hmset_dict commandRedisConnection.address propertyminsize/maxsize must not be Noneclose()/wait_closed()/closed interface for poolhstrlencreate_pool() minsize default value changed to 1time() conversion to floathmset() method to return bool instead of b'OK'tr.execute() to fail)asyncio.Future uses with utility methodloop.create_future())aioredis.ConnectionClosedError raised in execute_pubsub as wellRedis.slaveof() method signature changed: now to disable
replication one should call redis.slaveof(None) instead of redis.slaveof()iter() method to aioredis.Channel allowing to use it
with async forasync/await syntaxcreate_connectionasyncio.async calls with wrapper that respects asyncio versionaioredis.ConnectionClosedError exception added. Raised if
connection to Redis server is lostaioredis.util.decode to recursively decode list responsesPython 3.5 async support:
iscan, izscan, ihscan)with await pool: ... and async with pool.get() as conn: constructs)Fixed dropping closed connections from free pool
(see #83)
Docs updated
acquire call hangsinfo server command result parsing implementedhstrlen command addedDecoding data with encoding parameter now takes into account
list (array) replies
(see #68)
encoding parameter added to following commands:
Backward incompatibility:
ltrim command now returns bool value instead of 'OK'
Tests updated
wait_message in pub/subzrevrangebyscore commandzscore command fixedDropped following Redis methods -- Redis.multi(),
Redis.exec(), Redis.discard()
Redis.multi_exec hack'ish property removed
Redis.multi_exec() method added
High-level commands implemented:
Backward incompatibilities:
Following sorted set commands' API changed:
zcount, zrangebyscore, zremrangebyscore, zrevrangebyscore
set string command' API changed
RedisConnection.execute refactored to support commands pipelining
(see #33)
Several fixes
WIP on transactions and commands interface
High-level commands implemented and tested:
create_connection, create_pool, create_redis functions updated: db and password
arguments made keyword-only