Skip to content

Commit

Permalink
deal with 5 year old todo
Browse files Browse the repository at this point in the history
  • Loading branch information
ephraimfeldblum committed Oct 31, 2024
1 parent 49d9c87 commit 36491ce
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 27 deletions.
33 changes: 19 additions & 14 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,21 @@ macro_rules! redis_command {
return $crate::raw::Status::Err as c_int;
}

if $crate::raw::RedisModule_SetCommandACLCategories.is_some()
&& unsafe {
$crate::raw::RedisModule_SetCommandACLCategories.unwrap()(
command,
acl_categories.as_ptr(),
)
} == $crate::raw::Status::Err as c_int
if let Some(RM_SetCommandACLCategories) =
$crate::raw::RedisModule_SetCommandACLCategories
{
return $crate::raw::Status::Err as c_int;
if RM_SetCommandACLCategories(command, acl_categories.as_ptr())
== $crate::raw::Status::Err as c_int
{
$crate::raw::redis_log(
$ctx,
&format!(
"Error: failed to set command {} ACL categories {}",
$command_name, $acl_categories
),
);
return $crate::raw::Status::Err as c_int;
}
}
}
}};
Expand Down Expand Up @@ -266,12 +272,11 @@ macro_rules! redis_module {

$(
let category = CString::new($acl_category).unwrap();
if $crate::raw::RedisModule_AddACLCategory.is_some() && unsafe {
raw::RedisModule_AddACLCategory.unwrap()(ctx, category.as_ptr())
} == Status::Err as c_int
{
redis_log(ctx, "Error: failed to add ACL category");
return Err("Error: failed to add ACL category");
if let Some(RM_AddACLCategory) = raw::RedisModule_AddACLCategory {
if RM_AddACLCategory(ctx, category.as_ptr()) == raw::Status::Err as c_int {
raw::redis_log(ctx, "Error: failed to add ACL category");
return raw::Status::Err as c_int;
}
}
)*

Expand Down
16 changes: 3 additions & 13 deletions src/native_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl RedisType {
pub fn create_data_type(&self, ctx: *mut raw::RedisModuleCtx) -> Result<(), &str> {
if self.name.len() != 9 {
let msg = "Redis requires the length of native type names to be exactly 9 characters";
redis_log(ctx, format!("{msg}, name is: '{}'", self.name).as_str());
raw::redis_log(ctx, format!("{msg}, name is: '{}'", self.name).as_str());
return Err(msg);
}

Expand All @@ -50,27 +50,17 @@ impl RedisType {
};

if redis_type.is_null() {
redis_log(ctx, "Error: created data type is null");
raw::redis_log(ctx, "Error: created data type is null");
return Err("Error: created data type is null");
}

*self.raw_type.borrow_mut() = redis_type;

redis_log(
raw::redis_log(
ctx,
format!("Created new data type '{}'", self.name).as_str(),
);

Ok(())
}
}

// TODO: Move to raw
#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub fn redis_log(ctx: *mut raw::RedisModuleCtx, msg: &str) {
let level = CString::new("notice").unwrap(); // FIXME reuse this
let msg = CString::new(msg).unwrap();
unsafe {
raw::RedisModule_Log.unwrap()(ctx, level.as_ptr(), msg.as_ptr());
}
}
9 changes: 9 additions & 0 deletions src/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -952,3 +952,12 @@ impl From<c_int> for Version {
pub fn is_io_error(rdb: *mut RedisModuleIO) -> bool {
unsafe { RedisModule_IsIOError.unwrap()(rdb) != 0 }
}

#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub fn redis_log(ctx: *mut RedisModuleCtx, msg: &str) {
let level = CString::new("notice").unwrap(); // FIXME reuse this
let msg = CString::new(msg).unwrap();
unsafe {
RedisModule_Log.unwrap()(ctx, level.as_ptr(), msg.as_ptr());
}
}

0 comments on commit 36491ce

Please sign in to comment.