Registry / database / aioredis

aioredis

JSON →
library2.0.1pypypi✓ verified 7d ago

aioredis is an `asyncio` (PEP 3156) Redis client library providing asynchronous support for Redis. Currently at version 2.0.1, it underwent a complete rewrite in version 2.0.0 to align its API closely with the `redis-py` library, making it easier to adapt synchronous `redis-py` code for async applications. It is actively maintained with frequent updates.

pip install aioredis
INSTALL
IMPORT
SIG · AIOREDIS
A
aioredis
databasepythonv2.0.1
Install
1.8s avg
Import
889ms
Disk
18MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.0.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.390s · 20.4MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 1.8s · import 0.321s · 21MB
18MB installed
● package 18MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

from_url
from aioredis import from_url
import aioredis

This quickstart demonstrates connecting to Redis using `aioredis.from_url`, setting and retrieving a key, and using a transaction pipeline. It emphasizes graceful connection shutdown and the recommended `decode_responses` parameter for automatic string decoding.

import asyncio import aioredis import os async def main(): # Connect to Redis using a URL. For production, use environment variables. # decode_responses=True decodes bytes to strings automatically. redis_url = os.environ.get('REDIS_URL', 'redis://localhost') redis = aioredis.from_url( redis_url, encoding="utf-8", decode_responses=True ) try: await redis.set("my-key", "value") val = await redis.get("my-key") print(f"Retrieved value: {val}") # Example with a pipeline async with redis.pipeline(transaction=True) as pipe: result = await pipe.incr("counter").incr("counter").execute() print(f"Pipeline result: {result}") finally: # Ensure the connection pool is closed gracefully await redis.close() await redis.wait_closed() if __name__ == "__main__": asyncio.run(main())
Debug
Known issues
breakingVersion 2.0.0 of aioredis is a complete rewrite and introduces significant backward-incompatible API changes. It now closely follows the `redis-py` API, so existing code from v1.x will break.
fix
Refer to the official 'Migrating to v2.0' documentation. Key changes include connection methods, connection pool behavior, and command arguments.
affects: >=2.0.0
breakingFactory functions like `aioredis.create_redis()`, `aioredis.create_redis_pool()`, and `aioredis.create_pool()` are no longer available in v2.x.
fix
Use `aioredis.from_url()` to get a client with a connection pool, or `aioredis.Redis()` with an explicit `ConnectionPool` instance.
affects: >=2.0.0
breakingThe `loop` argument for specifying an `asyncio` event loop has been deprecated in v1.3.1 for Python 3.8+ and effectively removed in v2.x. `aioredis` now relies on the implicit event loop of `asyncio`.
fix
Remove the `loop` argument from all `aioredis` function calls. Code should run in the current running event loop.
affects: >=1.3.1
breakingIn v2.x, connection pools are lazy-filled, meaning connections are created on demand, unlike v1.x where `minsize` pre-filled the pool.
fix
Understand that `minsize` will not immediately establish connections in v2.x. Adjust application startup logic if pre-established connections are critical for initial performance checks.
affects: >=2.0.0
breakingThe `Channel` abstraction over PubSub, present in v1.x, has been removed in v2.x to align with `redis-py`'s API.
fix
Refactor PubSub code to use `redis.pubsub()` directly, similar to `redis-py`'s PubSub client.
affects: >=2.0.0
gotchaBy default, `aioredis` returns bytes for most Redis commands. To automatically decode responses to strings, you must explicitly pass `decode_responses=True` during client initialization.
fix
Initialize your Redis client with `redis = aioredis.from_url('redis://localhost', decode_responses=True)` to get string responses automatically. Otherwise, manually decode byte strings using `.decode('utf-8')`.
affects: All versions
breakingVersion 1.0.0 dropped support for Python 3.3 and 3.4. It also changed the return format for sorted set commands (with `withscores`) and `hscan` to lists of tuples instead of plain lists or mixed key-value lists.
fix
Ensure Python environment is 3.6+ and update code to handle the new return formats for affected commands.
affects: >=1.0.0
Upgrade
Version history
2.0.1latest on PyPI · released Dec 27, 2021
Audit
Dependencies
hiredisoptionalOptional C extension for faster parsing, highly recommended for performance.
typing-extensionsrequiredRequired for type hints.
async-timeoutrequiredRequired for asynchronous operations and timeouts.
Agent activity
35 hits · last 30 days
node
32
Resources