Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ serde_json = "1.0"
serde = "1.0"
libc = "0.2"
jsonpath_lib = { git="https://github.com/RedisJSON/jsonpath.git", branch="generic_json_path" }
# redis-module = { path="/home/meir/work/redismodule-rs", features = ["experimental-api"]}
redis-module = { version="0.18", features = ["experimental-api"]}

redis-module = { version="0.20", features = ["experimental-api"]}
[features]
# Workaround to allow cfg(feature = "test") in redismodue-rs dependencies:
# https://github.com/RedisLabsModules/redismodule-rs/pull/68
Expand Down
18 changes: 5 additions & 13 deletions src/c_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use libc::size_t;
use std::ffi::CString;
use std::os::raw::{c_double, c_int, c_long};
use std::ptr::{null, null_mut};
use std::slice;
use std::{
ffi::CStr,
os::raw::{c_char, c_void},
Expand All @@ -14,9 +13,8 @@ use crate::commands::KeyValue;
use jsonpath_lib::select::select_value::{SelectValue, SelectValueType};
use jsonpath_lib::select::Selector;
use redis_module::key::verify_type;
use redis_module::redisraw::bindings::RedisModule_StringPtrLen;
use redis_module::{raw as rawmod, RedisError};
use redis_module::{Context, Status};
use redis_module::{Context, RedisString, Status};
use serde_json::Value;

use crate::manager::{Manager, ReadHolder, RedisJsonKeyManager};
Expand Down Expand Up @@ -64,10 +62,10 @@ pub fn create_rmstring(
fn json_api_open_key_internal<M: Manager>(
manager: M,
ctx: *mut rawmod::RedisModuleCtx,
key: &str,
key: RedisString,
) -> *const M::V {
let ctx = Context::new(ctx);
if let Ok(h) = manager.open_key_read(&ctx, key) {
if let Ok(h) = manager.open_key_read(&ctx, &key) {
if let Ok(v) = h.get_value() {
if let Some(v) = v {
return v;
Expand All @@ -82,18 +80,12 @@ pub extern "C" fn JSONAPI_openKey(
ctx: *mut rawmod::RedisModuleCtx,
key_str: *mut rawmod::RedisModuleString,
) -> *mut c_void {
let mut len = 0;
let key = unsafe {
let bytes = RedisModule_StringPtrLen.unwrap()(key_str, &mut len);
let bytes = slice::from_raw_parts(bytes as *const u8, len);
String::from_utf8_lossy(bytes).into_owned()
};
json_api_open_key_internal(
RedisJsonKeyManager {
phantom: PhantomData,
},
ctx,
&key,
RedisString::new(ctx, key_str),
) as *mut c_void
}

Expand All @@ -108,7 +100,7 @@ pub extern "C" fn JSONAPI_openKeyFromStr(
phantom: PhantomData,
},
ctx,
&key,
RedisString::create(ctx, key),
) as *mut c_void
}

Expand Down
Loading