Skip to content
Closed
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
63 changes: 31 additions & 32 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ serde_json = "1.0"
serde = "1.0"
libc = "0.2"
jsonpath_lib = { git="https://github.com/RedisJSON/jsonpath.git", branch="public-parser" }
redis-module = { version="0.18", features = ["experimental-api"]}
# redis-module = { version="0.17", features = ["experimental-api"]}
redis-module = { git="https://github.com/RedisLabsModules/redismodule-rs.git", branch="RedisString", features = ["experimental-api"]}
# redis-module = { path="../redismodule-rs", features = ["experimental-api"]}
# readies-wd40 = { path = "deps/readies/wd40" }

[features]
Expand Down
10 changes: 6 additions & 4 deletions src/c_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::{
use redis_module::key::verify_type;
use redis_module::key::RedisKeyWritable;
use redis_module::logging::log_notice;
use redis_module::{raw as rawmod, RedisError};
use redis_module::{raw as rawmod, RedisError, RedisString};
use redis_module::{Context, Status};
use serde_json::Value;

Expand Down Expand Up @@ -82,18 +82,20 @@ impl<'a> JSONApiKey<'a> {
ctx: *mut rawmod::RedisModuleCtx,
key_str: *mut rawmod::RedisModuleString,
) -> Result<JSONApiKey<'a>, RedisError> {
let key = RedisString::new(ctx, key_str);
let ctx = Context::new(ctx);
let key = ctx.open_with_redis_string(key_str);
let key = ctx.open_key_writable(&key);
JSONApiKey::new_from_key(key)
}

pub fn new_from_str(
ctx: *mut rawmod::RedisModuleCtx,
path: *const c_char,
) -> Result<JSONApiKey<'a>, RedisError> {
let ctx = Context::new(ctx);
let path = unsafe { CStr::from_ptr(path).to_str().unwrap() };

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line not from this PR, but still would like to raise that since it is also related to UFT-8 and lossy conversion vs. error handling mentioned in this comment
let path = unsafe { CStr::from_ptr(path).to_str().unwrap() };
This would panic if invalid UTF-8 is passed here.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since c_api.rs currently has no error reporting capability, we should detect conversion failure and the caller should return null on failure (assuming invalid UFT-8 can arrive from redis/from callers of new_from_str)

let key = ctx.open_key_writable(path);
let key = RedisString::create(ctx, path);
let ctx = Context::new(ctx);
let key = ctx.open_key_writable(&key);
JSONApiKey::new_from_key(key)
}
}
Expand Down
Loading