8 releases
0.3.0 | May 25, 2020 |
---|---|
0.2.2 | May 17, 2020 |
0.1.3 | May 15, 2020 |
#178 in FFI
21 downloads per month
145KB
2.5K
SLoC
iredismodule
This crate provides an idiomatic Rust API for the Redis Modules API. It allows writing Redis modules in Rust, without needing to use raw pointers or unsafe code.
Get started
use iredismodule_macros::rcmd;
use iredismodule::prelude::*;
/// Define command
#[rcmd("simple.hello", "readonly", 0, 0, 0)]
fn simple_hello(ctx: &mut Context, _args: Vec<RStr>) -> RResult {
let db = ctx.get_select_db();
Ok(db.into())
}
// Register module
define_module! {
name: "simple",
version: 1,
data_types: [],
init_funcs: [],
commands: [
simple_hello_cmd,
]
}
Running the example module
- Install Rust
- Install Redis, most likely using your favorite package manager (Homebrew on Mac, APT or YUM on Linux)
- Run
cargo build --example helloworld
- Start a redis server with the
helloworld
module- Linux:
redis-server --loadmodule ./target/debug/examples/helloworld.so
- Mac:
redis-server --loadmodule ./target/debug/examples/helloworld.dylib
- Linux:
- Open a Redis CLI, and run
HELLO.SIMPLE
.
Writing your own module
See the examples directory for some sample modules.
This crate tries to provide high-level wrappers around the standard Redis Modules API, while preserving the API's basic concepts. Therefore, following the Redis Modules API documentation will be mostly relevant here as well.
No runtime deps
~0–2MB
~37K SLoC