diff --git a/src/context/mod.rs b/src/context/mod.rs index 41735c1a..98b7179c 100644 --- a/src/context/mod.rs +++ b/src/context/mod.rs @@ -203,6 +203,10 @@ impl Context { RedisKey::open(self.ctx, key) } + pub fn open_with_redis_string(&self, key: *mut raw::RedisModuleString) -> RedisKeyWritable { + RedisKeyWritable::open_with_redis_string(self.ctx, key) + } + pub fn open_key_writable(&self, key: &str) -> RedisKeyWritable { RedisKeyWritable::open(self.ctx, key) } @@ -219,6 +223,18 @@ impl Context { self.ctx } + pub fn export_shared_api( + &self, + func: *const ::std::os::raw::c_void, + name: *const ::std::os::raw::c_char, + ) { + raw::export_shared_api( + self.ctx, + func, + name, + ); + } + #[cfg(feature = "experimental-api")] pub fn notify_keyspace_event( &self, diff --git a/src/key.rs b/src/key.rs index 9241dfdf..2a5d2cd1 100644 --- a/src/key.rs +++ b/src/key.rs @@ -1,17 +1,18 @@ -use libc::size_t; use std::convert::TryFrom; use std::os::raw::c_void; use std::ptr; use std::str::Utf8Error; use std::time::Duration; +use libc::size_t; + use raw::KeyType; use crate::from_byte_string; use crate::native_types::RedisType; use crate::raw; -use crate::redismodule::REDIS_OK; use crate::RedisError; +use crate::redismodule::REDIS_OK; use crate::RedisResult; use crate::RedisString; @@ -33,7 +34,6 @@ pub enum KeyMode { pub struct RedisKey { ctx: *mut raw::RedisModuleCtx, key_inner: *mut raw::RedisModuleKey, - key_str: RedisString, } impl RedisKey { @@ -41,9 +41,8 @@ impl RedisKey { let key_str = RedisString::create(ctx, key); let key_inner = raw::open_key(ctx, key_str.inner, to_raw_mode(KeyMode::Read)); RedisKey { - ctx, - key_inner, - key_str, + ctx: ctx, + key_inner: key_inner, } } @@ -127,13 +126,6 @@ impl Drop for RedisKey { pub struct RedisKeyWritable { ctx: *mut raw::RedisModuleCtx, key_inner: *mut raw::RedisModuleKey, - - // The Redis string - // - // This field is needed on the struct so that its Drop implementation gets - // called when it goes out of scope. - #[allow(dead_code)] - key_str: RedisString, } impl RedisKeyWritable { @@ -141,9 +133,8 @@ impl RedisKeyWritable { let key_str = RedisString::create(ctx, key); let key_inner = raw::open_key(ctx, key_str.inner, to_raw_mode(KeyMode::ReadWrite)); RedisKeyWritable { - ctx, - key_inner, - key_str, + ctx: ctx, + key_inner: key_inner, } } @@ -277,7 +268,18 @@ impl RedisKeyWritable { self.key_type() == KeyType::Empty } - pub fn get_value(&self, redis_type: &RedisType) -> Result, RedisError> { + pub fn open_with_redis_string( + ctx: *mut raw::RedisModuleCtx, + key: *mut raw::RedisModuleString, + ) -> RedisKeyWritable { + let key_inner = raw::open_key(ctx, key, to_raw_mode(KeyMode::ReadWrite)); + RedisKeyWritable { + ctx: ctx, + key_inner: key_inner, + } + } + + pub fn get_value<'a, 'b, T>(&'a self, redis_type: &RedisType) -> Result, RedisError> { verify_type(self.key_inner, redis_type)?; let value = unsafe { raw::RedisModule_ModuleTypeGetValue.unwrap()(self.key_inner) as *mut T }; diff --git a/src/raw.rs b/src/raw.rs index ae78a919..a252c502 100644 --- a/src/raw.rs +++ b/src/raw.rs @@ -494,6 +494,14 @@ pub fn subscribe_to_server_event( unsafe { RedisModule_SubscribeToServerEvent.unwrap()(ctx, event, callback).into() } } +pub fn export_shared_api( + ctx: *mut RedisModuleCtx, + func: *const ::std::os::raw::c_void, + name: *const ::std::os::raw::c_char, +) { + unsafe { RedisModule_ExportSharedAPI.unwrap()(ctx, name, func as *mut ::std::os::raw::c_void) }; +} + #[cfg(feature = "experimental-api")] pub fn notify_keyspace_event( ctx: *mut RedisModuleCtx,