Skip to content

Commit e5ffd70

Browse files
Merge remote-tracking branch 'origin/unstable' into karsubba/1.0
2 parents c184d72 + 32b0218 commit e5ffd70

31 files changed

+552
-1030
lines changed

.github/workflows/ci.yml

+24-8
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ on:
77
env:
88
CARGO_TERM_COLOR: always
99
VALKEY_REPO_URL: https://github.com/valkey-io/valkey.git
10+
TEST_FRAMEWORK_REPO: https://github.com/valkey-io/valkey-test-framework
11+
TEST_FRAMEWORK_DIR: tests/build/valkeytestframework
1012

1113
jobs:
1214
build-ubuntu-latest:
1315
runs-on: ubuntu-latest
1416
strategy:
1517
fail-fast: false
1618
matrix:
17-
server_version: ['unstable', '8.0.0']
19+
server_version: ['unstable', '8.0', '8.1']
1820
steps:
1921
- uses: actions/checkout@v4
2022
- name: Set the server verison for python integeration tests
@@ -25,7 +27,7 @@ jobs:
2527
cargo clippy --profile release --all-targets -- -D clippy::all
2628
- name: Release Build
2729
run: |
28-
if [ "${{ matrix.server_version }}" = "8.0.0" ]; then
30+
if [ "${{ matrix.server_version }}" = "8.0" ]; then
2931
RUSTFLAGS="-D warnings" cargo build --all --all-targets --release --features valkey_8_0
3032
else
3133
RUSTFLAGS="-D warnings" cargo build --all --all-targets --release
@@ -34,13 +36,20 @@ jobs:
3436
run: cargo test --features enable-system-alloc
3537
- name: Make valkey-server binary
3638
run: |
37-
mkdir -p "tests/.build/binaries/${{ matrix.server_version }}"
38-
cd tests/.build
39+
mkdir -p "tests/build/binaries/${{ matrix.server_version }}"
40+
cd tests/build
3941
git clone "${{ env.VALKEY_REPO_URL }}"
4042
cd valkey
4143
git checkout ${{ matrix.server_version }}
4244
make -j
4345
cp src/valkey-server ../binaries/${{ matrix.server_version }}/
46+
- name: Set up test framework
47+
run: |
48+
echo "Cloning test framework..."
49+
git clone ${{ env.TEST_FRAMEWORK_REPO }}
50+
mkdir -p ${{ env.TEST_FRAMEWORK_DIR }}
51+
mv valkey-test-framework/src/* ${{ env.TEST_FRAMEWORK_DIR }}/
52+
rm -rf valkey-test-framework
4453
- name: Set up Python
4554
uses: actions/setup-python@v3
4655
with:
@@ -72,7 +81,7 @@ jobs:
7281
strategy:
7382
fail-fast: false
7483
matrix:
75-
server_version: ['unstable', '8.0.0']
84+
server_version: ['unstable', '8.0', '8.1']
7685
steps:
7786
- uses: actions/checkout@v4
7887
- name: Set the server verison for python integeration tests
@@ -83,7 +92,7 @@ jobs:
8392
cargo clippy --profile release --all-targets -- -D clippy::all
8493
- name: Release Build
8594
run: |
86-
if [ "${{ matrix.server_version }}" = "8.0.0" ]; then
95+
if [ "${{ matrix.server_version }}" = "8.0" ]; then
8796
RUSTFLAGS="-D warnings" cargo build --all --all-targets --release --features valkey_8_0
8897
else
8998
RUSTFLAGS="-D warnings" cargo build --all --all-targets --release
@@ -92,14 +101,21 @@ jobs:
92101
run: cargo test --features enable-system-alloc
93102
- name: Make Valkey-server binary with asan
94103
run: |
95-
mkdir -p "tests/.build/binaries/${{ matrix.server_version }}"
96-
cd tests/.build
104+
mkdir -p "tests/build/binaries/${{ matrix.server_version }}"
105+
cd tests/build
97106
git clone "${{ env.VALKEY_REPO_URL }}"
98107
cd valkey
99108
git checkout ${{ matrix.server_version }}
100109
make distclean
101110
make -j SANITIZER=address SERVER_CFLAGS='-Werror' BUILD_TLS=module
102111
cp src/valkey-server ../binaries/${{ matrix.server_version }}/
112+
- name: Set up test framework
113+
run: |
114+
echo "Cloning test framework..."
115+
git clone ${{ env.TEST_FRAMEWORK_REPO }}
116+
mkdir -p ${{ env.TEST_FRAMEWORK_DIR }}
117+
mv valkey-test-framework/src/* ${{ env.TEST_FRAMEWORK_DIR }}/
118+
rm -rf valkey-test-framework
103119
- name: Set up Python
104120
uses: actions/setup-python@v3
105121
with:

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Cargo.lock
22
target
3-
tests/.build
3+
tests/build
44
__pycache__
5+
.pytest_cache
56
test-data
67
.attach_pid*
8+
src/commands/commands

QUICK_START.md

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Quick Start
2+
3+
Follow these steps to set up, build, and run the Valkey server with the valkey-bloom module. This guide will walk you through creating a bloom filter, inserting items, and checking for items in the filters.
4+
5+
## Step 1: Install Valkey and valkey-bloom
6+
7+
1. Build Valkey from source by following the instructions [here](https://github.com/valkey-io/valkey?tab=readme-ov-file#building-valkey-using-makefile). Make sure to use Valkey version 8.0 or above.
8+
9+
2. Build the valkey-bloom module from source by following the instructions [here](https://github.com/valkey-io/valkey-bloom/blob/unstable/README.md#build-instructions).
10+
11+
## Step 2: Run the Valkey Server with valkey-bloom
12+
13+
Once valkey-bloom is built, run the Valkey server with the module loaded:
14+
15+
In case of Linux:
16+
```bash
17+
./valkey-server --loadmodule ./target/release/libvalkey_bloom.so
18+
```
19+
20+
You should see the Valkey server start, and it will be ready to accept commands.
21+
22+
## Step 3: Create a Bloom Filter
23+
24+
Start a Valkey CLI session:
25+
26+
```bash
27+
valkey-cli
28+
```
29+
30+
Create a bloom filter using the BF.ADD, BF.INSERT, BF.RESERVE or BF.MADD commands. For example:
31+
32+
```bash
33+
BF.ADD filter-key item-val
34+
```
35+
36+
- `filter-key` is the name of the bloom filter we will be operating on
37+
- `item-val` is the item we are inserting into the bloom filter
38+
39+
## Step 4: Insert some more items
40+
41+
To insert items on an already created filter, use the `BF.ADD`, `BF.MADD` or `BF.INSERT` commands:
42+
43+
```bash
44+
BF.ADD filter-key example
45+
BF.MADD filter-key example1 example2
46+
```
47+
48+
Replace the example with the actual items you want to add.
49+
50+
## Step 5: Check if items are present
51+
52+
Now that you've created a bloom filter and inserted items, you can check what items have been added. Use the `BF.EXISTS` or `BF.MEXISTS` commands to check for items:
53+
54+
```bash
55+
BF.EXISTS filter-key example
56+
```
57+
58+
This command checks if an item is present in a bloom filter. Bloom filters can have false positives, but no false negatives. This means that if the BF.EXISTS command returns 0, then the item is not present. But if the BF.EXISTS command returns 1, there is a possibility (determined by false positive rate) that the item is not actually present.

README.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# valkey-bloom
22

3-
Valkey-Bloom (BSD-3-Clause) is a Rust Valkey-Module which brings a native and space efficient probabilistic Module data type to Valkey. With this, users can create filters (space-efficient probabilistic Module data type) to add elements, perform “check” operation to test whether an element exists, auto scale their filters, perform RDB Save and load operations, etc.
3+
Valkey-Bloom (BSD-3-Clause) is a Rust based Valkey-Module which brings a Bloom Filter (Module) data type into Valkey and supports verions >= 8.0. With this, users can create bloom filters (space efficient probabilistic data structures) to add elements, check whether elements exists, auto scale their filters, customize bloom filter properties, perform RDB Save and load operations, etc.
44

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

7-
It is compatible with the BloomFilter (BF.*) command APIs in Redis offerings.
7+
It is API compatible with the bloom filter command syntax of the official Valkey client libraries including valkey-py, valkey-java, valkey-go (as well as the equivalent Redis libraries)
88

99
## Supported commands
1010
```
@@ -25,7 +25,10 @@ curl https://sh.rustup.rs -sSf | sh
2525
sudo yum install clang
2626
git clone https://github.com/valkey-io/valkey-bloom.git
2727
cd valkey-bloom
28-
cargo build --all --all-targets --release
28+
# Building for Valkey 8.1 and above:
29+
cargo build --release
30+
# Building for Valkey 8.0 specifically:
31+
cargo build --release --features valkey_8_0
2932
valkey-server --loadmodule ./target/release/libvalkey_bloom.so
3033
```
3134

build.sh

+23-11
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,29 @@ if [ -z "$SERVER_VERSION" ]; then
2222
export SERVER_VERSION="unstable"
2323
fi
2424

25-
if [ "$SERVER_VERSION" != "unstable" ] && [ "$SERVER_VERSION" != "8.0.0" ] ; then
25+
if [ "$SERVER_VERSION" != "unstable" ] && [ "$SERVER_VERSION" != "8.0" ] && [ "$SERVER_VERSION" != "8.1" ]; then
2626
echo "ERROR: Unsupported version - $SERVER_VERSION"
2727
exit 1
2828
fi
2929

3030
echo "Running cargo build release..."
31-
if [ "$SERVER_VERSION" == "8.0.0" ] ; then
31+
if [ "$SERVER_VERSION" == "8.0" ] ; then
3232
RUSTFLAGS="-D warnings" cargo build --all --all-targets --release --features valkey_8_0
3333
else
3434
RUSTFLAGS="-D warnings" cargo build --all --all-targets --release
3535
fi
3636

3737

3838
REPO_URL="https://github.com/valkey-io/valkey.git"
39-
BINARY_PATH="tests/.build/binaries/$SERVER_VERSION/valkey-server"
40-
39+
BINARY_PATH="tests/build/binaries/$SERVER_VERSION/valkey-server"
40+
CACHED_VALKEY_PATH="tests/build/valkey"
4141
if [ -f "$BINARY_PATH" ] && [ -x "$BINARY_PATH" ]; then
4242
echo "valkey-server binary '$BINARY_PATH' found."
4343
else
4444
echo "valkey-server binary '$BINARY_PATH' not found."
45-
mkdir -p "tests/.build/binaries/$SERVER_VERSION"
46-
cd tests/.build
47-
rm -rf valkey
45+
mkdir -p "tests/build/binaries/$SERVER_VERSION"
46+
rm -rf $CACHED_VALKEY_PATH
47+
cd tests/build
4848
git clone "$REPO_URL"
4949
cd valkey
5050
git checkout "$SERVER_VERSION"
@@ -55,6 +55,22 @@ else
5555
make -j
5656
fi
5757
cp src/valkey-server ../binaries/$SERVER_VERSION/
58+
cd $SCRIPT_DIR
59+
rm -rf $CACHED_VALKEY_PATH
60+
fi
61+
62+
63+
TEST_FRAMEWORK_REPO="https://github.com/valkey-io/valkey-test-framework"
64+
TEST_FRAMEWORK_DIR="tests/build/valkeytestframework"
65+
66+
if [ -d "$TEST_FRAMEWORK_DIR" ]; then
67+
echo "valkeytestframework found."
68+
else
69+
echo "Cloning valkey-test-framework..."
70+
git clone "$TEST_FRAMEWORK_REPO"
71+
mkdir -p "$TEST_FRAMEWORK_DIR"
72+
mv "valkey-test-framework/src"/* "$TEST_FRAMEWORK_DIR/"
73+
rm -rf valkey-test-framework
5874
fi
5975

6076
REQUIREMENTS_FILE="requirements.txt"
@@ -78,8 +94,6 @@ if [[ "$os_type" == "Darwin" ]]; then
7894
MODULE_EXT=".dylib"
7995
elif [[ "$os_type" == "Linux" ]]; then
8096
MODULE_EXT=".so"
81-
elif [[ "$os_type" == "Windows" ]]; then
82-
MODULE_EXT=".dll"
8397
else
8498
echo "Unsupported OS type: $os_type"
8599
exit 1
@@ -115,8 +129,6 @@ if [ ! -z "${ASAN_BUILD}" ]; then
115129
rm test_output.tmp
116130
exit 1
117131
fi
118-
119-
120132
rm test_output.tmp
121133
else
122134
# TEST_PATTERN can be used to run specific tests or test patterns.

src/bloom/command_handler.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ fn handle_bloom_add(
2424
) -> Result<ValkeyValue, ValkeyError> {
2525
match multi {
2626
true => {
27-
let mut result = Vec::new();
28-
for item in args.iter().take(argc).skip(item_idx) {
29-
match bf.add_item(item.as_slice(), validate_size_limit) {
27+
let mut result = Vec::with_capacity(argc - item_idx);
28+
let mut curr_cmd_idx = item_idx;
29+
while curr_cmd_idx < argc {
30+
let item = args[curr_cmd_idx].as_slice();
31+
match bf.add_item(item, validate_size_limit) {
3032
Ok(add_result) => {
3133
if add_result == 1 {
3234
*add_succeeded = true;
@@ -38,6 +40,7 @@ fn handle_bloom_add(
3840
break;
3941
}
4042
};
43+
curr_cmd_idx += 1;
4144
}
4245
Ok(ValkeyValue::Array(result))
4346
}
@@ -299,7 +302,7 @@ pub fn bloom_filter_exists(
299302
let item = input_args[curr_cmd_idx].as_slice();
300303
return Ok(handle_item_exists(value, item));
301304
}
302-
let mut result = Vec::new();
305+
let mut result = Vec::with_capacity(argc - curr_cmd_idx);
303306
while curr_cmd_idx < argc {
304307
let item = input_args[curr_cmd_idx].as_slice();
305308
result.push(handle_item_exists(value, item));

src/commands/bf.add.json

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"BF.ADD": {
3+
"summary": "Add a single item to a bloom filter. The bloom filter is created if it doesn't exist",
4+
"complexity": "O(N), where N is the number of hash functions used by the bloom filter.",
5+
"group": "bloom",
6+
"module_since": "1.0.0",
7+
"arity": 3,
8+
"acl_categories": [
9+
"FAST",
10+
"WRITE",
11+
"BLOOM"
12+
],
13+
"arguments": [
14+
{
15+
"name": "key",
16+
"type": "key",
17+
"key_spec_index": 0
18+
},
19+
{
20+
"name": "value",
21+
"type": "string"
22+
}
23+
]
24+
}
25+
}

src/commands/bf.card.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"BF.CARD": {
3+
"summary": "Returns the cardinality of a bloom filter",
4+
"complexity": "O(1)",
5+
"group": "bloom",
6+
"module_since": "1.0.0",
7+
"arity": 2,
8+
"acl_categories": [
9+
"READ",
10+
"FAST",
11+
"BLOOM"
12+
],
13+
"arguments": [
14+
{
15+
"name": "key",
16+
"type": "key",
17+
"key_spec_index": 0
18+
}
19+
]
20+
}
21+
}

src/commands/bf.exists.json

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"BF.EXISTS": {
3+
"summary": "Determines if the bloom filter contains the specified item",
4+
"complexity": "O(N), where N is the number of hash functions used by the bloom filter.",
5+
"group": "bloom",
6+
"module_since": "1.0.0",
7+
"arity": 3,
8+
"acl_categories": [
9+
"READ",
10+
"FAST",
11+
"BLOOM"
12+
],
13+
"arguments": [
14+
{
15+
"name": "key",
16+
"type": "key",
17+
"key_spec_index": 0
18+
},
19+
{
20+
"name": "value",
21+
"type": "string"
22+
}
23+
]
24+
}
25+
}

0 commit comments

Comments
 (0)