diff --git a/src/context/mod.rs b/src/context/mod.rs index 1e64e2ef..34f2a2a6 100644 --- a/src/context/mod.rs +++ b/src/context/mod.rs @@ -161,6 +161,26 @@ impl Context { unsafe { raw::RedisModule_ReplyWithSimpleString.unwrap()(self.ctx, msg.as_ptr()).into() } } + #[allow(clippy::must_use_candidate)] + pub fn reply_bulk_string(&self, s: &str) -> raw::Status { + unsafe { raw::RedisModule_ReplyWithStringBuffer.unwrap()(self.ctx, s.as_ptr() as *mut c_char, s.len()).into() } + } + + #[allow(clippy::must_use_candidate)] + pub fn reply_array(&self, size: usize) -> raw::Status { + unsafe { raw::RedisModule_ReplyWithArray.unwrap()(self.ctx, size as c_long).into() } + } + + #[allow(clippy::must_use_candidate)] + pub fn reply_long(&self, l: i64) -> raw::Status { + unsafe { raw::RedisModule_ReplyWithLongLong.unwrap()(self.ctx, l as c_long).into() } + } + + #[allow(clippy::must_use_candidate)] + pub fn reply_double(&self, d: f64) -> raw::Status { + unsafe { raw::RedisModule_ReplyWithDouble.unwrap()(self.ctx, d).into() } + } + #[allow(clippy::must_use_candidate)] pub fn reply_error_string(&self, s: &str) -> raw::Status { let msg = Self::str_as_legal_resp_string(s); diff --git a/src/context/thread_safe.rs b/src/context/thread_safe.rs index a4e5f7a4..45e42122 100644 --- a/src/context/thread_safe.rs +++ b/src/context/thread_safe.rs @@ -70,6 +70,10 @@ impl ThreadSafeContext { let ctx = Context::new(self.ctx); ctx.reply(r) } + + pub fn get_ctx(&self) -> Context { + Context::new(self.ctx) + } } impl ThreadSafeContext { diff --git a/src/lib.rs b/src/lib.rs index 6ce71b42..953c8d12 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,7 +17,7 @@ mod redismodule; pub mod redisraw; pub mod redisvalue; -mod context; +pub mod context; pub mod key; pub mod logging; mod macros; @@ -40,7 +40,7 @@ use backtrace::Backtrace; /// The workaround is to use the `test` feature instead. #[cfg(not(feature = "test"))] #[global_allocator] -static ALLOC: crate::alloc::RedisAlloc = crate::alloc::RedisAlloc; +pub static ALLOC: crate::alloc::RedisAlloc = crate::alloc::RedisAlloc; /// `LogLevel` is a level of logging to be specified with a Redis log directive. #[derive(Clone, Copy, Debug, AsRefStr)]