forked from RedisLabsModules/redismodule-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfo.rs
31 lines (25 loc) · 803 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
use redis_module::{
redis_module, Context, NextArg, RedisError, RedisResult, RedisString, RedisValue,
};
fn info_cmd(ctx: &Context, args: Vec<RedisString>) -> RedisResult {
if args.len() < 3 {
return Err(RedisError::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(RedisValue::Null, RedisValue::BulkRedisString))
}
//////////////////////////////////////////////////////
redis_module! {
name: "info",
version: 1,
allocator: (redis_module::alloc::RedisAlloc, redis_module::alloc::RedisAlloc),
data_types: [],
commands: [
["infoex", info_cmd, "", 0, 0, 0],
],
}