forked from valkey-io/valkeymodule-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfo.rs
32 lines (26 loc) · 815 Bytes
/
info.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use valkey_module::alloc::ValkeyAlloc;
use valkey_module::{
valkey_module, Context, NextArg, ValkeyError, ValkeyResult, ValkeyString, ValkeyValue,
};
fn info_cmd(ctx: &Context, args: Vec<ValkeyString>) -> ValkeyResult {
if args.len() < 3 {
return Err(ValkeyError::WrongArity);
}
let mut args = args.into_iter().skip(1);
let section = args.next_str()?;
let field = args.next_str()?;
let server_info = ctx.server_info(section);
Ok(server_info
.field(field)
.map_or(ValkeyValue::Null, ValkeyValue::BulkValkeyString))
}
//////////////////////////////////////////////////////
valkey_module! {
name: "info",
version: 1,
allocator: (ValkeyAlloc, ValkeyAlloc),
data_types: [],
commands: [
["infoex", info_cmd, "", 0, 0, 0],
],
}