-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Make call function generic. * Avoid RedisModuleString retain if there is not need to. * Code reuse * Support u8 slice and u8 vec. * Format fixes * Added tests for the new call functionality. * Improve tests * Format fixes * No need for AsBytes trait * Use try_into instead of into. * Apply suggestions from code review Co-authored-by: Guy Korland <gkorland@gmail.com> --------- Co-authored-by: Guy Korland <gkorland@gmail.com>
- Loading branch information
1 parent
3211882
commit c4b3ac3
Showing
6 changed files
with
192 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#[macro_use] | ||
extern crate redis_module; | ||
|
||
use redis_module::{Context, RedisError, RedisResult, RedisString}; | ||
|
||
fn call_test(ctx: &Context, _: Vec<RedisString>) -> RedisResult { | ||
let res: String = ctx.call("ECHO", &["TEST"])?.try_into()?; | ||
if "TEST" != &res { | ||
return Err(RedisError::Str("Failed calling 'ECHO TEST'")); | ||
} | ||
|
||
let res: String = ctx.call("ECHO", vec!["TEST"].as_slice())?.try_into()?; | ||
if "TEST" != &res { | ||
return Err(RedisError::Str( | ||
"Failed calling 'ECHO TEST' dynamic str vec", | ||
)); | ||
} | ||
|
||
let res: String = ctx.call("ECHO", &[b"TEST"])?.try_into()?; | ||
if "TEST" != &res { | ||
return Err(RedisError::Str( | ||
"Failed calling 'ECHO TEST' with static [u8]", | ||
)); | ||
} | ||
|
||
let res: String = ctx.call("ECHO", vec![b"TEST"].as_slice())?.try_into()?; | ||
if "TEST" != &res { | ||
return Err(RedisError::Str( | ||
"Failed calling 'ECHO TEST' dynamic &[u8] vec", | ||
)); | ||
} | ||
|
||
let res: String = ctx.call("ECHO", &[&"TEST".to_string()])?.try_into()?; | ||
if "TEST" != &res { | ||
return Err(RedisError::Str("Failed calling 'ECHO TEST' with String")); | ||
} | ||
|
||
let res: String = ctx | ||
.call("ECHO", vec![&"TEST".to_string()].as_slice())? | ||
.try_into()?; | ||
if "TEST" != &res { | ||
return Err(RedisError::Str( | ||
"Failed calling 'ECHO TEST' dynamic &[u8] vec", | ||
)); | ||
} | ||
|
||
let res: String = ctx | ||
.call("ECHO", &[&ctx.create_string("TEST")])? | ||
.try_into()?; | ||
if "TEST" != &res { | ||
return Err(RedisError::Str( | ||
"Failed calling 'ECHO TEST' with RedisString", | ||
)); | ||
} | ||
|
||
let res: String = ctx | ||
.call("ECHO", vec![&ctx.create_string("TEST")].as_slice())? | ||
.try_into()?; | ||
if "TEST" != &res { | ||
return Err(RedisError::Str( | ||
"Failed calling 'ECHO TEST' with dynamic array of RedisString", | ||
)); | ||
} | ||
|
||
Ok("pass".into()) | ||
} | ||
|
||
////////////////////////////////////////////////////// | ||
|
||
redis_module! { | ||
name: "call", | ||
version: 1, | ||
data_types: [], | ||
commands: [ | ||
["call.test", call_test, "", 0, 0, 0], | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters