Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a9e423d
Update to Redis 6.2.2 (#332)
gkorland Apr 29, 2021
00e9f9d
Fix json.arrappend performance (#324)
gkorland Apr 29, 2021
63d9c65
normalize index for backward (#327)
gkorland Apr 30, 2021
9d0aba5
fix #318 (#333)
gkorland May 2, 2021
fd4a76a
CircleCI: macOS and benchmark fixes (#337)
rafie May 3, 2021
ca866fa
Update config.yml (#338)
gkorland May 3, 2021
ac32737
Add JSON.CLEAR command (#306)
oshadmi May 3, 2021
3a882c7
Update RS_VERSIONS
TomerHekmati May 3, 2021
cffa9ca
Merge pull request #339 from RedisJSON/tomerhekredis-patch-1
TomerHekmati May 4, 2021
3654e36
Document flags for running tests
gavrie May 4, 2021
33837d2
fix arr_pop backward to 1.0 (#345)
gkorland May 5, 2021
283ceae
JSON.INSERTARR backward compatability for 1.0 (#343)
gkorland May 5, 2021
45187a4
Update deploy-docs.yaml (#341)
gkorland May 5, 2021
92ffe37
fixes 1
rafie May 5, 2021
3b92a62
Merge remote-tracking branch 'origin/master' into rafi-sj-merge-to-ma…
rafie May 5, 2021
8e70965
Changes per Guy's review
oshadmi May 6, 2021
886361d
Minimal Redis version support is 6 (#350)
gkorland May 9, 2021
ad47674
Updated readies (for getrust fix) (#353)
rafie May 9, 2021
2422b20
Add support client library (#351)
dengliming May 9, 2021
267e346
Changes per Gavrie's review
oshadmi May 11, 2021
af386ad
Merge remote-tracking branch 'origin/master' into rafi-sj-merge-to-ma…
rafie May 11, 2021
5e1a387
Updated readies
rafie May 11, 2021
d1b6dc8
Merge branch 'rafi-sj-merge-to-master' of ssh://github.com/RedisJSON/…
rafie May 11, 2021
79ce913
Merge remote-tracking branch 'origin/rafi-sj-merge-to-master' into ra…
rafie May 12, 2021
c3795e3
Merge from review branch
rafie May 12, 2021
62b1cca
fixes 1
rafie May 12, 2021
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
1 change: 1 addition & 0 deletions .github/workflows/deploy-docs.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Deploy docs to website

on:
workflow_dispatch:
push:
branches:
- master
Expand Down
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,3 @@ lazy_static = "1.4.0"
# https://github.com/RedisLabsModules/redismodule-rs/pull/68
# This requires running the tests with `--features test`
test = ["redis-module/test"]
# experimental-api = []
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ Some languages have client libraries that provide support for RedisJSON's comman
| [node_redis-rejson][node_redis-rejson-url] | Node.js | MIT | [Kyle Davis @stockholmux][node_redis-rejson-author] | [![node_redis-rejson-stars]][node_redis-rejson-url] | [npm][node_redis-rejson-package] |
| [redis-modules-sdk][redis-modules-sdk-url] | Node.js | BSD-3-Clause | [Dani Tseitlin @danitseitlin][redis-modules-sdk-author] | [![redis-modules-sdk-stars]][redis-modules-sdk-url] | [npm][redis-modules-sdk-package] |
| [JRedisJSON][JRedisJSON-url] | Java | BSD-2-Clause | [Redis Labs][JRedisJSON-author] | [![JRedisJSON-stars]][JRedisJSON-url] | [maven][JRedisJSON-package] |
| [redis-modules-java][redis-modules-java-url] | Java | Apache-2.0 | [Liming Deng @dengliming][redis-modules-java-author] | [![redis-modules-java-stars]][redis-modules-java-url] | [maven][redis-modules-java-package] |
| [redisjson-py][rejson-py-url] | Python | BSD-2-Clause | [Redis Labs][rejson-py-author] | [![rejson-py-stars]][rejson-py-url] | [pypi][rejson-py-package] |
| [go-rejson][go-rejson-url] | Go | MIT | [Nitish Malhotra @nitishm][go-rejson-author] | [![go-rejson-stars]][go-rejson-url] | |
| [rejonson][rejonson-url] | Go | Apache-2.0 | [Daniel Krom @KromDaniel][rejonson-author] | [![rejonson-stars]][rejonson-url] | |
Expand Down Expand Up @@ -99,6 +100,11 @@ Some languages have client libraries that provide support for RedisJSON's comman
[JRedisJSON-package]: https://search.maven.org/artifact/com.redislabs/jrejson/1.2.0/jar
[JRedisJSON-stars]: https://img.shields.io/github/stars/RedisJSON/JRedisJSON.svg?style=social&label=Star&maxAge=2592000

[redis-modules-java-author]: https://github.com/dengliming/
[redis-modules-java-url]: https://github.com/dengliming/redis-modules-java
[redis-modules-java-package]: https://search.maven.org/artifact/io.github.dengliming.redismodule/redis-modules-java/
[redis-modules-java-stars]: https://img.shields.io/github/stars/dengliming/redis-modules-java.svg?style=social&label=Star&maxAge=2592000

[rejson-py-author]: https://redislabs.com
[rejson-py-url]: https://github.com/RedisJSON/redisjson-py
[rejson-py-package]: https://pypi.python.org/pypi/rejson
Expand Down
2 changes: 1 addition & 1 deletion deps/readies
6 changes: 6 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ Some languages have client libraries that provide support for RedisJSON's comman
| [node_redis-rejson][node_redis-rejson-url] | Node.js | MIT | [Kyle Davis @stockholmux][node_redis-rejson-author] | [![node_redis-rejson-stars]][node_redis-rejson-url] | [npm][node_redis-rejson-package] |
| [redis-modules-sdk][redis-modules-sdk-url] | Node.js | BSD-3-Clause | [Dani Tseitlin @danitseitlin][redis-modules-sdk-author] | [![redis-modules-sdk-stars]][redis-modules-sdk-url] | [npm][redis-modules-sdk-package] |
| [JRedisJSON][JRedisJSON-url] | Java | BSD-2-Clause | [Redis Labs][JRedisJSON-author] | [![JRedisJSON-stars]][JRedisJSON-url] | [maven][JRedisJSON-package] |
| [redis-modules-java][redis-modules-java-url] | Java | Apache-2.0 | [Liming Deng @dengliming][redis-modules-java-author] | [![redis-modules-java-stars]][redis-modules-java-url] | [maven][redis-modules-java-package] |
| [redisjson-py][rejson-py-url] | Python | BSD-2-Clause | [Redis Labs][rejson-py-author] | [![rejson-py-stars]][rejson-py-url] | [pypi][rejson-py-package] |
| [go-rejson][go-rejson-url] | Go | MIT | [Nitish Malhotra @nitishm][go-rejson-author] | [![go-rejson-stars]][go-rejson-url] | |
| [rejonson][rejonson-url] | Go | Apache-2.0 | [Daniel Krom @KromDaniel][rejonson-author] | [![rejonson-stars]][rejonson-url] | |
Expand Down Expand Up @@ -259,6 +260,11 @@ Some languages have client libraries that provide support for RedisJSON's comman
[JRedisJSON-package]: https://search.maven.org/artifact/com.redislabs/jrejson/1.2.0/jar
[JRedisJSON-stars]: https://img.shields.io/github/stars/RedisJSON/JRedisJSON.svg?style=social&label=Star&maxAge=2592000

[redis-modules-java-author]: https://github.com/dengliming/
[redis-modules-java-url]: https://github.com/dengliming/redis-modules-java
[redis-modules-java-package]: https://search.maven.org/artifact/io.github.dengliming.redismodule/redis-modules-java/
[redis-modules-java-stars]: https://img.shields.io/github/stars/dengliming/redis-modules-java.svg?style=social&label=Star&maxAge=2592000

[rejson-py-author]: https://redislabs.com
[rejson-py-url]: https://github.com/RedisJSON/redisjson-py
[rejson-py-package]: https://pypi.python.org/pypi/rejson
Expand Down
4 changes: 2 additions & 2 deletions ramp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ description: Native JSON Data Type for Redis
homepage: http://redisjson.io
license: Redis Source Available License Agreement
command_line_args: ""
min_redis_version: "5.0"
min_redis_pack_version: "5.4"
min_redis_version: "6.0"
min_redis_pack_version: "6.0"
capabilities:
- types
- no_multi_key
Expand Down
110 changes: 39 additions & 71 deletions src/c_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use crate::redisjson::Format;
use crate::{redisjson::RedisJSON, REDIS_JSON_TYPE};
use redis_module::key::RedisKeyWritable;
use redis_module::logging::log_notice;
use redis_module::Context;
use redis_module::{raw as rawmod, RedisError};
use redis_module::{Context, Status};
use serde_json::Value;

// extern crate readies_wd40;
Expand All @@ -22,12 +22,6 @@ use serde_json::Value;
// structs
//

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct RedisModuleCtx {
_unused: [u8; 0],
}

#[repr(C)]
pub enum JSONType {
String = 0,
Expand All @@ -39,13 +33,6 @@ pub enum JSONType {
Null = 6,
}

#[repr(C)]
#[allow(non_camel_case_types)]
pub enum RedisReturnCode {
REDISMODULE_OK = 0,
REDISMODULE_ERR = 1,
}

//---------------------------------------------------------------------------------------------

pub struct JSONApiKey<'a> {
Expand All @@ -65,18 +52,14 @@ impl<'a> JSONApiKey<'a> {
let p = s.as_bytes_with_nul().as_ptr() as *const c_char;
let len = s.as_bytes().len();
unsafe { *str = rawmod::RedisModule_CreateString.unwrap()(self.ctx.get_raw(), p, len) };
return RedisReturnCode::REDISMODULE_OK as c_int;
return Status::Ok as c_int;
}
return RedisReturnCode::REDISMODULE_ERR as c_int;
Status::Err as c_int
}

fn get_value(&self, path: *const c_char) -> Option<&Value> {
let path = unsafe { CStr::from_ptr(path).to_str().unwrap() };
if let Ok(ref value) = self.redis_json.get_first(path) {
Some(value)
} else {
None
}
self.redis_json.get_first(path).ok()
}
}
pub type JSONApiKeyRef<'a> = *mut JSONApiKey<'a>;
Expand Down Expand Up @@ -190,14 +173,14 @@ pub extern "C" fn JSONAPI_getString(
*str = s.as_bytes_with_nul().as_ptr() as *const c_char;
*len = s.as_bytes().len();
}
return RedisReturnCode::REDISMODULE_OK as c_int;
return Status::Ok as c_int;
} else if let Some(ref p) = json.path {
if let Ok(s) = json.json_key.redis_json.to_string(p.as_str(), Format::JSON) {
return json.set_string(s.as_str(), str, len);
}
}
}
RedisReturnCode::REDISMODULE_ERR as c_int
Status::Err as c_int
}

#[no_mangle]
Expand All @@ -217,11 +200,11 @@ pub extern "C" fn JSONAPI_getStringFromKey(
*len = s.as_bytes().len();
}
key.cstr_val = Some(s);
return RedisReturnCode::REDISMODULE_OK as c_int;
return Status::Ok as c_int;
}
}
}
RedisReturnCode::REDISMODULE_ERR as c_int
Status::Err as c_int
}

#[no_mangle]
Expand All @@ -237,7 +220,7 @@ pub extern "C" fn JSONAPI_getRedisModuleString(
}
}
}
return RedisReturnCode::REDISMODULE_ERR as c_int;
Status::Err as c_int
}

#[no_mangle]
Expand All @@ -252,10 +235,10 @@ pub extern "C" fn JSONAPI_getRedisModuleStringFromKey(
if let Ok(res) = key.redis_json.to_string(path, Format::JSON) {
key.create_rmstring(res.as_str(), str)
} else {
RedisReturnCode::REDISMODULE_ERR as c_int
Status::Err as c_int
}
} else {
RedisReturnCode::REDISMODULE_ERR as c_int
Status::Err as c_int
}
}

