1
我有一個問題,EXEC的回調隨機返回一些值,如null
s。Redis MULTI事務在NodeJS的EXEC回調中隨機返回null
的代碼工作正常,大部分的時間,但它隨機失敗(或者我刷新多次瀏覽器)...
這裏是淪落到這種地步的代碼,其中它的失敗:
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]
聽起來像你有某種地方的競爭條件。你是在其他地方刪除密鑰還是設置過期? – Bill
關於失敗,在調用exec之前'console.log(transaction)'的輸出是什麼樣的?它應該顯示你的電話。 – sintaxi