WIP on async - test failure due to closed event loop
This commit is contained in:
parent
0f9f7aa868
commit
b2c2dd9f6f
22 changed files with 348 additions and 190 deletions
28
redis_om/connections.py
Normal file
28
redis_om/connections.py
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import os
|
||||
from typing import Union
|
||||
|
||||
import dotenv
|
||||
import aioredis
|
||||
import redis
|
||||
from redis_om.unasync_util import ASYNC_MODE
|
||||
|
||||
dotenv.load_dotenv()
|
||||
|
||||
URL = os.environ.get("REDIS_OM_URL", None)
|
||||
if ASYNC_MODE:
|
||||
client = aioredis.Redis
|
||||
else:
|
||||
client = redis.Redis
|
||||
|
||||
|
||||
def get_redis_connection(**kwargs) -> Union[aioredis.Redis, redis.Redis]:
|
||||
# If someone passed in a 'url' parameter, or specified a REDIS_OM_URL
|
||||
# environment variable, we'll create the Redis client from the URL.
|
||||
url = kwargs.pop("url", URL)
|
||||
if url:
|
||||
return client.from_url(url, **kwargs)
|
||||
|
||||
# Decode from UTF-8 by default
|
||||
if "decode_responses" not in kwargs:
|
||||
kwargs["decode_responses"] = True
|
||||
return client(**kwargs)
|
||||
Loading…
Add table
Add a link
Reference in a new issue