Skip to content

Ask the HotKV docs

Answers come only from these docs and can be wrong; check the linked pages before you rely on them.

BF.RESERVE

Last updated
BF.RESERVE key error_rate capacity [EXPANSION expansion] [NONSCALING]
Group
Bloom filter
Complexity
O(1)
Arity
-1 (at least 1 words, counting the command name)
Flags
fast
Keys
first 1, last 1, step 1
HotKV Cloud
All plans
On-Premise
no license needed

BF.RESERVE creates an empty Bloom filter at key. A Bloom filter answers “have I seen this item?” using far less memory than a set: it never misses an item that was added, but may wrongly report an item that was not, at about the error rate you choose.

You only need BF.RESERVE to pick non-default settings. BF.ADD, BF.MADD and BF.INSERT create a filter on demand, with capacity 100, error rate 0.01 and expansion 2.

Argument Effect
error_rate The false positive rate to aim for, between 0 and 1 (exclusive), for example 0.001 for 0.1%. Lower rates use more memory.
capacity How many items the filter is sized for, from 1 to 1073741824.
EXPANSION expansion When the filter is full, the next item adds a new layer this many times larger than the last one, keeping the overall error rate. Default 2, range 0 to 32768. 0 makes the filter non-scaling.
NONSCALING Never grow: once capacity items are in, adding a new item fails.

EXPANSION and NONSCALING cannot be combined. Other extra arguments are ignored.

Case RESP2 RESP3
Created Simple string OK Simple string OK

Error replies:

  • ERR item exists if a Bloom filter already exists at the key.
  • ERR bad error rate and ERR error rate must be in the range (0.000000, 1.000000)
  • ERR bad capacity and ERR capacity must be in the range [1, 1073741824]
  • ERR no expansion, ERR bad expansion and ERR expansion must be in the range [0, 32768]
  • Nonscaling filters cannot expand when EXPANSION and NONSCALING are both given.
  • ERR Insufficient memory to create filter when the filter would not fit in memory.
  • WRONGTYPE if the key holds another type.
127.0.0.1:6379> BF.RESERVE signups 0.01 1000
OK
127.0.0.1:6379> BF.RESERVE signups 0.01 1000
(error) ERR item exists
127.0.0.1:6379> BF.RESERVE fixed 0.001 5000 NONSCALING
OK
127.0.0.1:6379> BF.RESERVE bad 1.5 100
(error) ERR error rate must be in the range (0.000000, 1.000000)

Same arguments, limits and errors as BF.RESERVE in RedisBloom.

BF.ADD, BF.INSERT, BF.INFO, BF.EXISTS