MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / blockingPopGenericCommand

Function blockingPopGenericCommand

src/t_list.cpp:935–980  ·  view source on GitHub ↗

Blocking RPOP/LPOP */

Source from the content-addressed store, hash-verified

933
934/* Blocking RPOP/LPOP */
935void blockingPopGenericCommand(client *c, int where) {
936 robj *o;
937 mstime_t timeout;
938 int j;
939
940 if (getTimeoutFromObjectOrReply(c,c->argv[c->argc-1],&timeout,UNIT_SECONDS)
941 != C_OK) return;
942
943 for (j = 1; j < c->argc-1; j++) {
944 o = lookupKeyWrite(c->db,c->argv[j]);
945 if (o != NULL) {
946 if (checkType(c,o,OBJ_LIST)) {
947 return;
948 } else {
949 if (listTypeLength(o) != 0) {
950 /* Non empty list, this is like a normal [LR]POP. */
951 robj *value = listTypePop(o,where);
952 serverAssert(value != NULL);
953
954 addReplyArrayLen(c,2);
955 addReplyBulk(c,c->argv[j]);
956 addReplyBulk(c,value);
957 decrRefCount(value);
958 listElementsRemoved(c,c->argv[j],where,o,1);
959
960 /* Replicate it as an [LR]POP instead of B[LR]POP. */
961 rewriteClientCommandVector(c,2,
962 (where == LIST_HEAD) ? shared.lpop : shared.rpop,
963 c->argv[j]);
964 return;
965 }
966 }
967 }
968 }
969
970 /* If we are not allowed to block the client, the only thing
971 * we can do is treating it as a timeout (even with timeout 0). */
972 if (c->flags & CLIENT_DENY_BLOCKING) {
973 addReplyNullArray(c);
974 return;
975 }
976
977 /* If the keys do not exist we must block */
978 listPos pos = {where};
979 blockForKeys(c,BLOCKED_LIST,c->argv + 1,c->argc - 2,timeout,NULL,&pos,NULL);
980}
981
982/* BLPOP <key> [<key> ...] <timeout> */
983void blpopCommand(client *c) {

Callers 2

blpopCommandFunction · 0.85
brpopCommandFunction · 0.85

Calls 12

lookupKeyWriteFunction · 0.85
checkTypeFunction · 0.85
listTypeLengthFunction · 0.85
listTypePopFunction · 0.85
addReplyArrayLenFunction · 0.85
addReplyBulkFunction · 0.85
decrRefCountFunction · 0.85
listElementsRemovedFunction · 0.85
addReplyNullArrayFunction · 0.85
blockForKeysFunction · 0.85

Tested by

no test coverage detected