6 个版本
0.3.0 | 2020 年 5 月 25 日 |
---|---|
0.2.0 | 2020 年 5 月 15 日 |
0.1.3 | 2020 年 5 月 15 日 |
#339 in FFI
32KB
519 行代码(不含注释)
iredismodule
此包提供了一个符合 Rust 风格的 API,用于 Redis 模块 API。它允许使用 Rust 编写 Redis 模块,而无需使用原始指针或不安全代码。
入门指南
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,
]
}
运行示例模块
- 安装 Rust
- 安装 Redis,通常使用您喜欢的包管理器(Mac 上的 Homebrew,Linux 上的 APT 或 YUM)
- 运行
cargo build --example helloworld
- 使用
helloworld
模块启动 Redis 服务器- Linux:
redis-server --loadmodule ./target/debug/examples/helloworld.so
- Mac:
redis-server --loadmodule ./target/debug/examples/helloworld.dylib
- Linux:
- 打开 Redis CLI,并运行
HELLO.SIMPLE
。
编写自己的模块
请参阅 示例 目录以获取一些示例模块。
此包试图提供标准 Redis 模块 API 的高级包装,同时保留 API 的基本概念。因此,遵循 Redis 模块 API 文档在这里也将非常有用。
依赖项
~1.5MB
~35K SLoC