Skip to content

Commit

Permalink
Update caching.py
Browse files Browse the repository at this point in the history
  • Loading branch information
kiran-aot committed Jun 13, 2024
1 parent 6d4bb1f commit f76799e
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions forms-flow-api-utils/src/formsflow_api_utils/utils/caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,8 @@
from redis.client import Redis
import json
import os
from redis.cluster import RedisCluster
from urllib.parse import urlparse
from redis import ConnectionPool

def get_cluster_startup_nodes(cluster_url):
parsed_url = urlparse(cluster_url)
hosts_ports = parsed_url.netloc.split(',')
startup_nodes = []
for host_port in hosts_ports:
host, port = host_port.split(':')
startup_nodes.append({"host": host, "port": int(port)})
return startup_nodes

class RedisManager:
"""
Expand Down Expand Up @@ -44,9 +35,8 @@ def get_client(cls, app=None) -> Redis:
if app is None:
app = current_app
redis_url = app.config.get("REDIS_URL")
startup_nodes = get_cluster_startup_nodes(redis_url)
if redis_cluster:
cls._redis_client = RedisCluster(startup_nodes=startup_nodes, decode_responses=True)
cls._redis_client = redis.StrictRedis.from_url(redis_url, decode_responses=True, connection_pool=ConnectionPool.from_url(redis_url), cluster=True)
else:
cls._redis_client = redis.StrictRedis.from_url(redis_url)
app.logger.info("Redis client initiated successfully")
Expand Down

0 comments on commit f76799e

Please sign in to comment.