From ec6db95d47b0eb1cae15c9b19e810d842592aad3 Mon Sep 17 00:00:00 2001 From: jingyiliu Date: Mon, 15 May 2023 18:23:09 +0800 Subject: [PATCH] [backend] make sure redis consumer group exist --- ymir/backend/src/ymir_app/app/libs/redis_stream.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ymir/backend/src/ymir_app/app/libs/redis_stream.py b/ymir/backend/src/ymir_app/app/libs/redis_stream.py index 62212f7438..dc40b8e364 100644 --- a/ymir/backend/src/ymir_app/app/libs/redis_stream.py +++ b/ymir/backend/src/ymir_app/app/libs/redis_stream.py @@ -25,6 +25,12 @@ async def init_group_and_stream(self) -> None: if not exists: logger.info("init redis stream and consumer group") await self._conn.xgroup_create(name=self.stream_name, groupname=self.group_name, mkstream=True) + else: + groups = await self._conn.xinfo_groups(self.stream_name) + if not any(group["name"] == self.group_name for group in groups): + logger.info("init consumer group on existing stream") + # set id = '0' to make sure this new consumer group will catch up existing messages in stream + await self._conn.xgroup_create(name=self.stream_name, groupname=self.group_name, id="0") async def connect(self) -> None: self._conn = await redis.from_url(self.redis_uri, decode_responses=True)