Available in: Redis Stack
Time complexity: O(k), where k is the number of hash functions used by the last sub-filter
Creates an empty Bloom Filter with a single sub-filter for the initial capacity
requested and with an upper bound
error_rate. By default, the filter
auto-scales by creating additional sub-filters when
capacity is reached. The
new sub-filter is created with size of the previous sub-filter multiplied by
Though the filter can scale up by creating sub-filters, it is recommended to
reserve the estimated required
capacity since maintaining and querying
sub-filters requires additional memory (each sub-filter uses an extra bits and
hash function) and consume further CPU time than an equivalent filter that had
the right capacity at creation time.
The number of hash functions is
The number of bits per item is
-log(error)/ln(2) ≈ 1.44.
capacityis reached, an additional sub-filter is created. The size of the new sub-filter is the size of the last sub-filter multiplied by
expansion. If the number of elements to be stored in the filter is unknown, we recommend that you use an
expansionof 2 or more to reduce the number of sub-filters. Otherwise, we recommend that you use an
expansionof 1 to reduce memory consumption. The default expansion value is 2.
Integer reply - "1" if the item did not exist in the filter, "0" otherwise.
redis> BF.ADD bf item1 (integer) 0 redis> BF.ADD bf item_new (integer) 1