Skip to content

Commit a8c8c0e

Browse files
committed
Fix real-time message updates: use blocking Redis XREAD
The chat message list wasn't updating in real-time because XREAD was using non-blocking mode, causing it to return immediately without waiting for new messages. Root cause: - XREAD_TIMEOUT = 0 was converted to block=None (non-blocking) - In old aioredis: timeout=0 meant "block forever" - In new redis library: block=None means "non-blocking" (return immediately) - This caused XREAD to constantly poll without waiting for messages Fix: - Changed to block=5000 (5 seconds) for proper blocking behavior - XREAD now waits up to 5 seconds for new messages before returning - Messages now appear in real-time for all connected users Tested: - Users connecting to the same room see each other's messages immediately - Message list updates within milliseconds of sending - No more need to refresh or reconnect to see new messages
1 parent 7e283e6 commit a8c8c0e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

chat.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ async def ws_send_moderator(websocket: WebSocket, chat_info: dict):
135135
events = await pool.xread(
136136
streams=latest_ids,
137137
count=XREAD_COUNT,
138-
block=XREAD_TIMEOUT if XREAD_TIMEOUT > 0 else None
138+
block=5000 # Block for 5 seconds waiting for new messages
139139
)
140140
for stream, messages in events:
141141
for e_id, e in messages:
@@ -182,7 +182,7 @@ async def ws_send(websocket: WebSocket, chat_info: dict):
182182
events = await pool.xread(
183183
streams=latest_ids,
184184
count=XREAD_COUNT,
185-
block=XREAD_TIMEOUT if XREAD_TIMEOUT > 0 else None
185+
block=5000 # Block for 5 seconds waiting for new messages
186186
)
187187
for stream, messages in events:
188188
for e_id, e in messages:

0 commit comments

Comments
 (0)