CF.INSERTNX key [CAPACITY capacity] [NOCREATE] ITEMS item [item ...]
- Available in:
- Redis Stack / Bloom 1.0.0
- Time complexity:
- O(n * (k + i)), where n is the number of items, k is the number of sub-filters and i is maxIterations
Adds one or more items to a cuckoo filter if they did not exist previously, allowing the filter to be created with a custom capacity if it does not exist yet.
This command is similar to
CF.ADDNX, except that more than one item can be added and capacity can be specified.
- This command is slower than
CF.INSERTbecause it first checks whether each item exists.
CF.EXISTScan result in false positive,
CF.INSERTNXmay not add an item because it is supposedly already exist, which may be wrong.
is key name for a cuckoo filter to add items to.
key does not exist - a new cuckoo filter is created.
One or more items to add.
Specifies the desired capacity of the new filter, if this filter does not exist yet.
If the filter already exists, then this parameter is ignored.
If the filter does not exist yet and this parameter is not specified, then the filter is created with the module-level default capacity which is 1024.
CF.RESERVE for more information on cuckoo filter capacities.
If specified, prevents automatic filter creation if the filter does not exist (Instead, an error is returned).
This option is mutually exclusive with
Returns one of these replies:
- Array reply of Integer reply, where
0means that the item's fingerprint already exists in the filter,
1means that the item has been successfully added to the filter, and
-1means that the item was not added because the filter is full.
- Error reply on error (invalid arguments, wrong key type, etc.) and also when
NOCREATEis specified and
keydoes not exist.
O(n + i), where n is the number of
sub-filters and i is
Adding items requires up to 2 memory accesses per
But as the filter fills up, both locations for an item might be full. The filter attempts to
Cuckoo swap items up to
redis> CF.INSERTNX cf CAPACITY 1000 ITEMS item1 item2 1) (integer) 1 2) (integer) 1
redis> CF.INSERTNX cf CAPACITY 1000 ITEMS item1 item2 item3 1) (integer) 0 2) (integer) 0 3) (integer) 1
redis> CF.INSERTNX cf_new CAPACITY 1000 NOCREATE ITEMS item1 item2 (error) ERR not found