From 3dd3a8d4e8c6bc22d364c50e7dab5be716d1f401 Mon Sep 17 00:00:00 2001 From: Guy Korland Date: Tue, 30 Aug 2022 14:33:12 +0300 Subject: [PATCH 1/3] add ERR prefix to error --- src/key.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/key.rs b/src/key.rs index 3ccb97bc..dadda27c 100644 --- a/src/key.rs +++ b/src/key.rs @@ -269,6 +269,14 @@ impl RedisKeyWritable { REDIS_OK } + /// # Panics + /// + /// Will panic if `RedisModule_UnlinkKey` is missing in redismodule.h + pub fn unlink(&self) -> RedisResult { + unsafe { raw::RedisModule_UnlinkKey.unwrap()(self.key_inner) }; + REDIS_OK + } + /// # Panics /// /// Will panic if `RedisModule_KeyType` is missing in redismodule.h @@ -502,7 +510,7 @@ pub fn verify_type(key_inner: *mut raw::RedisModuleKey, redis_type: &RedisType) let raw_type = unsafe { raw::RedisModule_ModuleTypeGetType.unwrap()(key_inner) }; if raw_type != *redis_type.raw_type.borrow() { - return Err(RedisError::Str("Existing key has wrong Redis type")); + return Err(RedisError::Str("ERR Existing key has wrong Redis type")); } } From 5618ef377ca0ac102f17207c76a96319a7f7d42b Mon Sep 17 00:00:00 2001 From: Guy Korland Date: Tue, 30 Aug 2022 14:36:35 +0300 Subject: [PATCH 2/3] remove unlink --- src/key.rs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/key.rs b/src/key.rs index dadda27c..9819fb09 100644 --- a/src/key.rs +++ b/src/key.rs @@ -269,14 +269,6 @@ impl RedisKeyWritable { REDIS_OK } - /// # Panics - /// - /// Will panic if `RedisModule_UnlinkKey` is missing in redismodule.h - pub fn unlink(&self) -> RedisResult { - unsafe { raw::RedisModule_UnlinkKey.unwrap()(self.key_inner) }; - REDIS_OK - } - /// # Panics /// /// Will panic if `RedisModule_KeyType` is missing in redismodule.h From 6e919dcc8e84cd33c4f3f80722de8a418a98c18f Mon Sep 17 00:00:00 2001 From: Guy Korland Date: Mon, 16 Jan 2023 12:50:37 +0200 Subject: [PATCH 3/3] Add ERR prefix to all errors --- examples/data_type.rs | 2 +- src/key.rs | 6 +++--- src/raw.rs | 2 +- src/rediserror.rs | 8 ++++---- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/data_type.rs b/examples/data_type.rs index 69b94ad4..e196ab01 100644 --- a/examples/data_type.rs +++ b/examples/data_type.rs @@ -37,7 +37,7 @@ static MY_REDIS_TYPE: RedisType = RedisType::new( ); unsafe extern "C" fn free(value: *mut c_void) { - Box::from_raw(value.cast::()); + drop(Box::from_raw(value.cast::())); } fn alloc_set(ctx: &Context, args: Vec) -> RedisResult { diff --git a/src/key.rs b/src/key.rs index 9819fb09..a1133127 100644 --- a/src/key.rs +++ b/src/key.rs @@ -402,7 +402,7 @@ where /// let hm = ctx /// .open_key(keyname) /// .hash_get_multi(fields)? - /// .ok_or(RedisError::Str("ERR key not found"))?; + /// .ok_or(RedisError::Str("key not found"))?; /// let response: HashMap<&str, String> = hm.into_iter().collect(); /// ``` /// @@ -414,7 +414,7 @@ where /// let hm = ctx /// .open_key(keyname) /// .hash_get_multi(fields)? - /// .ok_or(RedisError::Str("ERR key not found"))?; + /// .ok_or(RedisError::Str("key not found"))?; /// let response: Vec = hm.into_iter().map(|(_, v)| v).collect(); /// ``` /// @@ -502,7 +502,7 @@ pub fn verify_type(key_inner: *mut raw::RedisModuleKey, redis_type: &RedisType) let raw_type = unsafe { raw::RedisModule_ModuleTypeGetType.unwrap()(key_inner) }; if raw_type != *redis_type.raw_type.borrow() { - return Err(RedisError::Str("ERR Existing key has wrong Redis type")); + return Err(RedisError::Str("Existing key has wrong Redis type")); } } diff --git a/src/raw.rs b/src/raw.rs index ae122442..61e35c4f 100644 --- a/src/raw.rs +++ b/src/raw.rs @@ -365,7 +365,7 @@ where match res { Status::Ok => Ok(()), - Status::Err => Err(RedisError::Str("ERR key is not a hash value")), + Status::Err => Err(RedisError::Str("key is not a hash value")), } } diff --git a/src/rediserror.rs b/src/rediserror.rs index e7a98c16..e73e7f5c 100644 --- a/src/rediserror.rs +++ b/src/rediserror.rs @@ -13,18 +13,18 @@ pub enum RedisError { impl RedisError { #[must_use] pub fn nonexistent_key() -> Self { - Self::Str("ERR could not perform this operation on a key that doesn't exist") + Self::Str("could not perform this operation on a key that doesn't exist") } #[must_use] pub fn short_read() -> Self { - Self::Str("ERR short read or OOM loading DB") + Self::Str("short read or OOM loading DB") } } impl From for RedisError { fn from(e: T) -> Self { - Self::String(format!("ERR {}", e)) + Self::String(e.to_string()) } } @@ -45,6 +45,6 @@ impl fmt::Display for RedisError { RedisError::String(s) => s.as_str(), }; - write!(f, "{}", d) + write!(f, "ERR {d}") } }