TypeError:无法在RedisClient.internal_send_command中读取未定义的属性'length'

时间:2018-08-15 02:33:44

标签: node.js redis

我正在使用Node.js学习Redis的数据类型“ set”:

这些代码正在建立交易跟踪系统:

1。将交易标记为已发送给用户

2。检查用户是否收到一组交易

3。从已发送的交易中收集指标

//deal_metrics.js
var redis = require("redis");
var client = redis.createClient();

function markDealAsSent(dealId, userId) {
    client.internal_send_command(dealId, userId);
}

function sendDealIfNotSent(dealId, userId) {
    client.sismember(dealId, userId, function(err, reply){
        if (reply) {
            console.log("Deal", dealId, "was already sent to user", userId);
        } else {
            console.log("Sending", dealId, "to user", userId);
            //code to send the deal to the user would go here...//
            markDealAsSent(dealId, userId);
        }
    });
}

function showUsersThatReceivedAllDeals(dealIds){
    client.sinter(dealIds, function(err, reply){
        console.log(`${reply} received al the deals: ${dealIds}`);
    });
}

function showUsersThatReceivedAtLeastOneOfTheDeals(dealIds) {
    client.sunion(dealIds, function(err, reply){
        console.log(`${reply} received at least one of the deals: ${dealIds}`);
    });
}

markDealAsSent("deal:1", "user:1");
markDealAsSent("deal:1", "user:2");
markDealAsSent("deal:2", "user:1");
markDealAsSent("deal:2", "user:3");

sendDealIfNotSent("deal:1", "user:1");
sendDealIfNotSent("deal:1", "user:2");
sendDealIfNotSent("deal:1", "user:3");

showUsersThatReceivedAllDeals(["deal:1", "deal:2"]);
showUsersThatReceivedAtLeastOneOfTheDeals(["deal:1", "deal:2"]);

client.quit();

它在运行时报告意外错误

$ node deal_metrics.js 

/Users/me/node_modules/redis/index.js:875
    var len = args.length;
                   ^
TypeError: Cannot read property 'length' of undefined
    at RedisClient.internal_send_command (/Users/me/node_modules/redis/index.js:875:20)
    at markDealAsSent (/Users/me/Desktop/Code/Redis Essentials/Chapter 2:Advanced Data Tyeps/deal_metrics.js:5:12)
    at Object.<anonymous> (/Users/me/Desktop/CodeHero/Redis Essentials/Chapter 2:Advanced Data Tyeps/deal_metrics.js:32:1)
    at Module._compile (module.js:649:30)
    at Object.Module._extensions..js (module.js:660:10)
    at Module.load (module.js:561:32)
    at tryModuleLoad (module.js:501:12)
    at Function.Module._load (module.js:493:3)
    at Function.Module.runMain (module.js:690:10)
    at startup (bootstrap_node.js:194:16)

我在各个角落进行了搜索,但是没有找到合适的解决方案。

0 个答案:

没有答案