Refine connection strings (dotenv), Makefile targets
This commit is contained in:
parent
d2fa4c586f
commit
49654eeede
7 changed files with 49 additions and 7 deletions
|
|
@ -1,5 +1,26 @@
|
|||
import os
|
||||
|
||||
import dotenv
|
||||
import redis
|
||||
|
||||
|
||||
def get_redis_connection() -> redis.Redis:
|
||||
return redis.Redis(decode_responses=True)
|
||||
dotenv.load_dotenv()
|
||||
|
||||
URL = os.environ.get("REDIS_OM_URL", None)
|
||||
|
||||
|
||||
def get_redis_connection(**kwargs) -> 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 not url:
|
||||
import ipdb
|
||||
|
||||
ipdb.set_trace()
|
||||
if url:
|
||||
return redis.from_url(url, **kwargs)
|
||||
|
||||
# Decode from UTF-8 by default
|
||||
if "decode_responses" not in kwargs:
|
||||
kwargs["decode_responses"] = True
|
||||
return redis.Redis(**kwargs)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue