2021-10-20 14:29:31 -07:00
|
|
|
import os
|
|
|
|
|
2022-08-10 15:21:13 +03:00
|
|
|
from . import redis
|
2021-10-20 14:29:31 -07:00
|
|
|
|
2022-05-01 17:03:05 +03:00
|
|
|
|
2021-10-20 14:29:31 -07:00
|
|
|
URL = os.environ.get("REDIS_OM_URL", None)
|
|
|
|
|
|
|
|
|
2022-08-10 15:21:13 +03:00
|
|
|
def get_redis_connection(**kwargs) -> redis.Redis:
|
2022-09-08 06:53:24 -04:00
|
|
|
# Decode from UTF-8 by default
|
|
|
|
if "decode_responses" not in kwargs:
|
|
|
|
kwargs["decode_responses"] = True
|
|
|
|
|
2021-10-20 14:29:31 -07: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:
|
2022-08-10 15:21:13 +03:00
|
|
|
return redis.Redis.from_url(url, **kwargs)
|
2021-10-20 14:29:31 -07:00
|
|
|
|
2022-08-10 15:21:13 +03:00
|
|
|
return redis.Redis(**kwargs)
|