2017-04-04 19 views
0

我可以在docs從Node.js的Redis的客戶端讀取:讓Node.js的Redis的客戶。多()和.batch()返回結果錯誤用於測試目的

If your code contains an syntax error an EXECABORT error is going to be thrown and all commands are going to be aborted. That error contains a .errors property that contains the concret errors. If all commands were queued successfully and an error is thrown by redis while processing the commands that error is going to be returned in the result array! No other command is going to be aborted though than the onces failing.

我怎樣寫一個Node.js Redis客戶端的.multi().batch()爲了在測試結果中出現錯誤?

回答

0

不確定它是否仍然適合您,但以下代碼會爲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的示例代碼

相關問題