Skip to content

Commit

Permalink
Merge pull request #139 from RedisLabsModules/omer_feature-search-json
Browse files Browse the repository at this point in the history
WIP open_with_redis_string does not take ownership of the RedisModuleString
  • Loading branch information
oshadmi authored Apr 18, 2021
2 parents 06a9724 + 036cb51 commit 2aa926b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 23 deletions.
25 changes: 12 additions & 13 deletions src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ pub enum KeyMode {
pub struct RedisKey {
ctx: *mut raw::RedisModuleCtx,
key_inner: *mut raw::RedisModuleKey,
key_str: RedisString,
key_str: Option<RedisString>,
}

impl RedisKey {
pub fn open(ctx: *mut raw::RedisModuleCtx, key: &str) -> 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,
key_str: Some(key_str),
}
}

Expand Down Expand Up @@ -133,17 +133,17 @@ pub struct RedisKeyWritable {
// 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,
key_str: Option<RedisString>,
}

impl RedisKeyWritable {
pub fn open(ctx: *mut raw::RedisModuleCtx, key: &str) -> 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,
key_str: Some(key_str),
}
}

Expand Down Expand Up @@ -243,12 +243,11 @@ impl RedisKeyWritable {
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));
let key_inner = raw::open_key(ctx, string, to_raw_mode(KeyMode::ReadWrite));
RedisKeyWritable {
ctx,
key_inner,
key_str,
ctx: ctx,
key_inner: key_inner,
key_str: None,
}
}

Expand Down
10 changes: 0 additions & 10 deletions src/redismodule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,6 @@ 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) };
Expand Down

0 comments on commit 2aa926b

Please sign in to comment.