MCPcopy Create free account
hub / github.com/F-Stack/f-stack / zrandmemberCommand

Function zrandmemberCommand

app/redis-6.2.6/src/t_zset.c:4208–4233  ·  view source on GitHub ↗

ZRANDMEMBER key [ [WITHSCORES]] */

Source from the content-addressed store, hash-verified

4206
4207/* ZRANDMEMBER key [<count> [WITHSCORES]] */
4208void zrandmemberCommand(client *c) {
4209 long l;
4210 int withscores = 0;
4211 robj *zset;
4212 ziplistEntry ele;
4213
4214 if (c->argc >= 3) {
4215 if (getLongFromObjectOrReply(c,c->argv[2],&l,NULL) != C_OK) return;
4216 if (c->argc > 4 || (c->argc == 4 && strcasecmp(c->argv[3]->ptr,"withscores"))) {
4217 addReplyErrorObject(c,shared.syntaxerr);
4218 return;
4219 } else if (c->argc == 4)
4220 withscores = 1;
4221 zrandmemberWithCountCommand(c, l, withscores);
4222 return;
4223 }
4224
4225 /* Handle variant without <count> argument. Reply with simple bulk string */
4226 if ((zset = lookupKeyReadOrReply(c,c->argv[1],shared.null[c->resp]))== NULL ||
4227 checkType(c,zset,OBJ_ZSET)) {
4228 return;
4229 }
4230
4231 zsetTypeRandomElement(zset, zsetLength(zset), &ele,NULL);
4232 zsetReplyFromZiplistEntry(c,&ele);
4233}

Callers

nothing calls this directly

Calls 9

getLongFromObjectOrReplyFunction · 0.85
strcasecmpFunction · 0.85
addReplyErrorObjectFunction · 0.85
lookupKeyReadOrReplyFunction · 0.85
checkTypeFunction · 0.85
zsetTypeRandomElementFunction · 0.85
zsetLengthFunction · 0.85

Tested by

no test coverage detected