aboutsummaryrefslogtreecommitdiff
path: root/qc_app/db_utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'qc_app/db_utils.py')
-rw-r--r--qc_app/db_utils.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/qc_app/db_utils.py b/qc_app/db_utils.py
index 75b6b73..ef26398 100644
--- a/qc_app/db_utils.py
+++ b/qc_app/db_utils.py
@@ -2,10 +2,11 @@
import logging
import traceback
import contextlib
+from urllib.parse import urlparse
from typing import Any, Tuple, Optional, Iterator, Callable
-from urllib.parse import urlparse
import MySQLdb as mdb
+from redis import Redis
from flask import current_app as app
def parse_db_url(db_url) -> Tuple:
@@ -37,3 +38,9 @@ def with_db_connection(func: Callable[[mdb.Connection], Any]) -> Any:
"""Call `func` with a MySQDdb database connection."""
with database_connection(app.config["SQL_URI"]) as conn:
return func(conn)
+
+def with_redis_connection(func: Callable[[Redis], Any]) -> Any:
+ """Call `func` with a redis connection."""
+ redisuri = app.config["REDIS_URL"]
+ with Redis.from_url(redisuri, decode_responses=True) as rconn:
+ return func(rconn)