Skip to content

Commit 3a0185f

Browse files
committed
Adds REDIS_URL support and updates the docs
1 parent b41fa22 commit 3a0185f

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ REDIS_HOST="your.redis.host.example.com"
101101
REDIS_PORT=6379
102102
REDIS_PASSWORD="YourRedisP@ssword!"
103103
104+
# OR, if your host provides a [Connection URL](https://redis-py.readthedocs.io/en/stable/#quickly-connecting-to-redis)
105+
REDIS_URL="redis://YourUsername:YourRedisP@ssword!@your.redis.host.example.com:6379"
106+
104107
# deta
105108
DETA_BASE_NAME="steamcmd"
106109
DETA_PROJECT_KEY="YourDet@ProjectKey!"

src/functions.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,15 @@ def redis_read(app_id):
9090
"""
9191

9292
# parse redis config and connect
93-
rds = redis.Redis(
94-
host=os.environ["REDIS_HOST"],
95-
port=os.environ["REDIS_PORT"],
96-
password=os.environ["REDIS_PASSWORD"],
97-
)
93+
# try connection string, or default to separate REDIS_* env vars
94+
if "REDIS_URL" in os.environ:
95+
rds = redis.Redis.from_url(os.environ["REDIS_URL"])
96+
else:
97+
rds = redis.Redis(
98+
host=os.environ["REDIS_HOST"],
99+
port=os.environ["REDIS_PORT"],
100+
password=os.environ["REDIS_PASSWORD"],
101+
)
98102

99103
try:
100104
# get info from cache

0 commit comments

Comments
 (0)