Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NodeJS Redis Client Returning Wrong Value

I'm using the NodeJS Redis client (Node Redis) and calling the SISMEMBER Redis command. However, when I call the command it always returns true, no matter whether or not the value is a member of the set.

I am using this in conjunction with the Node IRC module. I am at a loss for why the Redis call is returning the wrong value. I have tried isolating just the Redis code (without the surrounding code) and it works fine. Code follows, thank you for the help.

This does not work

var redis = require("redis");
var redisClient = redis.createClient();

ircClient.addListener('join', function(channel, who) {
    console.log(redisClient.sismember('visitedUsers', 'awdwf'));
    console.log(who + ' connected');
});

This works, however

var redis = require("redis");
var redisClient = redis.createClient();

console.log(redisClient.sismember('visitedUsers', 'awdwf'));
like image 424
AlienHoboken Avatar asked Oct 27 '25 05:10

AlienHoboken


1 Answers

redis methods are all asynchronous. The return values are just booleans indicating whether any more commands should be issued for the time being (depending on if the command queue size exceeds the high water mark -- this is similar to node's stream.write() returning false).

Try something like this:

client.sismember('visitedUsers', 'awdwf', function(err, reply) {
  if (err) throw err;
  console.log(reply);
});
like image 187
mscdex Avatar answered Oct 28 '25 20:10

mscdex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!