【问题标题】:node-redis reports "EXEC without MULT"node-redis 报告“没有 MULT 的执行”
【发布时间】:2013-08-14 00:01:29
【问题描述】:

错误输出:

[Error: ERR EXEC without MULTI]

Nodejs 脚本:

client  = redis.createClient(REDIS_SOCK);

client.keys(['*'], function(err, keys) {
  client.multi();

  keys.forEach(function(key) {
      count = start;

      while(count <= end) {
          client.zrangebyscore([key, count, count + 120000], function() {});
          count += 120000;
      }   
  }); 

  client.exec(function(err, results) {
      if(err) { console.log(err);     }   
      else    { console.log(results); }
      client.quit();
  }); 
});

【问题讨论】:

    标签: node.js redis node-redis


    【解决方案1】:

    这不是你使用multi/exec的方式。 multi 调用返回一个您必须持有的对象:

    client  = redis.createClient(REDIS_SOCK);
    
    client.keys(['*'], function(err, keys) {
      multi = client.multi();
    
      keys.forEach(function(key) {
          count = start;
    
          while(count <= end) {
              multi.zrangebyscore([key, count, count + 120000], function() {});
              count += 120000;
          }   
      }); 
    
      multi.exec(function(err, results) {
          if(err) { console.log(err);     }   
          else    { console.log(results); }
          client.quit();
      }); 
    });
    

    由于您可以同时激活多个multis,这就是redis lib 知道您要执行哪个的方式。

    【讨论】:

    • 我正在使用以下代码client.multi([ ["mget", "multifoo", "multibar", redis.print], ["incr", "multifoo"], ["incr", "multibar"]]).exec(function (err, replies) { console.log(replies.toString());});,但我仍然收到“EXEC without MULTI”错误。即使使用这种方法,redis lib 是否有可能对执行哪个 multi 感到困惑?
    猜你喜欢
    • 1970-01-01
    • 2023-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多