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

Function pfaddCommand

src/hyperloglog.cpp:1190–1227  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 13

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

Tested by

no test coverage detected