Skip to content

Commit 98e7b17

Browse files
committed
examples: Show how to use is_keys_position_request
1 parent 78db486 commit 98e7b17

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

examples/hello.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
#[macro_use]
22
extern crate redis_module;
33

4-
use redis_module::{parse_integer, Context, RedisError, RedisResult};
4+
use redis_module::{parse_integer, Context, RedisError, RedisResult, RedisValue};
55

6-
fn hello_mul(_: &Context, args: Vec<String>) -> RedisResult {
6+
fn hello_mul(ctx: &Context, args: Vec<String>) -> RedisResult {
77
if args.len() < 2 {
88
return Err(RedisError::WrongArity);
99
}
1010

11+
if ctx.is_keys_position_request() {
12+
for i in 1..args.len() {
13+
if i % 2 == 0 {
14+
ctx.key_at_pos(i as i32);
15+
}
16+
}
17+
return Ok(RedisValue::NoReply);
18+
}
19+
1120
let nums = args
1221
.into_iter()
1322
.skip(1)
@@ -29,7 +38,7 @@ redis_module! {
2938
version: 1,
3039
data_types: [],
3140
commands: [
32-
["hello.mul", hello_mul, "", 0, 0, 0],
41+
["hello.mul", hello_mul, "getkeys-api", 1, 1, 1],
3342
],
3443
}
3544

0 commit comments

Comments
 (0)