redis-om-python/aredis_om/connections.py

23 lines
564 B
Python
Raw Normal View History

import os
import aioredis
import dotenv
dotenv.load_dotenv()
URL = os.environ.get("REDIS_OM_URL", None)
2021-11-10 00:59:10 +01:00
def get_redis_connection(**kwargs) -> aioredis.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:
2021-11-10 00:59:10 +01:00
return aioredis.Redis.from_url(url, **kwargs)
# Decode from UTF-8 by default
if "decode_responses" not in kwargs:
kwargs["decode_responses"] = True
2021-11-10 00:59:10 +01:00
return aioredis.Redis(**kwargs)