Expand All @@ -280,47 +263,32 @@ fn get_int_value(value: &Value) -> Option<c_long> {
}
_ => {}
}
return None;
None
}

fn get_double_value(value: &Value) -> Option<c_double> {
match value {
Value::Number(n) => {
if let Some(f) = n.as_f64() {
return Some(f);
}
}
Value::String(ref s) => {
if let Ok(v) = c_double::from_str(s.as_str()) {
return Some(v);
}
}
Value::Bool(ref b) => {
if *b {
return Some(1.0);
} else {
return Some(0.0);
}
}
_ => {}
Value::Number(n) if n.is_f64() => n.as_f64(),
Value::String(s) => c_double::from_str(s.as_str()).ok(),
Value::Bool(b) => Some(if *b { 1.0 } else { 0.0 }),
_ => None,
}
return None;
}

fn get_bool_value(value: &Value) -> Option<c_int> {
match value {
Value::Bool(ref b) => return if *b { Some(1) } else { Some(0) },
Value::Number(n) => {
if let Some(i) = n.as_i64() {
return if i != 0 { Some(1) } else { Some(0) };
} else if let Some(f) = n.as_f64() {
return if f != 0.0 { Some(1) } else { Some(0) };
Value::Bool(b) => {
if *b {
Some(1)
} else {
Some(0)
}
}
Value::String(ref s) => return if s.len() != 0 { Some(1) } else { Some(0) },
_ => {}
Value::Number(n) if n.is_i64() => Some(if n.as_i64().unwrap() != 0 { 1 } else { 0 }),
Value::Number(n) if n.is_f64() => Some(if n.as_f64().unwrap() != 0.0 { 1 } else { 0 }),
Value::String(s) => Some(if s.is_empty() { 0 } else { 1 }),
_ => None,
}
return None;
}

#[no_mangle]
Expand All @@ -329,10 +297,10 @@ pub extern "C" fn JSONAPI_getInt(json: JSONApiPathRef, val: *mut c_long) -> c_in
let json = unsafe { &mut *json };
if let Some(v) = get_int_value(json.value) {
unsafe { *val = v };
return RedisReturnCode::REDISMODULE_OK as c_int;
return Status::Ok as c_int;
}
}
return RedisReturnCode::REDISMODULE_ERR as c_int;
Status::Err as c_int
}

