{"id":13482074,"url":"https://github.com/jonathanslenders/asyncio-redis","last_synced_at":"2025-04-08T09:09:50.630Z","repository":{"id":11171945,"uuid":"13547040","full_name":"jonathanslenders/asyncio-redis","owner":"jonathanslenders","description":"Redis client for Python asyncio (PEP 3156)","archived":false,"fork":false,"pushed_at":"2020-08-11T13:56:53.000Z","size":818,"stargazers_count":552,"open_issues_count":52,"forks_count":74,"subscribers_count":20,"default_branch":"master","last_synced_at":"2025-04-01T08:34:12.343Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://asyncio-redis.readthedocs.org/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jonathanslenders.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-10-13T21:31:36.000Z","updated_at":"2025-03-25T14:04:55.000Z","dependencies_parsed_at":"2022-07-16T09:46:38.250Z","dependency_job_id":null,"html_url":"https://github.com/jonathanslenders/asyncio-redis","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonathanslenders%2Fasyncio-redis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonathanslenders%2Fasyncio-redis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonathanslenders%2Fasyncio-redis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonathanslenders%2Fasyncio-redis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonathanslenders","download_url":"https://codeload.github.com/jonathanslenders/asyncio-redis/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247809964,"owners_count":20999816,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T17:00:58.758Z","updated_at":"2025-04-08T09:09:50.557Z","avatar_url":"https://github.com/jonathanslenders.png","language":"Python","funding_links":[],"categories":["HarmonyOS","资源列表","Python","Database Drivers","数据库驱动"],"sub_categories":["Windows Manager","数据库驱动"],"readme":"Redis client for Python asyncio.\n================================\n\n|Build Status|\n\n..\n    # Don't show the Build status on drone.io. Update script first. It's still\n    # using an older Redis version.\n    # |Build Status2| \n\n\nRedis client for the `PEP 3156`_ Python event loop.\n\n.. _PEP 3156: http://legacy.python.org/dev/peps/pep-3156/\n\nThis Redis library is a completely asynchronous, non-blocking client for a Redis server.\nIt depends on asyncio (PEP 3156) and requires Python 3.6 or greater. If you're new to\nasyncio, it can be helpful to check out `the asyncio documentation`_ first.\n\n.. _the asyncio documentation: http://docs.python.org/dev/library/asyncio.html\n\n\nMaintainers needed!\n-------------------\n\nRight now, this library is working fine, but not actively maintained, due to\nlack of time and shift of priorities on my side (Jonathan). Most of my time\ndoing open source goes to prompt_toolkt community.\n\nI still merge pull request when they are fine, especially for bug/security\nfixes. But for a while now, we don't have new features. If you are already\nusing it, then there's not really a need to worry, asyncio-redis will keep\nworking fine, and we fix bugs, but it's not really evolving.\n\nIf anyone is interested to seriously take over development, please let me know.\nAlso keep in mind that there is a competing library called `aioredis`, which\ndoes have a lot of activity.\n\nSee issue https://github.com/jonathanslenders/asyncio-redis/issues/134 to\ndiscuss.\n\n\nFeatures\n--------\n\n- Works for the asyncio (PEP3156) event loop\n- No dependencies except asyncio\n- Connection pooling\n- Automatic conversion from unicode (Python) to bytes (inside Redis.)\n- Bytes and str protocols.\n- Completely tested\n- Blocking calls and transactions supported\n- Streaming of some multi bulk replies\n- Pubsub support\n\n\n*Trollius support*: There is `a fork by Ben Jolitz`_ that has the necessary\nchanges for using this asyncio-redis library with Trollius.\n\n.. _a fork by Ben Jolitz: https://github.com/benjolitz/trollius-redis\n\n\nInstallation\n------------\n\n.. code::\n\n    pip install asyncio_redis\n\nDocumentation\n-------------\n\nView documentation at `read-the-docs`_\n\n.. _read-the-docs: http://asyncio-redis.readthedocs.org/en/latest/\n\n\nThe connection class\n--------------------\n\nA ``asyncio_redis.Connection`` instance will take care of the connection and\nwill automatically reconnect, using a new transport when the connection drops.\nThis connection class also acts as a proxy to a ``asyncio_redis.RedisProtocol``\ninstance; any Redis command of the protocol can be called directly at the\nconnection.\n\n\n.. code:: python\n\n    import asyncio\n    import asyncio_redis\n\n\n    async def example():\n        # Create Redis connection\n        connection = await asyncio_redis.Connection.create(host='localhost', port=6379)\n\n        # Set a key\n        await connection.set('my_key', 'my_value')\n\n        # When finished, close the connection.\n        connection.close()\n\n\n    if __name__ == '__main__':\n        loop = asyncio.get_event_loop()\n        loop.run_until_complete(example())\n\n\nConnection pooling\n------------------\n\nRequests will automatically be distributed among all connections in a pool. If\na connection is blocking because of --for instance-- a blocking rpop, another\nconnection will be used for new commands.\n\n\n.. code:: python\n\n    import asyncio\n    import asyncio_redis\n\n\n    async def example():\n        # Create Redis connection\n        connection = await asyncio_redis.Pool.create(host='localhost', port=6379, poolsize=10)\n\n        # Set a key\n        await connection.set('my_key', 'my_value')\n\n        # When finished, close the connection pool.\n        connection.close()\n\n\nTransactions example\n--------------------\n\n.. code:: python\n\n    import asyncio\n    import asyncio_redis\n\n\n    async def example(loop):\n        # Create Redis connection\n        connection = await asyncio_redis.Pool.create(host='localhost', port=6379, poolsize=10)\n\n        # Create transaction\n        transaction = await connection.multi()\n\n        # Run commands in transaction (they return future objects)\n        f1 = await transaction.set('key', 'value')\n        f2 = await transaction.set('another_key', 'another_value')\n\n        # Commit transaction\n        await transaction.exec()\n\n        # Retrieve results\n        result1 = await f1\n        result2 = await f2\n\n        # When finished, close the connection pool.\n        connection.close()\n\nIt's recommended to use a large enough poolsize. A connection will be occupied\nas long as there's a transaction running in there.\n\n\nPubsub example\n--------------\n\n.. code:: python\n\n    import asyncio\n    import asyncio_redis\n\n    async def example():\n        # Create connection\n        connection = await asyncio_redis.Connection.create(host='localhost', port=6379)\n\n        # Create subscriber.\n        subscriber = await connection.start_subscribe()\n\n        # Subscribe to channel.\n        await subscriber.subscribe([ 'our-channel' ])\n\n        # Inside a while loop, wait for incoming events.\n        while True:\n            reply = await subscriber.next_published()\n            print('Received: ', repr(reply.value), 'on channel', reply.channel)\n\n        # When finished, close the connection.\n        connection.close()\n\n\nLUA Scripting example\n---------------------\n\n.. code:: python\n\n    import asyncio\n    import asyncio_redis\n\n    code = \\\n    \"\"\"\n    local value = redis.call('GET', KEYS[1])\n    value = tonumber(value)\n    return value * ARGV[1]\n    \"\"\"\n\n\n    async def example():\n        connection = await asyncio_redis.Connection.create(host='localhost', port=6379)\n\n        # Set a key\n        await connection.set('my_key', '2')\n\n        # Register script\n        multiply = await connection.register_script(code)\n\n        # Run script\n        script_reply = await multiply.run(keys=['my_key'], args=['5'])\n        result = await script_reply.return_value()\n        print(result) # prints 2 * 5\n\n        # When finished, close the connection.\n        connection.close()\n\n\nExample using the Protocol class\n--------------------------------\n\n.. code:: python\n\n    import asyncio\n    import asyncio_redis\n\n\n    async def example():\n        loop = asyncio.get_event_loop()\n\n        # Create Redis connection\n        transport, protocol = await loop.create_connection(\n                    asyncio_redis.RedisProtocol, 'localhost', 6379)\n\n        # Set a key\n        await protocol.set('my_key', 'my_value')\n\n        # Get a key\n        result = await protocol.get('my_key')\n        print(result)\n\n        # Close transport when finished.\n        transport.close()\n\n    if __name__ == '__main__':\n        asyncio.get_event_loop().run_until_complete(example())\n\n\n\n.. |Build Status| image:: https://travis-ci.org/jonathanslenders/asyncio-redis.png\n    :target: https://travis-ci.org/jonathanslenders/asyncio-redis#\n\n.. |Build Status2| image:: https://drone.io/github.com/jonathanslenders/asyncio-redis/status.png\n    :target: https://drone.io/github.com/jonathanslenders/asyncio-redis/latest\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonathanslenders%2Fasyncio-redis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonathanslenders%2Fasyncio-redis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonathanslenders%2Fasyncio-redis/lists"}