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