Crates.io | iredismodule |
lib.rs | iredismodule |
version | 0.3.0 |
source | src |
created_at | 2020-05-13 13:34:07.092582 |
updated_at | 2020-05-25 08:12:03.139182 |
description | A toolkit for building Redis modules in Rust |
homepage | |
repository | https://github.com/sigoden/iredismodule |
max_upload_size | |
id | 241117 |
size | 278,480 |
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.
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,
]
}
cargo build --example helloworld
helloworld
module
redis-server --loadmodule ./target/debug/examples/helloworld.so
redis-server --loadmodule ./target/debug/examples/helloworld.dylib
HELLO.SIMPLE
.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.