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

Function blockingGenericZpopCommand

src/t_zset.cpp:3943–3976  ·  view source on GitHub ↗

BZPOPMIN / BZPOPMAX actual implementation. */

Source from the content-addressed store, hash-verified

3941
3942/* BZPOPMIN / BZPOPMAX actual implementation. */
3943void blockingGenericZpopCommand(client *c, int where) {
3944 robj *o;
3945 mstime_t timeout;
3946 int j;
3947
3948 if (getTimeoutFromObjectOrReply(c,c->argv[c->argc-1],&timeout,UNIT_SECONDS)
3949 != C_OK) return;
3950
3951 for (j = 1; j < c->argc-1; j++) {
3952 o = lookupKeyWrite(c->db,c->argv[j]);
3953 if (checkType(c,o,OBJ_ZSET)) return;
3954 if (o != NULL) {
3955 if (zsetLength(o) != 0) {
3956 /* Non empty zset, this is like a normal ZPOP[MIN|MAX]. */
3957 genericZpopCommand(c,&c->argv[j],1,where,1,NULL);
3958 /* Replicate it as an ZPOP[MIN|MAX] instead of BZPOP[MIN|MAX]. */
3959 rewriteClientCommandVector(c,2,
3960 where == ZSET_MAX ? shared.zpopmax : shared.zpopmin,
3961 c->argv[j]);
3962 return;
3963 }
3964 }
3965 }
3966
3967 /* If we are not allowed to block the client and the zset is empty the only thing
3968 * we can do is treating it as a timeout (even with timeout 0). */
3969 if (c->flags & CLIENT_DENY_BLOCKING) {
3970 addReplyNullArray(c);
3971 return;
3972 }
3973
3974 /* If the keys do not exist we must block */
3975 blockForKeys(c,BLOCKED_ZSET,c->argv + 1,c->argc - 2,timeout,NULL,NULL,NULL);
3976}
3977
3978// BZPOPMIN key [key ...] timeout
3979void bzpopminCommand(client *c) {

Callers 2

bzpopminCommandFunction · 0.85
bzpopmaxCommandFunction · 0.85

Calls 8

lookupKeyWriteFunction · 0.85
checkTypeFunction · 0.85
zsetLengthFunction · 0.85
genericZpopCommandFunction · 0.85
addReplyNullArrayFunction · 0.85
blockForKeysFunction · 0.85

Tested by

no test coverage detected