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
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::array_index::ArrayIndex;
use crate::error::Error;
use crate::redisjson::{Format, Path, RedisJSON, SetOptions};

pub const REDIS_JSON_TYPE_VERSION: i32 = 2;
pub const REDIS_JSON_TYPE_VERSION: i32 = 3;

static REDIS_JSON_TYPE: RedisType = RedisType::new(
"ReJSON-RL",
Expand All @@ -38,7 +38,7 @@ static REDIS_JSON_TYPE: RedisType = RedisType::new(
digest: None,

// Auxiliary data (v2)
aux_load: None,
aux_load: Some(redisjson::type_methods::aux_load),
aux_save: None,
aux_save_triggers: rawmod::Aux::Before as i32,

Expand Down
29 changes: 27 additions & 2 deletions src/redisjson.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ use crate::backward;
use crate::error::Error;
use crate::formatter::RedisJsonFormatter;
use crate::nodevisitor::{StaticPathElement, StaticPathParser, VisitStatus};
use crate::REDIS_JSON_TYPE_VERSION;

use bson::decode_document;
use jsonpath_lib::SelectorMut;
use redis_module::raw;
use redis_module::raw::{self, Status};
use serde::Serialize;
use serde_json::{Map, Value};
use std::io::Cursor;
Expand Down Expand Up @@ -421,7 +422,7 @@ pub mod type_methods {
0 => RedisJSON {
data: backward::json_rdb_load(rdb),
},
2 => {
2 | 3 => {
let data = raw::load_string(rdb);
RedisJSON::from_str(&data, Format::JSON).unwrap()
}
Expand All @@ -443,4 +444,28 @@ pub mod type_methods {
let json = &*(value as *mut RedisJSON);
raw::save_string(rdb, &json.data.to_string());
}

Comment thread
gkorland marked this conversation as resolved.
Resolved
#[allow(non_snake_case, unused)]
pub unsafe extern "C" fn aux_load(rdb: *mut raw::RedisModuleIO, encver: i32, when: i32) -> i32 {
if (encver > REDIS_JSON_TYPE_VERSION) {
return Status::Err as i32; // could not load rdb created with higher RedisJSON version!
}

// Backward support for modules that had AUX field for RediSarch
// TODO remove in future versions
if (encver == 2 && when == raw::Aux::Before as i32) {
let map_size = raw::load_unsigned(rdb);
for _ in 0..map_size {
let index_name = raw::load_string(rdb);
let fields_size = raw::load_unsigned(rdb);
for _ in 0..fields_size {
let field_name = raw::load_string(rdb);
let path = raw::load_string(rdb);
// index::add_field(&index_name, &field_name, &path);
}
}
}

Status::Ok as i32
}
}