Caught exception: TypeError: listener is not a function while publish redis client using node v16.16.0, redis-cli 7.0.0 & "redis": "^4.2.0",

Viewed 170

When using node v16.16.0, redis-cli 7.0.0 & "redis": "^4.2.0"

getting such exeption below:

Caught exception: TypeError: listener is not a function Exception origin: uncaughtException[2022-07-18T07:39:30.386Z] process.on uncaughtException ERRORCODE 105199 TypeError: listener is not a function at Function._RedisCommandsQueue_emitPubSubMessage (/mnt/c/Projects/konnectcore/app/sse/sse/node_modules/@redis/client/dist/lib/client/commands-queue.js:241:9) at RedisCommandsQueue._RedisCommandsQueue_handlePubSubReply (/mnt/c/Projects/konnectcore/app/sse/sse/node_modules/@redis/client/dist/lib/client/commands-queue.js:283:100)

It's working fine while using node redis "redis": "^2.8.0".

1 Answers

I had a similar issue where I was using probably some old way of subscribing and receiving the messages. Something like this:

sub.on('message', (channel, message) => {
  redisClient.hSet('values', message, someFunction);
});

sub.subscribe('channel');

I hope you are using the right way of publishing and subscribing to a channel in redis client. Here is one example from their documentation:

// This is how you create the client
import { createClient } from 'redis';
const client = createClient();

// This is the subscriber part
const subscriber = client.duplicate();
await subscriber.connect();
await subscriber.subscribe('channel', (message) => {
  console.log(message); // 'message'
});

// This is an example of how to publish a message to the same channel
await publisher.publish('channel', 'message');

Here is the link if you would like to see some more details about publishing and subscribing of the messages using node-redis client: https://github.com/redis/node-redis#pubsub

Related