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

Function srandmemberCommand

src/t_set.cpp:822–846  ·  view source on GitHub ↗

SRANDMEMBER [ ] */

Source from the content-addressed store, hash-verified

820
821/* SRANDMEMBER [<count>] */
822void srandmemberCommand(client *c) {
823 robj_roptr set;
824 const char *ele;
825 int64_t llele = 0;
826 int encoding;
827
828 if (c->argc == 3) {
829 srandmemberWithCountCommand(c);
830 return;
831 } else if (c->argc > 3) {
832 addReplyErrorObject(c,shared.syntaxerr);
833 return;
834 }
835
836 /* Handle variant without <count> argument. Reply with simple bulk string */
837 if ((set = lookupKeyReadOrReply(c,c->argv[1],shared.null[c->resp]))
838 == nullptr || checkType(c,set,OBJ_SET)) return;
839
840 encoding = setTypeRandomElement(set,&ele,&llele);
841 if (encoding == OBJ_ENCODING_INTSET) {
842 addReplyBulkLongLong(c,llele);
843 } else {
844 addReplyBulkCBuffer(c,ele,sdslen(ele));
845 }
846}
847
848int qsortCompareSetsByCardinality(const void *s1, const void *s2) {
849 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