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

Function hrandfieldCommand

app/redis-6.2.6/src/t_hash.c:1184–1209  ·  view source on GitHub ↗

HRANDFIELD key [ [WITHVALUES]] */

Source from the content-addressed store, hash-verified

1182
1183/* HRANDFIELD key [<count> [WITHVALUES]] */
1184void hrandfieldCommand(client *c) {
1185 long l;
1186 int withvalues = 0;
1187 robj *hash;
1188 ziplistEntry ele;
1189
1190 if (c->argc >= 3) {
1191 if (getLongFromObjectOrReply(c,c->argv[2],&l,NULL) != C_OK) return;
1192 if (c->argc > 4 || (c->argc == 4 && strcasecmp(c->argv[3]->ptr,"withvalues"))) {
1193 addReplyErrorObject(c,shared.syntaxerr);
1194 return;
1195 } else if (c->argc == 4)
1196 withvalues = 1;
1197 hrandfieldWithCountCommand(c, l, withvalues);
1198 return;
1199 }
1200
1201 /* Handle variant without <count> argument. Reply with simple bulk string */
1202 if ((hash = lookupKeyReadOrReply(c,c->argv[1],shared.null[c->resp]))== NULL ||
1203 checkType(c,hash,OBJ_HASH)) {
1204 return;
1205 }
1206
1207 hashTypeRandomElement(hash,hashTypeLength(hash),&ele,NULL);
1208 hashReplyFromZiplistEntry(c, &ele);
1209}

Callers

nothing calls this directly

Calls 9

getLongFromObjectOrReplyFunction · 0.85
strcasecmpFunction · 0.85
addReplyErrorObjectFunction · 0.85
lookupKeyReadOrReplyFunction · 0.85
checkTypeFunction · 0.85
hashTypeRandomElementFunction · 0.85
hashTypeLengthFunction · 0.85

Tested by

no test coverage detected