Question

Error Output:

[Error: ERR EXEC without MULTI]

Nodejs Script:

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();
  }); 
});
Était-ce utile?

La solution

That's not how you use multi/exec. The multi call returns an object that you must hold on to:

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

Since you can have many multis active at a time, this is how the redis lib knows which one you're trying to exec.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top