#[no_mangle]
Expand All @@ -346,11 +314,11 @@ pub extern "C" fn JSONAPI_getIntFromKey(
if let Some(value) = key.get_value(path) {
if let Some(v) = get_int_value(value) {
unsafe { *val = v };
return RedisReturnCode::REDISMODULE_OK as c_int;
return Status::Ok as c_int;
}
}
}
return RedisReturnCode::REDISMODULE_ERR as c_int;
Status::Err as c_int
}

#[no_mangle]
Expand All @@ -359,10 +327,10 @@ pub extern "C" fn JSONAPI_getDouble(json: JSONApiPathRef, val: *mut c_double) ->
let json = unsafe { &mut *json };
if let Some(v) = get_double_value(json.value) {
unsafe { *val = v };
return RedisReturnCode::REDISMODULE_OK as c_int;
return Status::Ok as c_int;
}
}
return RedisReturnCode::REDISMODULE_ERR as c_int;
Status::Err as c_int
}

#[no_mangle]
Expand All @@ -376,11 +344,11 @@ pub extern "C" fn JSONAPI_getDoubleFromKey(
if let Some(value) = key.get_value(path) {
if let Some(v) = get_double_value(value) {
unsafe { *val = v };
return RedisReturnCode::REDISMODULE_OK as c_int;
return Status::Ok as c_int;
}
}
}
return RedisReturnCode::REDISMODULE_ERR as c_int;
Status::Err as c_int
}

