2021-10-20 23:29:31 +02:00
|
|
|
import os
|
|
|
|
|
2021-10-22 15:33:05 +02:00
|
|
|
import aioredis
|
2021-10-20 23:29:31 +02:00
|
|
|
|
|
|
|
URL = os.environ.get("REDIS_OM_URL", None)
|
|
|
|
|
|
|
|
|
2021-11-10 00:59:10 +01:00
|
|
|
def get_redis_connection(**kwargs) -> aioredis.Redis:
|
2021-10-20 23:29:31 +02:00
|
|
|
# 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)
|
2021-10-20 23:29:31 +02:00
|
|
|
|
|
|
|
# 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)
|