{"id":2857,"library":"aioredis","title":"aioredis","description":"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.","status":"active","version":"2.0.1","language":"en","source_language":"en","source_url":"https://github.com/aio-libs/aioredis-py","tags":["async","redis","asyncio","database","cache","client"],"install":[{"cmd":"pip install aioredis","lang":"bash","label":"Standard Install"},{"cmd":"pip install aioredis hiredis","lang":"bash","label":"Recommended for Performance (with hiredis)"}],"dependencies":[{"reason":"Optional C extension for faster parsing, highly recommended for performance.","package":"hiredis","optional":true},{"reason":"Required for type hints.","package":"typing-extensions","optional":false},{"reason":"Required for asynchronous operations and timeouts.","package":"async-timeout","optional":false}],"imports":[{"note":"As of v2.0.0, `create_redis_pool` and similar factory functions were removed. Use `aioredis.from_url` or `aioredis.Redis` directly.","wrong":"import aioredis\nredis = await aioredis.create_redis_pool(...)","symbol":"from_url","correct":"import aioredis\nredis = aioredis.from_url(...)"},{"symbol":"Redis","correct":"from aioredis import Redis\nredis = Redis(connection_pool=...)"},{"symbol":"ConnectionPool","correct":"from aioredis import ConnectionPool\npool = ConnectionPool.from_url(...)"}],"quickstart":{"code":"import asyncio\nimport aioredis\nimport os\n\nasync def main():\n    # Connect to Redis using a URL. For production, use environment variables.\n    # decode_responses=True decodes bytes to strings automatically.\n    redis_url = os.environ.get('REDIS_URL', 'redis://localhost')\n    redis = aioredis.from_url(\n        redis_url,\n        encoding=\"utf-8\",\n        decode_responses=True\n    )\n\n    try:\n        await redis.set(\"my-key\", \"value\")\n        val = await redis.get(\"my-key\")\n        print(f\"Retrieved value: {val}\")\n\n        # Example with a pipeline\n        async with redis.pipeline(transaction=True) as pipe:\n            result = await pipe.incr(\"counter\").incr(\"counter\").execute()\n            print(f\"Pipeline result: {result}\")\n\n    finally:\n        # Ensure the connection pool is closed gracefully\n        await redis.close()\n        await redis.wait_closed()\n\nif __name__ == \"__main__\":\n    asyncio.run(main())","lang":"python","description":"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."},"warnings":[{"fix":"Refer to the official 'Migrating to v2.0' documentation. Key changes include connection methods, connection pool behavior, and command arguments.","message":"Version 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.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Use `aioredis.from_url()` to get a client with a connection pool, or `aioredis.Redis()` with an explicit `ConnectionPool` instance.","message":"Factory functions like `aioredis.create_redis()`, `aioredis.create_redis_pool()`, and `aioredis.create_pool()` are no longer available in v2.x.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Remove the `loop` argument from all `aioredis` function calls. Code should run in the current running event loop.","message":"The `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`.","severity":"breaking","affected_versions":">=1.3.1"},{"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.","message":"In v2.x, connection pools are lazy-filled, meaning connections are created on demand, unlike v1.x where `minsize` pre-filled the pool.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Refactor PubSub code to use `redis.pubsub()` directly, similar to `redis-py`'s PubSub client.","message":"The `Channel` abstraction over PubSub, present in v1.x, has been removed in v2.x to align with `redis-py`'s API.","severity":"breaking","affected_versions":">=2.0.0"},{"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')`.","message":"By default, `aioredis` returns bytes for most Redis commands. To automatically decode responses to strings, you must explicitly pass `decode_responses=True` during client initialization.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure Python environment is 3.6+ and update code to handle the new return formats for affected commands.","message":"Version 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.","severity":"breaking","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}