Skip to content

Commit 794ebb6

Browse files
committed
Implement From for RedisValue
1 parent 2054585 commit 794ebb6

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

examples/hello.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::ffi::CString;
99

1010
//use failure::Error;
1111

12-
use redismodule::{Context, Command, RedisResult, RedisValue, RedisError};
12+
use redismodule::{Context, Command, RedisResult, RedisError};
1313

1414
fn hello_mul(_: &Context, args: Vec<String>) -> RedisResult {
1515
if args.len() < 2 {
@@ -24,14 +24,10 @@ fn hello_mul(_: &Context, args: Vec<String>) -> RedisResult {
2424

2525
let product = nums.iter().product();
2626

27-
let response = nums
28-
.into_iter()
29-
.chain(iter::once(product));
27+
let mut response = Vec::from(nums);
28+
response.push(product);
3029

31-
return Ok(RedisValue::Array(
32-
response
33-
.map(RedisValue::Integer)
34-
.collect()));
30+
return Ok(response.into());
3531
}
3632

3733
fn parse_integer(arg: String) -> Result<i64, RedisError> {

src/redismodule.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@ pub enum RedisValue {
2020
Array(Vec<RedisValue>),
2121
}
2222

23+
impl From<Vec<i64>> for RedisValue {
24+
fn from(nums: Vec<i64>) -> Self {
25+
RedisValue::Array(nums
26+
.into_iter()
27+
.map(RedisValue::Integer)
28+
.collect())
29+
}
30+
}
31+
32+
///////////////////////////////////////////////////
33+
2334
#[derive(Debug)]
2435
pub struct RedisString {
2536
ctx: *mut raw::RedisModuleCtx,

0 commit comments

Comments
 (0)