Skip to content
This repository was archived by the owner on Apr 20, 2020. It is now read-only.

Commit 4d8e10c

Browse files
authored
fix backward read buffer (#45)
* backward rdb load * add backward test
1 parent fe0bd8f commit 4d8e10c

File tree

5 files changed

+24
-93
lines changed

5 files changed

+24
-93
lines changed

Cargo.lock

Lines changed: 11 additions & 82 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ serde_json = "1.0"
1313
libc = "0.2"
1414
jsonpath_lib = { git="https://github.com/gkorland/jsonpath.git", branch="reaplce_with_ownership_parser" }
1515
redismodule = { git="https://github.com/redislabsmodules/redismodule-rs.git", branch="master" }
16-
redisearch_api = { git = "https://github.com/RediSearch/redisearch-api-rs.git", branch="master" }
16+
redisearch_api = { git = "https://github.com/RediSearch/redisearch-api-rs.git", branch="master" }

src/backward.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,14 @@ pub unsafe fn json_rdb_load(rdb: *mut raw::RedisModuleIO) -> Value {
3939
match node_type {
4040
NodeType::Null => Value::Null,
4141
NodeType::Boolean => {
42-
let mut str_len = 0;
43-
let str_buffer = raw::load_string_buffer(rdb, &mut str_len);
44-
Value::Bool(str_buffer.starts_with("1"))
42+
let buffer = raw::load_string_buffer(rdb);
43+
Value::Bool(buffer.as_ref()[0] == b'1')
4544
}
4645
NodeType::Integer => Value::Number(raw::load_signed(rdb).into()),
4746
NodeType::Number => Value::Number(Number::from_f64(raw::load_double(rdb)).unwrap()),
4847
NodeType::String => {
49-
let mut str_len = 0;
50-
let str_buffer = raw::load_string_buffer(rdb, &mut str_len);
51-
Value::String(str_buffer.to_string())
48+
let buffer = raw::load_string_buffer(rdb);
49+
Value::String(buffer.to_string().unwrap())
5250
}
5351
NodeType::Dict => {
5452
let len = raw::load_unsigned(rdb);
@@ -58,9 +56,8 @@ pub unsafe fn json_rdb_load(rdb: *mut raw::RedisModuleIO) -> Value {
5856
if t != NodeType::KeyVal {
5957
panic!("Can't load old RedisJSON RDB");
6058
}
61-
let mut str_len = 0;
62-
let name = &raw::load_string_buffer(rdb, &mut str_len);
63-
m.insert(name.to_string(), json_rdb_load(rdb));
59+
let buffer = raw::load_string_buffer(rdb);
60+
m.insert(buffer.to_string().unwrap(), json_rdb_load(rdb));
6461
}
6562
Value::Object(m)
6663
}

test/files/backward.rdb

317 Bytes
Binary file not shown.

test/pytest/test.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
},
6767
}
6868

69-
rmtest.config.REDIS_MODULE = './target/debug/libredisjson.so'
69+
rmtest.config.REDIS_MODULE = os.path.abspath(os.path.join(os.getcwd(), 'target/debug/libredisjson.so'))
7070

7171
class BaseReJSONTest(BaseModuleTestCase):
7272
def getCacheInfo(self):
@@ -241,6 +241,11 @@ def testGetPartsOfValuesDocumentMultiple(self):
241241
data = json.loads(r.execute_command('JSON.GET', 'test', *docs['values'].keys()))
242242
# self.assertDictEqual(data, docs['values']) // TODO backward compatibility with JSONPATH "$.list" vs "list"
243243

244+
def testBackwardRDB(self):
245+
with self.redis(**{"dir": os.path.abspath(os.path.join(os.getcwd(), 'test/files/')), "dbfilename": 'backward.rdb'}) as r:
246+
r.client_setname(self._testMethodName)
247+
data = json.loads(r.execute_command('JSON.GET', 'complex'))
248+
self.assertDictEqual(data, {"a":{"b":[{"c":{"d":[1,'2'],"e":None}},True],"a":'a'},"b":1,"c":True,"d":None})
244249

245250
def testSetBSON(self):
246251
with self.redis() as r:

0 commit comments

Comments
 (0)