Skip to content

Commit 9ea08ca

Browse files
authored
Merge pull request #63 from grippy/grippy/macro-args
Add Support for CreateCommand Keys
2 parents f0427d8 + 43b6d55 commit 9ea08ca

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

examples/data_type.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ redis_module! {
8383
MY_REDIS_TYPE,
8484
],
8585
commands: [
86-
["alloc.set", alloc_set, "write"],
87-
["alloc.get", alloc_get, "readonly"],
86+
["alloc.set", alloc_set, "write", 1, 1, 1],
87+
["alloc.get", alloc_get, "readonly", 1, 1, 1],
8888
],
8989
}

examples/hello.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ redis_module! {
2929
version: 1,
3030
data_types: [],
3131
commands: [
32-
["hello.mul", hello_mul, ""],
32+
["hello.mul", hello_mul, "", 1, 1, 1],
3333
],
3434
}
3535

src/macros.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
#[macro_export]
22
macro_rules! redis_command {
3-
($ctx: expr, $command_name:expr, $command_handler:expr, $command_flags:expr) => {{
3+
($ctx:expr,
4+
$command_name:expr,
5+
$command_handler:expr,
6+
$command_flags:expr,
7+
$firstkey:expr,
8+
$lastkey:expr,
9+
$keystep:expr) => {{
410
let name = CString::new($command_name).unwrap();
511
let flags = CString::new($command_flags).unwrap();
6-
let (firstkey, lastkey, keystep) = (1, 1, 1);
712

813
/////////////////////
914
extern "C" fn do_command(
@@ -37,9 +42,9 @@ macro_rules! redis_command {
3742
name.as_ptr(),
3843
Some(do_command),
3944
flags.as_ptr(),
40-
firstkey,
41-
lastkey,
42-
keystep,
45+
$firstkey,
46+
$lastkey,
47+
$keystep,
4348
)
4449
} == raw::Status::Err as c_int
4550
{
@@ -61,7 +66,10 @@ macro_rules! redis_module {
6166
$([
6267
$name:expr,
6368
$command:expr,
64-
$flags:expr
69+
$flags:expr,
70+
$firstkey:expr,
71+
$lastkey:expr,
72+
$keystep:expr
6573
]),* $(,)*
6674
] $(,)*
6775
) => {
@@ -112,7 +120,7 @@ macro_rules! redis_module {
112120
)*
113121

114122
$(
115-
redis_command!(ctx, $name, $command, $flags);
123+
redis_command!(ctx, $name, $command, $flags, $firstkey, $lastkey, $keystep);
116124
)*
117125

118126
raw::Status::Ok as c_int

0 commit comments

Comments
 (0)