Skip to content

Commit 1c206b1

Browse files
use createPool with redis@5
1 parent 1921b51 commit 1c206b1

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

lib/util.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ function mapResult(result) {
5757
};
5858
}
5959

60+
const POOL = Symbol("redis-v5-pool");
61+
6062
/**
6163
* @see https://redis.io/commands/xread/
6264
*/
@@ -68,6 +70,28 @@ export function XREAD(
6870
blockTimeInMs: number
6971
) {
7072
if (isNodeRedisClient(redisClient)) {
73+
if (typeof redisClient.createPool === "function") {
74+
if (!redisClient[POOL]) {
75+
redisClient[POOL] = redisClient.createPool();
76+
77+
redisClient.on("end", () => {
78+
redisClient[POOL].destroy();
79+
});
80+
}
81+
82+
return redisClient[POOL].xRead(
83+
[
84+
{
85+
key: streamName,
86+
id: offset,
87+
},
88+
],
89+
{
90+
COUNT: readCount,
91+
BLOCK: blockTimeInMs,
92+
}
93+
);
94+
}
7195
return redisClient.xRead(
7296
[
7397
{

0 commit comments

Comments
 (0)