# BF.LOADCHUNK

> Restore a Bloom filter from the chunks BF.SCANDUMP produced.

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

```
BF.LOADCHUNK key iterator data
```

- Group: Bloom filter
- Complexity: O(n), n being the bytes of the chunk
- HotKV Cloud: all plans
- On-Premise: no license needed

`BF.LOADCHUNK` rebuilds a Bloom filter from a dump made with
[BF.SCANDUMP](https://docs.hotkv.com/commands/bf-scandump/index.md). Send the chunks back in the order you
received them, each with the iterator that BF.SCANDUMP returned alongside it.

The first chunk (iterator `1`) creates the filter at `key`, replacing any
Bloom filter already there. The later chunks fill in its bits. The restored
filter answers exactly as the original did.

## Return value

| Case | RESP2 | RESP3 |
| --- | --- | --- |
| Chunk loaded | Simple string `OK` | Simple string `OK` |

Error replies:

- `ERR received bad data` for a chunk that does not belong to the filter being loaded.
- `ERR not found` for a data chunk sent before the first chunk.
- `ERR Second argument must be numeric` for a non-integer iterator.
- `WRONGTYPE` if the key holds a value that is not a Bloom filter.

## Examples

A typical restore, in client code:

```
iter = 0
chunks = []
loop:
    iter, data = BF.SCANDUMP src iter
    if iter == 0: break
    chunks.append((iter, data))
for (iter, data) in chunks:
    BF.LOADCHUNK dst iter data
```

Errors from `redis-cli`:

```
127.0.0.1:6379> BF.LOADCHUNK restored 1 garbage
(error) ERR received bad data
127.0.0.1:6379> BF.LOADCHUNK restored 145 garbage
(error) ERR not found
```

## Compatibility

Same command flow as `BF.LOADCHUNK` in RedisBloom. Chunks must come from a
HotKV BF.SCANDUMP.

## See also

[BF.SCANDUMP](https://docs.hotkv.com/commands/bf-scandump/index.md), [BF.RESERVE](https://docs.hotkv.com/commands/bf-reserve/index.md)