不確定它是否仍然適合您,但以下代碼會爲MULTI生成EXECABORT錯誤。 PS。我不是開發商的NodeJS :)
代碼:
var redis = require("redis"),
client = redis.createClient();
client.sadd("bigset", "a member");
client.sadd("bigset", "another member");
set_size = 20;
while (set_size > 0) {
client.sadd("bigset", "member " + set_size);
set_size -= 1;
}
// multi chain with an individual callback
client.multi()
.scard("bigset")
.smembers("bigset")
.set("a")
.keys("*", function (err, replies) {
// NOTE: code in this callback is NOT atomic
// this only happens after the the .exec call finishes.
client.mget(replies, redis.print);
})
.dbsize()
.exec(function (err, replies) {
// console.log("MULTI got " + replies.length + " replies");
// replies.forEach(function (reply, index) {
// console.log("Reply " + index + ": " + reply.toString());
// });
console.log(replies);
console.log(err);
client.quit();
});
輸出:
undefined
{ [ReplyError: EXECABORT Transaction discarded because of previous errors.] command: 'EXEC', code: 'EXECABORT', errors: [ { [ReplyError: ERR wrong number of arguments for 'set' command] command: 'SET', args: [Object], code: 'ERR', position: 2 } ] }
說明:SET命令需要兩個參數。我只給了一個,並打印錯誤到控制檯。
有關該主題的詳細說明在this問題。請參閱BridgeAR的最後一條評論。
取自nodejs git repo的示例代碼