Skip to content

Commit

Permalink
WIP - API extentions.
Browse files Browse the repository at this point in the history
  • Loading branch information
MeirShpilraien committed May 17, 2022
1 parent 517eabf commit 8541ac9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
20 changes: 20 additions & 0 deletions src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/context/thread_safe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ impl ThreadSafeContext<BlockedClient> {
let ctx = Context::new(self.ctx);
ctx.reply(r)
}

pub fn get_ctx(&self) -> Context {
Context::new(self.ctx)
}
}

impl<B: Send> ThreadSafeContext<B> {
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)]
Expand Down

0 comments on commit 8541ac9

Please sign in to comment.