PFADD var ele ele ele ... ele => :0 or :1 */
| 1178 | |
| 1179 | /* PFADD var ele ele ele ... ele => :0 or :1 */ |
| 1180 | void 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. */ |
| 1220 | void pfcountCommand(client *c) { |
nothing calls this directly
no test coverage detected