fixed redis subscription keysapce issue mismatch

This commit is contained in:
2025-07-28 00:53:37 +09:30
parent c40f6aeef7
commit cc1e2c7f84
2 changed files with 7 additions and 6 deletions
+1 -1
View File
@@ -29,7 +29,7 @@ DATABASE_URL = "mysql://root:password@172.17.0.1:3306/theapi"
redis_connection_pool = redis.ConnectionPool.from_url(
REDIS_URL,
decode_responses=True,
max_connections=10,
max_connections=10000,
socket_timeout=5
)
+6 -5
View File
@@ -21,21 +21,22 @@ def redis_subscribe(worker_id):
"""
redis_client = get_redis_client()
redis_client.config_set("notify-keyspace-events", "KA")
logger.debug(f"Total connections in pool: {len(redis_client.connection_pool._available_connections)}")
redis_client.config_set("notify-keyspace-events", "KEA")
logger.debug(f"Total available in pool: {len(redis_client.connection_pool._available_connections)}")
pubsub = redis_client.pubsub()
channels = [
f"__keyspace@0__:worker_status_{worker_id}",
f"__keyspace@0__:worker_queue_{worker_id}"
f"__keyspace@2__:worker_status_{worker_id}", #TODO - The number 2 here is important, it's the Redis DB number which must align with the resid URL in config.py!
f"__keyspace@2__:worker_queue_{worker_id}"
]
logger.error(f"Subscribed to {channels}")
try:
pubsub.psubscribe(channels)
logger.info(f"Subscribed to Redis keyspace events: {channels}")
while not thread_stop_flags.get(worker_id, False):
message = pubsub.get_message(timeout=1.0)
logger.debug(message)
if message and message["type"] in ["pmessage", "message"]:
current_status = redis_client.get(f"worker_status_{worker_id}")
logger.debug(f"[{worker_id}] Current Redis status: {current_status}")