Coverage for src/task/redis_client.py: 0%
24 statements
« prev ^ index » next coverage.py v7.7.0, created at 2025-04-18 12:36 +0000
« prev ^ index » next coverage.py v7.7.0, created at 2025-04-18 12:36 +0000
1import time
3import redis
6class RedisClient:
7 def __init__(self):
8 self.host = "localhost"
9 self.port = 6379
10 self.decode_responses = True
12 def get_connection(self):
13 return redis.Redis(host=self.host, port=self.port, decode_responses=self.decode_responses)
15 def exec_cmd(self, command, *args, **kwargs):
16 max_retries = 3
17 timeout = 5
18 count = 0
19 while True:
20 try:
21 return command(*args, **kwargs)
22 except (redis.exceptions.ConnectionError, redis.exceptions.TimeoutError):
23 count += 1
24 if count > max_retries:
25 raise
26 print("Retrying in {} seconds".format(timeout))
27 time.sleep(timeout)
28 except Exception as ex:
29 print("Exception occured {}".format(ex))