NodeJS Redis 客户端返回错误值 [英] NodeJS Redis Client Returning Wrong Value

查看:178
本文介绍了NodeJS Redis 客户端返回错误值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 NodeJS Redis 客户端 (Node Redis) 并调用 SISMEMBER Redis 命令.但是,当我调用该命令时,它始终返回 true,无论该值是否是该集合的成员.

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.

我将它与 Node IRC 模块结合使用.我不知道为什么 Redis 调用返回错误的值.我试过只隔离 Redis 代码(没有周围的代码),它工作正常.代码如下,谢谢帮助.

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.

这不起作用

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

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

这行得通

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

console.log(redisClient.sismember('visitedUsers', 'awdwf'));

推荐答案

redis 方法都是异步的.返回值只是布尔值,指示是否应该执行更多命令暂时发出(取决于命令队列大小是否超过高水位线——这类似于节点的 stream.write() 返回 false).

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).

尝试这样的事情:

client.sismember('visitedUsers', 'awdwf', function(err, reply) {
  if (err) throw err;
  console.log(reply);
});

这篇关于NodeJS Redis 客户端返回错误值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