forked from valkey-io/valkeymodule-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhello.rs
32 lines (26 loc) · 789 Bytes
/
hello.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, ValkeyError, ValkeyResult, ValkeyString};
fn hello_mul(_: &Context, args: Vec<ValkeyString>) -> ValkeyResult {
if args.len() < 2 {
return Err(ValkeyError::WrongArity);
}
let nums = args
.into_iter()
.skip(1)
.map(|s| s.parse_integer())
.collect::<Result<Vec<i64>, ValkeyError>>()?;
let product = nums.iter().product();
let mut response = nums;
response.push(product);
Ok(response.into())
}
//////////////////////////////////////////////////////
valkey_module! {
name: "hello",
version: 1,
allocator: (ValkeyAlloc, ValkeyAlloc),
data_types: [],
commands: [
["hello.mul", hello_mul, "", 0, 0, 0],
],
}