0

错误输出:

[Error: ERR EXEC without MULTI]

节点脚本:

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();
  }); 
});
4

1 回答 1

3

这不是您使用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 库如何知道您正在尝试执行哪个。

于 2013-08-13T16:01:29.240 回答