objbase 0.3.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,35 @@
1
+ import os
2
+ from typing import TYPE_CHECKING
3
+
4
+ if TYPE_CHECKING:
5
+ import redis
6
+ import redis.asyncio
7
+
8
+
9
+ def get_async_redis_client() -> "redis.asyncio.Redis":
10
+ try:
11
+ import redis.asyncio
12
+ except ImportError:
13
+ raise ImportError("redis is not installed. Please install it with 'pip install redis'.") from None
14
+
15
+ redis_url = os.getenv("REDIS_URL", "redis://localhost:6379/0")
16
+ if not redis_url:
17
+ raise ValueError("REDIS_URL is not set in environment variables.")
18
+ return redis.asyncio.from_url(redis_url, decode_responses=True)
19
+
20
+
21
+ # Backwards-compatible name; the standalone aioredis package is abandoned and
22
+ # has been merged into redis-py as redis.asyncio.
23
+ get_aioredis_client = get_async_redis_client
24
+
25
+
26
+ def get_redis_client() -> "redis.Redis":
27
+ try:
28
+ import redis
29
+ except ImportError:
30
+ raise ImportError("redis is not installed. Please install it with 'pip install redis'.") from None
31
+
32
+ redis_url = os.getenv("REDIS_URL", "redis://localhost:6379/0")
33
+ if not redis_url:
34
+ raise ValueError("REDIS_URL is not set in environment variables.")
35
+ return redis.from_url(redis_url, decode_responses=True)