【发布时间】:2012-09-27 12:58:09
【问题描述】:
我有一个问题,EXEC 的回调随机返回一些值作为nulls。
代码在大多数情况下都能正常工作,但随机失败(或者如果我反复刷新浏览器)...
这里的代码被简化到失败的地步:
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
});
当它工作正常时,exec 回调返回:
[{
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'
}]
当它不起作用时,它会返回:(注意 null 值)
[{
owner: '123',
id: 'asdasdasd',
name: 'asdasdasd',
created_at: '2012-10-06T09:26:25.596Z',
updated_at: '2012-10-06T09:28:54.929Z'
}, null]
【问题讨论】:
-
听起来你在某处有竞争条件。您是在其他地方删除密钥还是设置过期时间?
-
关于失败,在调用 exec 之前,
console.log(transaction)的输出是什么样的?它应该向您显示电话。
标签: javascript node.js transactions redis node-redis