From 834d3d5f71446164c86427f5d11d10c9ab7b2cf0 Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Tue, 7 May 2024 07:20:43 +0200 Subject: [PATCH] refactor: remove redis import --- lib/util.ts | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/lib/util.ts b/lib/util.ts index c311ce4..e0f1942 100644 --- a/lib/util.ts +++ b/lib/util.ts @@ -1,5 +1,4 @@ import { randomBytes } from "crypto"; -import { commandOptions } from "redis"; export function hasBinary(obj: any, toJSON?: boolean): boolean { if (!obj || typeof obj !== "object") { @@ -74,21 +73,23 @@ export function XREAD( readCount: number ) { if (isRedisV4Client(redisClient)) { - return redisClient.xRead( - commandOptions({ - isolated: true, - }), - [ + return import("redis").then((redisPackage) => { + return redisClient.xRead( + redisPackage.commandOptions({ + isolated: true, + }), + [ + { + key: streamName, + id: offset, + }, + ], { - key: streamName, - id: offset, - }, - ], - { - COUNT: readCount, - BLOCK: 5000, - } - ); + COUNT: readCount, + BLOCK: 5000, + } + ); + }); } else { return redisClient .xread("BLOCK", 100, "COUNT", readCount, "STREAMS", streamName, offset)