diff --git a/src/context/mod.rs b/src/context/mod.rs index 344ecd09..1868a59f 100644 --- a/src/context/mod.rs +++ b/src/context/mod.rs @@ -198,6 +198,10 @@ impl Context { RedisKey::open(self.ctx, key) } + pub fn open_with_redis_string(&self, string: *mut raw::RedisModuleString) -> RedisKeyWritable { + RedisKeyWritable::open_with_redis_string(self.ctx, string) + } + pub fn open_key_writable(&self, key: &str) -> RedisKeyWritable { RedisKeyWritable::open(self.ctx, key) } @@ -214,6 +218,18 @@ impl Context { return 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 edc83ba7..ca84b29f 100644 --- a/src/key.rs +++ b/src/key.rs @@ -239,7 +239,20 @@ 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, + string: *mut raw::RedisModuleString, + ) -> RedisKeyWritable { + let key_str = RedisString::create_from_redis_string(ctx, string); + let key_inner = raw::open_key(ctx, key_str.inner, to_raw_mode(KeyMode::ReadWrite)); + RedisKeyWritable { + ctx, + key_inner, + key_str, + } + } + + 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 26b4a8a0..61262929 100644 --- a/src/raw.rs +++ b/src/raw.rs @@ -475,6 +475,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, diff --git a/src/redismodule.rs b/src/redismodule.rs index 6fcb4d91..bf2c2a99 100644 --- a/src/redismodule.rs +++ b/src/redismodule.rs @@ -103,6 +103,16 @@ impl RedisString { RedisString { ctx, inner } } + pub fn create_from_redis_string( + ctx: *mut raw::RedisModuleCtx, + redis_string: *mut raw::RedisModuleString, + ) -> RedisString { + RedisString { + ctx, + inner: redis_string, + } + } + pub fn from_ptr<'a>(ptr: *const raw::RedisModuleString) -> Result<&'a str, Utf8Error> { let mut len: libc::size_t = 0; let bytes = unsafe { raw::RedisModule_StringPtrLen.unwrap()(ptr, &mut len) };