I am getting a Type Error when creating a set type of redis database in node.js app

851 Views Asked by At

I am trying to add a set to a redis database in a node.js app like this:

let redisConnect = async () => {

  redisClient.on('error', (err) => {
    console.log('Redis Client Error', err);
  });

  redisClient.on('ready', () => console.log('Redis is ready'));
  
  await redisClient.connect();

  redisClient.sadd(['tags', 'angularjs', 'reactjs', 'nodejs'], function(err, reply) {
    console.log(reply);
  });
  
};

redisConnect();

This error is thrown: TypeError: redisClient.sadd is not a function

I am able to set other Redis database types on this client like list or string.

1

There are 1 best solutions below

0
On

I do not understand fully how I solved this problem. I switched from the redis library to ioredis and got rid of:

await redisClient.connect();

and added 'await' to

await redisClient.sadd(['tags', 'angularjs', 'reactjs', 'nodejs'], function(err, reply) {
    console.log(reply);
  });

I think the redisClient.connect( ) might have been redundant. This threw an error when I switched to ioredis :

Error: Redis is already connecting/connected

Possibly someone will have an explanation for this solution.