Skip to content

Commit

Permalink
Update README.md (#39)
Browse files Browse the repository at this point in the history
Signed-off-by: KarthikSubbarao <[email protected]>
  • Loading branch information
KarthikSubbarao authored Jan 12, 2025
1 parent a9b578e commit 1bb7d25
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 79 deletions.
98 changes: 22 additions & 76 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ Valkey-Bloom (BSD-3-Clause) is a Rust Valkey-Module which brings a native and sp

Valkey-Bloom is built using bloomfilter::Bloom (https://crates.io/crates/bloomfilter which has a BSD-2-Clause license).

It is compatible with the BloomFilter (BF.*) command APIs of the ReBloom Module from Redis Ltd.
It is compatible with the BloomFilter (BF.*) command APIs in Redis offerings.

The following commands are supported.
## Supported commands
```
BF.EXISTS
BF.ADD
Expand All @@ -19,99 +19,45 @@ BF.INSERT
BF.LOAD
```

Build instructions for Linux.
## Build instructions
```
curl https://sh.rustup.rs -sSf | sh
sudo yum install clang
git clone https://github.com/KarthikSubbarao/valkey-bloom.git
git clone https://github.com/valkey-io/valkey-bloom.git
cd valkey-bloom
cargo build --all --all-targets --release
valkey-server --loadmodule ./target/release/libvalkey_bloom.so
```

Local development script to build, run format checks, run unit / integration tests, and for cargo release:
#### Local development script to build, run format checks, run unit / integration tests, and for cargo release:
```
# Builds the valkey-server (unstable) for integration testing.
SERVER_VERSION=unstable
./build.sh
# Builds the valkey-server (8.0.0) for integration testing.
# Same as above, but uses valkey-server (8.0.0) for integration testing.
SERVER_VERSION=8.0.0
./build.sh
```

Client Usage
```
<redacted> % ./valkey-cli
127.0.0.1:6379> module list
1) 1) "name"
2) "bloom"
3) "ver"
4) (integer) 1
5) "path"
6) "./target/release/libvalkey_bloom.so"
7) "args"
8) (empty array)
127.0.0.1:6379> bf.add key item
(integer) 1
127.0.0.1:6379> bf.exists key item
(integer) 1
127.0.0.1:6379> bf.exists key item2
(integer) 0
127.0.0.1:6379> bf.card key
(integer) 1
127.0.0.1:6379> bf.reserve key 0.01 10000
(error) ERR item exists
127.0.0.1:6379> bf.reserve key1 0.01 10000
OK
127.0.0.1:6379> bf.card key1
(integer) 0
127.0.0.1:6379> bf.add key1 item
(integer) 1
127.0.0.1:6379> bf.card key1
(integer) 1
```
## Load the Module
To test the module with a Valkey, you can load the module in the following ways:

#### Using valkey.conf:
```
127.0.0.1:6379> bf.reserve key1 0.01 10000
OK
127.0.0.1:6379> bf.info key3
(empty array)
127.0.0.1:6379> bf.info key1
1) Capacity
2) (integer) 10000
3) Size
4) (integer) 12198
5) Number of filters
6) (integer) 1
7) Number of items inserted
8) (integer) 0
9) Expansion rate
10) (integer) 2
1. Add the following to valkey.conf:
loadmodule /path/to/libvalkey_bloom.so
2. Start valkey-server:
valkey-server /path/to/valkey.conf
```

RDB Load, Save and flushall validation
#### Starting Valkey with the `--loadmodule` option:
```text
valkey-server --loadmodule /path/to/libvalkey_bloom.so
```
127.0.0.1:6379> info keyspace
# Keyspace
127.0.0.1:6379> bf.add key item
(integer) 1
127.0.0.1:6379> info keyspace
# Keyspace
db0:keys=1,expires=0,avg_ttl=0
127.0.0.1:6379> flushall
OK
127.0.0.1:6379> info keyspace
# Keyspace
127.0.0.1:6379> bf.add key item
(integer) 1
127.0.0.1:6379> bgsave
Background saving started
127.0.0.1:6379> shutdown
not connected> info keyspace // Started up
# Keyspace
db0:keys=1,expires=0,avg_ttl=0
127.0.0.1:6379> keys *
1) "key"
127.0.0.1:6379> bf.exists key item
(integer) 1

#### Using the Valkey command `MODULE LOAD`:
```
1. Connect to a running Valkey instance using valkey-cli
2. Execute Valkey command:
MODULE LOAD /path/to/libvalkey_bloom.so
```
4 changes: 1 addition & 3 deletions src/bloom/command_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,9 +565,7 @@ pub fn bloom_filter_insert(ctx: &Context, input_args: &[ValkeyString]) -> Valkey
idx += 1;
}
if idx == argc && items_provided {
// We expect the ITEMS <item> [<item> ...] argument to be provided on the BF.INSERT command used on primary nodes.
// For replicated commands, this is optional to allow BF.INSERT to be used to replicate bloom object creation
// commands without any items (BF.RESERVE).
// When the `ITEMS` argument is provided, we expect additional item arg/s to be provided.
return Err(ValkeyError::WrongArity);
}
// If the filter does not exist, create one
Expand Down

0 comments on commit 1bb7d25

Please sign in to comment.