Redis MULTI transaction randomly returning null on EXEC callback in NodeJS

I have a problem where EXEC's callback randomly returns some values as nulls.

The code works fine most of the times, but it fails randomly (or if I refresh the browser repeatedly)...

Here's the code reduced to the point where it's failing:

var transaction = client.multi();
reply.forEach(function (id) { // reply always equals [ 'mykey1', 'mykey2' ]
  transaction.hgetall(namespace + ":" + id);
});
transaction.exec(function (err, replies) {
  // 'replies' sometimes returns all the responses properly,
  // other times it returns some of the values as null
  // See the examples I wrote below
});

When it works fine, the exec callback returns this:

[{
  owner: '123',
  id: 'asdasdasd',
  name: 'asdasdasd',
  created_at: '2012-10-06T09:26:25.596Z',
  updated_at: '2012-10-06T09:28:54.929Z'
},
{
  owner: '456',
  id: 'asdfsdfasdf',
  name: 'asdfsdfasdf',
  created_at: '2012-10-06T09:27:19.251Z',
  updated_at: '2012-10-06T09:28:03.116Z'
}]

When it doesn't work, it's returning this: (notice the null value)

[{
  owner: '123',
  id: 'asdasdasd',
  name: 'asdasdasd',
  created_at: '2012-10-06T09:26:25.596Z',
  updated_at: '2012-10-06T09:28:54.929Z'
}, null]

What is your redis version?

Versions before 2.6.5 executed transactions even if some of the commands failed to be queued - you need to check if each command inside transaction block does fail (using the error parameter of callback).

If you are using redis 2.6.5 or newer, EXEC command of transaction with commands which were not queued properly would return error, so that should not be your case, and probable explanation would be some race condition or nonexistent key as hinted in commend above. "null" reply from hgetall means that the key does not exists - so maybe it really does not exist at the time of executing the transaction?