Skip to content

Commit 26310cb

Browse files
committed
More cleanups
1 parent c9a62cb commit 26310cb

File tree

5 files changed

+12
-19
lines changed

5 files changed

+12
-19
lines changed

examples/hello.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
use std::ffi::CString;
22

3-
extern crate libc;
4-
5-
use libc::c_int;
6-
73
#[macro_use]
84
extern crate redismodule;
9-
10-
use redismodule::Context;
11-
use redismodule::{Command, RedisResult, RedisValue, RedisError};
5+
use redismodule::{Context, Command, RedisResult, RedisValue, RedisError};
126

137
fn hello_mul(_: &Context, args: Vec<String>) -> RedisResult {
148
if args.len() != 3 {
@@ -31,7 +25,7 @@ fn hello_mul(_: &Context, args: Vec<String>) -> RedisResult {
3125

3226
fn parse_integer(arg: &str) -> Result<i64, RedisError> {
3327
arg.parse::<i64>()
34-
.map_err(|_| RedisError::String("Couldn't parse as integer"))
28+
.map_err(|_| RedisError::String(format!("Couldn't parse as integer: {}", arg)))
3529
}
3630

3731
//////////////////////////////////////////////////////

src/context.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::os::raw::c_long;
22
use std::ffi::CString;
33

44
use crate::raw;
5-
use crate::error::Error;
65
use crate::LogLevel;
76
use crate::key::{RedisKey, RedisKeyWritable};
87
use crate::{RedisString, RedisError, RedisValue, RedisResult};
@@ -37,7 +36,7 @@ impl Context {
3736
let _ = command;
3837
let _ = args;
3938

40-
return Err(RedisError::String("not implemented"));
39+
return Err(RedisError::Str("not implemented"));
4140
}
4241

4342
pub fn reply(&self, r: RedisResult) -> raw::Status {
@@ -74,6 +73,11 @@ impl Context {
7473
let msg = CString::new(s).unwrap();
7574
raw::RedisModule_ReplyWithError.unwrap()(self.ctx, msg.as_ptr()).into()
7675
}
76+
77+
Err(RedisError::Str(s)) => unsafe {
78+
let msg = CString::new(s).unwrap();
79+
raw::RedisModule_ReplyWithError.unwrap()(self.ctx, msg.as_ptr()).into()
80+
}
7781
}
7882
}
7983

@@ -85,10 +89,3 @@ impl Context {
8589
RedisKeyWritable::open(self.ctx, key)
8690
}
8791
}
88-
89-
fn handle_status(status: raw::Status, message: &str) -> Result<(), Error> {
90-
match status {
91-
raw::Status::Ok => Ok(()),
92-
raw::Status::Err => Err(error!(message)),
93-
}
94-
}

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![allow(dead_code)]
1+
//#![allow(dead_code)]
22

33
use std::string;
44
use std::os::raw::c_char;

src/macros.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ macro_rules! log_debug {
2424
#[macro_export]
2525
macro_rules! redis_module (
2626
($module_name:expr, $module_version:expr, $commands:expr) => (
27+
use std::os::raw::c_int;
2728
use redismodule::raw;
2829

2930
#[no_mangle]

src/redismodule.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ use crate::raw;
99
#[derive(Debug)]
1010
pub enum RedisError {
1111
WrongArity,
12-
String(&'static str),
12+
Str(&'static str),
13+
String(String),
1314
}
1415

1516
#[derive(Debug)]

0 commit comments

Comments
 (0)