Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add high level wrapper for RedisModule_EmitAOF #75

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,9 @@ impl Context {
pub fn create_string(&self, s: &str) -> RedisString {
RedisString::create(self.ctx, s)
}

#[cfg(feature = "experimental-api")]
pub fn emit_aof(&self, io: *mut raw::RedisModuleIO, command: &str, args: &[&str]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The public API of Context should not use raw pointers like *mut raw::RedisModuleIO; its whole purpose it to provide a safe abstraction over them.

I haven't dived deeply into this, but it seems the correct thing here is to create a wrapper struct around the raw type and pass safe Rust references to it (like Context itself).

raw::emit_aof(self.ctx, io, command, args)
}
}
17 changes: 17 additions & 0 deletions src/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,20 @@ pub fn string_append_buffer(
RedisModule_StringAppendBuffer.unwrap()(ctx, s, buff.as_ptr() as *mut i8, buff.len()).into()
}
}

#[cfg(feature = "experimental-api")]
pub fn emit_aof(ctx: *mut RedisModuleCtx, io: *mut RedisModuleIO, command: &str, args: &[&str]) {
let terminated_args: Vec<RedisString> =
args.iter().map(|s| RedisString::create(ctx, s)).collect();
let inner_args: Vec<*mut RedisModuleString> = terminated_args.iter().map(|s| s.inner).collect();
let cmd = CString::new(command).unwrap();
unsafe {
RedisModule_EmitAOF.unwrap()(
io,
cmd.as_ptr(),
FMT,
inner_args.as_ptr() as *const c_char,
terminated_args.len(),
)
}
}