aredis-client

🧰 Async Redis Client

Redis PyPI Python License

aredis-client is your go-to Python package for seamless asynchronous Redis interactions, powered by redis-py. With its singleton-based connection pooling, it ensures efficient, thread-safe operations, making your Redis experience faster and easier.


Source Code Website
github.com/deepmancer/aredis-client deepmancer.github.io/aredis-client

✨ Features

πŸ“¦ Installation

Get started quickly by installing aredis-client with pip:

pip install git+https://github.com/deepmancer/aredis-client.git

πŸ“ Usage Guide

πŸ”§ Configuration

Start by creating a configuration object with RedisConfig:

from aredis_client import RedisConfig

config = RedisConfig(
    host='localhost',
    port=6379,
    db=0,
)

πŸ—οΈ Creating an AsyncRedis Instance

Next, create an instance of AsyncRedis using the configuration:

from aredis_client import AsyncRedis

async def main():
    redis_client = await AsyncRedis.create(config=config)
    print(redis_client.url)

βš™οΈ Managing Redis Sessions

Interact with the Redis server using the context manager from get_or_create_session:

from aredis_client import AsyncRedis

async def main():
    redis_client = await AsyncRedis.create(config=config)

    async with redis_client.get_or_create_session() as session:
        # Interact with your Redis server
        await session.set('key', 'value')
        value = await session.get('key')
        print(value)

    await redis_client.disconnect()

πŸ” Example Usage

Here’s a complete example to demonstrate the power of aredis-client:

import asyncio
from aredis_client import AsyncRedis, RedisConfig

async def main():
    config = RedisConfig(
        host='localhost',
        port=6379,
        db=0,
    )
    client = await AsyncRedis.create(config=config)

    async with client.get_or_create_session() as session:
        await session.set('key', 'value')
        value = await session.get('key')
        print(f'The value for "key" is {value}')
        
        keys = ['key1', 'key2', 'key3']
        pipeline = session.pipeline()
        for key in keys:
            pipeline.delete(key)
        await pipeline.execute()
        
    await client.disconnect()

if __name__ == "__main__":
    asyncio.run(main())

πŸ›‘οΈ Error Handling

Stay safe with custom exceptions to handle Redis-related errors:

πŸ›‘ Disconnecting

Ensure a clean disconnect from the Redis server:

await redis_client.disconnect()

πŸ“„ License

This project is licensed under the Apache License 2.0. See the LICENSE file for full details.


Get started with aredis-client today and take your Redis operations much easier! πŸš€