客户端断开连接时的redis lpop行为

时间:2016-03-22 15:45:08

标签: redis

如果客户端在redis服务器执行命令时断开连接时使用LPOP,那么弹出的项目会发生什么变化?

更具体地说,即使没有交付项目,项目是否会被删除,或者因为命令没有成功而将其保存在内存中?

感谢您提供任何帮助/指示。

1 个答案:

答案 0 :(得分: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);
相关问题