0

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();
  }); 
});
aXqd
  • 733
  • 5
  • 17

1 Answers1

3

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.

Aaron Dufour
  • 17,288
  • 1
  • 47
  • 69
  • i am using following code `client.multi([ ["mget", "multifoo", "multibar", redis.print], ["incr", "multifoo"], ["incr", "multibar"]]).exec(function (err, replies) { console.log(replies.toString());});` and still i am getting the “EXEC without MULTI” error. Is there a possibility that redis lib can get confused even with this method about which multi to execute ? – swapnilsarwe Apr 01 '14 at 20:37