2016-03-22 37 views
0

如果在redis服務器執行命令時客戶端斷開連接,則使用LPOP時,彈出的項目會發生什麼?客戶端斷開連接時的redis lpop行爲

更具體地說,即使它沒有交付或者它保存在內存中,該項目是否被刪除,因爲命令沒有成功?

感謝您的任何幫助/指針。

回答

1

處理實際彈出邏輯的代碼部分忽略了客戶端狀態。 Redis不會等待響應發送完成以完成處理命令。如果像這樣等待,它會很慢,特別是單線程。

你可以看看,處理BLPOP怎麼看這種情況的部分代碼:

// here is where redis actually pops from the list 
    robj *value = listTypePop(o,where); 
    serverAssert(value != NULL); 

    // now it ads the reply to the client's queue (c is the client) 
    // but as you can see there is no return code from these methods 
    // and redis doesn't actually send anything when addReply is called 
    addReplyMultiBulkLen(c,2); 
    addReplyBulk(c,c->argv[j]); 
    addReplyBulk(c,value);