Redis Sentinel support for AppConfig

This commit is contained in:
Jan Kessler
2025-03-18 09:28:47 +01:00
parent 9167a8bef0
commit e68cd9b671
5 changed files with 22 additions and 10 deletions

View File

@@ -33,7 +33,12 @@ def get_redis_connection(redis_url, sentinels, decode_responses=True):
else:
# Standard Redis connection
return redis.Redis.from_url(redis_url, decode_responses=decode_responses)
def get_sentinels_from_env(SENTINEL_HOSTS, SENTINEL_PORT):
sentinel_hosts=SENTINEL_HOSTS.split(',')
sentinel_port=int(SENTINEL_PORT)
return [(host, sentinel_port) for host in sentinel_hosts]
class AsyncRedisSentinelManager(socketio.AsyncRedisManager):
def __init__(self, sentinel_hosts, sentinel_port=26379, redis_port=6379, service="mymaster", db=0,
username=None, password=None, channel='socketio', write_only=False, logger=None, redis_options=None):
@@ -81,4 +86,4 @@ class AsyncRedisSentinelManager(socketio.AsyncRedisManager):
)
self.redis = sentinel.master_for(self._service)
self.pubsub = self.redis.pubsub(ignore_subscribe_messages=True)
self.pubsub = self.redis.pubsub(ignore_subscribe_messages=True)