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

Function pfaddCommand

app/redis-6.2.6/src/hyperloglog.c:1180–1217  ·  view source on GitHub ↗

PFADD var ele ele ele ... ele => :0 or :1 */

Source from the content-addressed store, hash-verified

1178
1179/* PFADD var ele ele ele ... ele => :0 or :1 */
1180void pfaddCommand(client *c) {
1181 robj *o = lookupKeyWrite(c->db,c->argv[1]);
1182 struct hllhdr *hdr;
1183 int updated = 0, j;
1184
1185 if (o == NULL) {
1186 /* Create the key with a string value of the exact length to
1187 * hold our HLL data structure. sdsnewlen() when NULL is passed
1188 * is guaranteed to return bytes initialized to zero. */
1189 o = createHLLObject();
1190 dbAdd(c->db,c->argv[1],o);
1191 updated++;
1192 } else {
1193 if (isHLLObjectOrReply(c,o) != C_OK) return;
1194 o = dbUnshareStringValue(c->db,c->argv[1],o);
1195 }
1196 /* Perform the low level ADD operation for every element. */
1197 for (j = 2; j < c->argc; j++) {
1198 int retval = hllAdd(o, (unsigned char*)c->argv[j]->ptr,
1199 sdslen(c->argv[j]->ptr));
1200 switch(retval) {
1201 case 1:
1202 updated++;
1203 break;
1204 case -1:
1205 addReplyError(c,invalid_hll_err);
1206 return;
1207 }
1208 }
1209 hdr = o->ptr;
1210 if (updated) {
1211 signalModifiedKey(c,c->db,c->argv[1]);
1212 notifyKeyspaceEvent(NOTIFY_STRING,"pfadd",c->argv[1],c->db->id);
1213 server.dirty += updated;
1214 HLL_INVALIDATE_CACHE(hdr);
1215 }
1216 addReply(c, updated ? shared.cone : shared.czero);
1217}
1218
1219/* PFCOUNT var -> approximated cardinality of set. */
1220void pfcountCommand(client *c) {

Callers

nothing calls this directly

Calls 11

lookupKeyWriteFunction · 0.85
createHLLObjectFunction · 0.85
dbAddFunction · 0.85
isHLLObjectOrReplyFunction · 0.85
dbUnshareStringValueFunction · 0.85
hllAddFunction · 0.85
sdslenFunction · 0.85
addReplyErrorFunction · 0.85
signalModifiedKeyFunction · 0.85
notifyKeyspaceEventFunction · 0.85
addReplyFunction · 0.85

Tested by

no test coverage detected