javascript - NodeJS Redis Client Returning Wrong Value - Stack Overflow

I'm using the NodeJS Redis client (Node Redis) and calling the SISMEMBER Redis mand. However, when

I'm using the NodeJS Redis client (Node Redis) and calling the SISMEMBER Redis mand. However, when I call the mand 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'));

I'm using the NodeJS Redis client (Node Redis) and calling the SISMEMBER Redis mand. However, when I call the mand 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'));
Share Improve this question asked Dec 21, 2014 at 1:04 AlienHobokenAlienHoboken 2,80022 silver badges23 bronze badges 1
  • I doubt if the above code you said is working would actually work if tested with a non-existent user, in which case it should return 0. – Hanu Commented Feb 28, 2018 at 11:39
Add a ment  | 

1 Answer 1

Reset to default 5

redis methods are all asynchronous. The return values are just booleans indicating whether any more mands should be issued for the time being (depending on if the mand 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);
});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745600880a4635392.html

相关推荐

  • javascript - NodeJS Redis Client Returning Wrong Value - Stack Overflow

    I'm using the NodeJS Redis client (Node Redis) and calling the SISMEMBER Redis mand. However, when

    14小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信