# BF.INSERT

> Add items to a Bloom filter, creating it with chosen settings or refusing to create it.

URL: https://docs.hotkv.com/commands/bf-insert/

```
BF.INSERT key [CAPACITY capacity] [ERROR error] [EXPANSION expansion] [NOCREATE] [NONSCALING] ITEMS item [item ...]
```

- Group: Bloom filter
- Complexity: O(k * n), k hash functions and n items
- HotKV Cloud: all plans
- On-Premise: no license needed

`BF.INSERT` adds items to the Bloom filter at `key` like
[BF.MADD](https://docs.hotkv.com/commands/bf-madd/index.md), but lets you set how a missing filter is
created, or forbid creating it. The settings only apply when the filter is
created by this call; an existing filter keeps its own.

## Options

| Option | Effect |
| --- | --- |
| `CAPACITY capacity` | Capacity of a new filter, 1 to 1073741824 (default 100). |
| `ERROR error` | Error rate of a new filter, between 0 and 1 exclusive (default 0.01). |
| `EXPANSION expansion` | Growth factor of a new filter, 0 to 32768 (default 2). |
| `NONSCALING` | Make a new filter non-scaling. |
| `NOCREATE` | Do not create the filter: reply `ERR not found` if the key does not exist. |
| `ITEMS item [item ...]` | The items to add. Required, and must come last. |

## Return value

An array with one element per item, as for BF.MADD:

| Element | RESP2 | RESP3 |
| --- | --- | --- |
| Item added | Integer `1` | Boolean true |
| Item (probably) already present | Integer `0` | Boolean false |

If an item cannot be added, the array ends with that error
(`ERR non scaling filter is full` or `ERR Insufficient memory to grow the filter`)
and the remaining items are not tried.

Error replies for the whole call:

- `ERR not found` with `NOCREATE` and no filter at the key.
- `Bad capacity`, `Bad error rate`, `Bad expansion` for invalid option values.
- `Unknown argument received` for an unknown option before `ITEMS`.
- `ERR wrong number of arguments for 'bf.insert' command` when `ITEMS` or the items are missing.
- `ERR Insufficient memory to create filter`, or `WRONGTYPE`.

## Examples

```
127.0.0.1:6379> BF.INSERT emails CAPACITY 10000 ERROR 0.001 ITEMS a@example.com b@example.com
1) (integer) 1
2) (integer) 1
127.0.0.1:6379> BF.INSERT emails ITEMS a@example.com
1) (integer) 0
127.0.0.1:6379> BF.INSERT other NOCREATE ITEMS x
(error) ERR not found
```

## Compatibility

Same as `BF.INSERT` in RedisBloom.

## See also

[BF.MADD](https://docs.hotkv.com/commands/bf-madd/index.md), [BF.RESERVE](https://docs.hotkv.com/commands/bf-reserve/index.md), [BF.ADD](https://docs.hotkv.com/commands/bf-add/index.md)