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

Function srandmemberCommand

app/redis-6.2.6/src/t_set.c:811–835  ·  view source on GitHub ↗

SRANDMEMBER [ ] */

Source from the content-addressed store, hash-verified

809
810/* SRANDMEMBER [<count>] */
811void srandmemberCommand(client *c) {
812 robj *set;
813 sds ele;
814 int64_t llele;
815 int encoding;
816
817 if (c->argc == 3) {
818 srandmemberWithCountCommand(c);
819 return;
820 } else if (c->argc > 3) {
821 addReplyErrorObject(c,shared.syntaxerr);
822 return;
823 }
824
825 /* Handle variant without <count> argument. Reply with simple bulk string */
826 if ((set = lookupKeyReadOrReply(c,c->argv[1],shared.null[c->resp]))
827 == NULL || checkType(c,set,OBJ_SET)) return;
828
829 encoding = setTypeRandomElement(set,&ele,&llele);
830 if (encoding == OBJ_ENCODING_INTSET) {
831 addReplyBulkLongLong(c,llele);
832 } else {
833 addReplyBulkCBuffer(c,ele,sdslen(ele));
834 }
835}
836
837int qsortCompareSetsByCardinality(const void *s1, const void *s2) {
838 if (setTypeSize(*(robj**)s1) > setTypeSize(*(robj**)s2)) return 1;

Callers

nothing calls this directly

Calls 8

addReplyErrorObjectFunction · 0.85
lookupKeyReadOrReplyFunction · 0.85
checkTypeFunction · 0.85
setTypeRandomElementFunction · 0.85
addReplyBulkLongLongFunction · 0.85
addReplyBulkCBufferFunction · 0.85
sdslenFunction · 0.85

Tested by

no test coverage detected