6 releases
99.99.99 |
|
---|---|
2.0.7 |
|
0.1.5 | Mar 10, 2025 |
0.1.4 | Feb 17, 2025 |
0.1.0 | Apr 30, 2024 |
#1387 in Database interfaces
839 downloads per month
280KB
6.5K
SLoC
valkeymodule-rs
This crate provides an idiomatic Rust API for the Valkey Modules API. It allows writing Valkey modules in Rust, without needing to use raw pointers or unsafe code. See here for the most recent API documentation.
This repo was forked from redismodule-rs. We appreciate the contributions of the original authors.
Running the example module
- Install Rust
- Install Valkey, most likely using your favorite package manager (Homebrew on Mac, APT or YUM on Linux)
- Run
cargo build --example hello
- Start a valkey server with the
hello
module- Linux:
valkey-server --loadmodule ./target/debug/examples/libhello.so
- Mac:
valkey-server --loadmodule ./target/debug/examples/libhello.dylib
- Linux:
- Open a valkey-cli, and run
HELLO.MUL 31 11
.
Writing your own module
See the examples directory for some sample modules.
This crate tries to provide high-level wrappers around the standard Valkey Modules API, while preserving the API's basic concepts. Therefore, following the Valkey Modules API documentation will be mostly relevant here as well.
Feature Flags
- System Allocator
This feature flag is ideal for unit testing where the engine server is not running, and we do not have access to the Vakey engine Allocator; so we can use the System Allocator instead.
To optionally enter the System.alloc
code paths in alloc.rs
specify this in Cargo.toml
of your module:
[features]
enable-system-alloc = ["valkey-module/system-alloc"]
For unit tests with System.alloc
use this:
cargo test --features enable-system-alloc
For integration tests with ValkeyAlloc
use this:
cargo test
- Redis Compatibility
This feature flag is useful in case you have a Module that needs to be loaded on both Valkey and Redis Servers. In this case, you can use the use-redismodule-api
flag so that the Module is loaded using the RedisModule API Initialization for compatibility.
To use this feature by conditionally, specify the following in your Cargo.toml
:
[features]
use-redismodule-api = ["valkey-module/use-redismodule-api"]
default = []
cargo build --release --features use-redismodule-api
Dependencies
~6–15MB
~217K SLoC