Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ export function createAdapter(
redisClient: any,
opts?: RedisStreamsAdapterOptions & ClusterAdapterOptions
) {
const internalRedisClient =
typeof redisClient.createPool === "function"
? redisClient.createPool()
: redisClient;
const namespaceToAdapters = new Map<string, RedisStreamsAdapter>();
const options = Object.assign(
{
Expand All @@ -74,7 +78,7 @@ export function createAdapter(
async function poll() {
try {
let response = await XREAD(
redisClient,
internalRedisClient,
options.streamName,
offset,
options.readCount
Expand Down Expand Up @@ -106,7 +110,7 @@ export function createAdapter(
}

return function (nsp) {
const adapter = new RedisStreamsAdapter(nsp, redisClient, options);
const adapter = new RedisStreamsAdapter(nsp, internalRedisClient, options);
namespaceToAdapters.set(nsp.name, adapter);

if (!polling) {
Expand Down
39 changes: 24 additions & 15 deletions lib/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ export function hasBinary(obj: any, toJSON?: boolean): boolean {
* @see https://github.com/redis/node-redis
*/
function isRedisV4Client(redisClient: any) {
return typeof redisClient.sSubscribe === "function";
return (
typeof redisClient.sSubscribe === "function" ||
typeof redisClient.totalClients === "number"
);
}

/**
Expand Down Expand Up @@ -68,21 +71,27 @@ export function XREAD(
) {
if (isRedisV4Client(redisClient)) {
return import("redis").then((redisPackage) => {
return redisClient.xRead(
redisPackage.commandOptions({
isolated: true,
}),
[
{
key: streamName,
id: offset,
},
],
const streams = [
{
COUNT: readCount,
BLOCK: 5000,
}
);
key: streamName,
id: offset,
},
];
const options = {
COUNT: readCount,
BLOCK: 5000,
};
if (redisPackage.commandOptions) {
return redisClient.xRead(
redisPackage.commandOptions({
isolated: true,
}),
streams,
options
);
} else {
return redisClient.xRead(streams, options);
}
});
} else {
return redisClient
Expand Down