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 |
- 💼 Full Compatibility: Works effortlessly with the
redis-py
library. - ⚡ Asynchronous Operations: Async Redis connections for improved performance.
- 🛠️ Singleton Pattern: Efficiently manage Redis connections using a singleton design.
- 🔄 Context Manager Support: Easily manage Redis sessions.
- 🔧 Simple Configuration: Configure effortlessly with
RedisConfig
.
Get started quickly by installing aredis-client
with pip:
pip install git+https://github.com/deepmancer/aredis-client.git
Start by creating a configuration object with RedisConfig
:
from aredis_client import RedisConfig
config = RedisConfig(
host='localhost',
port=6379,
db=0,
)
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)
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()
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())
Stay safe with custom exceptions to handle Redis-related errors:
RedisConnectionError
RedisSessionCreationError
Ensure a clean disconnect from the Redis server:
await redis_client.disconnect()
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! 🚀