#[no_mangle]
Expand All @@ -389,10 +357,10 @@ pub extern "C" fn JSONAPI_getBoolean(json: JSONApiPathRef, val: *mut c_int) -> c
let json = unsafe { &*json };
if let Some(v) = get_bool_value(json.value) {
unsafe { *val = v };
return RedisReturnCode::REDISMODULE_OK as c_int;
return Status::Ok as c_int;
}
}
return RedisReturnCode::REDISMODULE_ERR as c_int;
Status::Err as c_int
}

#[no_mangle]
Expand All @@ -406,11 +374,11 @@ pub extern "C" fn JSONAPI_getBooleanFromKey(
if let Some(value) = key.get_value(path) {
if let Some(v) = get_bool_value(value) {
unsafe { *val = v };
return RedisReturnCode::REDISMODULE_OK as c_int;
return Status::Ok as c_int;
}
}
}
return RedisReturnCode::REDISMODULE_ERR as c_int;
Status::Err as c_int
}

//---------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -500,10 +468,10 @@ impl<'a> JSONApiPath<'a> {
*len = s.as_bytes().len();
}
self.cstr_val = Some(s);
return RedisReturnCode::REDISMODULE_OK as c_int;
return Status::Ok as c_int;
}
}
return RedisReturnCode::REDISMODULE_ERR as c_int;
Status::Err as c_int
}
}

Expand Down
38 changes: 22 additions & 16 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,23 +342,29 @@ where
let path = backwards_compat_path(args.next_string()?);
let number = args.next_string()?;

let redis_key = ctx.open_key_writable(&key);
// FIXME: Consider how to make a similar change to all other commands:
// FIXME: Have the keyspace notification and the replication occur only after the `data:Value` of the JSonPath is updated and the key in redis is closed (naively done here using a nested block)
let res = {
let redis_key = ctx.open_key_writable(&key);

redis_key
.get_value::<RedisJSON>(&REDIS_JSON_TYPE)?
.ok_or_else(RedisError::nonexistent_key)
.and_then(|doc| {
doc.value_op(
&path,
|value| do_json_num_op(&number, value, &op_i64, &op_f64),
|result| Ok(result.to_string().into()),
)
.map_err(|e| e.into())
})
};

redis_key
.get_value::<RedisJSON>(&REDIS_JSON_TYPE)?
.ok_or_else(RedisError::nonexistent_key)
.and_then(|doc| {
doc.value_op(
&path,
|value| do_json_num_op(&number, value, &op_i64, &op_f64),
|result| {
ctx.notify_keyspace_event(NotifyEvent::MODULE, cmd, key.as_str());
ctx.replicate_verbatim();
Ok(result.to_string().into())
},
)
.map_err(|e| e.into())
})
if let Ok(_) = res {
ctx.notify_keyspace_event(NotifyEvent::MODULE, cmd, key.as_str());
ctx.replicate_verbatim();
}
res
}

fn do_json_num_op<I, F>(
Expand Down
17 changes: 0 additions & 17 deletions tasks.json

This file was deleted.