Skip to content
Open
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
14 changes: 5 additions & 9 deletions redis_json/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use itertools::{EitherOrBoth, Itertools};
use serde::{Serialize, Serializer};

const JSON_ROOT_PATH: &str = "$";
const JSON_ROOT_PATH_LEGACY: &str = ".";
const JSON_ROOT_PATH_DOT: &str = ".";
const CMD_ARG_NOESCAPE: &str = "NOESCAPE";
const CMD_ARG_INDENT: &str = "INDENT";
const CMD_ARG_NEWLINE: &str = "NEWLINE";
Expand Down Expand Up @@ -85,13 +85,9 @@ fn is_resp3(ctx: &Context) -> bool {
.contains(redis_module::ContextFlags::FLAGS_RESP3)
}

/// Returns the deault path for the given RESP version
fn default_path(ctx: &Context) -> &str {
if is_resp3(ctx) {
JSON_ROOT_PATH
} else {
JSON_ROOT_PATH_LEGACY
}
/// Returns the default path
fn default_path(_ctx: &Context) -> &str {
JSON_ROOT_PATH_DOT
}

///
Expand Down Expand Up @@ -1422,7 +1418,7 @@ pub fn json_arr_pop<M: Manager>(manager: M, ctx: &Context, args: Vec<RedisString
(Path::new(JSON_ROOT_PATH), i64::MAX)
} else {
// Legacy behavior for backward compatibility
(Path::new(JSON_ROOT_PATH_LEGACY), i64::MAX)
(Path::new(JSON_ROOT_PATH_DOT), i64::MAX)
}
}
Some(s) => {
Expand Down
14 changes: 7 additions & 7 deletions tests/pytest/test_resp3.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,20 +321,20 @@ def test_resp_default_path(self):
# Test JSON.X commands on object type when default path is used
r.assertTrue(r.execute_command('JSON.SET', 'test_resp3', '$', '{"a":[{"b":2},{"g":[1,2]},3]}'))
r.assertEqual(r.execute_command('JSON.GET', 'test_resp3', 'FORMAT', 'EXPAND'), [[{"a":[{"b":2},{"g":[1,2]},3]}]])
r.assertEqual(json.loads(r.execute_command('JSON.GET', 'test_resp3')), [{"a":[{"b":2},{"g":[1,2]},3]}])
r.assertEqual(r.execute_command('JSON.OBJKEYS', 'test_resp3'), [['a']])
r.assertEqual(r.execute_command('JSON.OBJLEN', 'test_resp3'), [1])
r.assertEqual(r.execute_command('JSON.TYPE', 'test_resp3'), [['object']])
r.assertEqual(r.execute_command('JSON.DEBUG', 'MEMORY', 'test_resp3'), [507])
r.assertEqual(r.execute_command('JSON.GET', 'test_resp3'), '{"a":[{"b":2},{"g":[1,2]},3]}')
r.assertEqual(r.execute_command('JSON.OBJKEYS', 'test_resp3'), ['a'])
r.assertEqual(r.execute_command('JSON.OBJLEN', 'test_resp3'), 1)
r.assertEqual(r.execute_command('JSON.TYPE', 'test_resp3'), ['object'])
r.assertEqual(r.execute_command('JSON.DEBUG', 'MEMORY', 'test_resp3'), 507)
r.assertEqual(r.execute_command('JSON.DEL', 'test_resp3'), 1)

# Test JSON.strX commands on object type when default path is used
r.assertTrue(r.execute_command('JSON.SET', 'test_resp3_str', '$', '"test_resp3_str"'))
r.assertEqual(r.execute_command('JSON.STRLEN', 'test_resp3_str'), [14])
r.assertEqual(r.execute_command('JSON.STRLEN', 'test_resp3_str'), 14)

# Test JSON.arrX commands on object type when default path is used
r.assertTrue(r.execute_command('JSON.SET', 'test_resp3_arr', '$', '[true, 1, "dud"]'))
r.assertEqual(r.execute_command('JSON.ARRLEN', 'test_resp3_arr'), [3])
r.assertEqual(r.execute_command('JSON.ARRLEN', 'test_resp3_arr'), 3)

def test_fail_with_resp2():
r = Env(protocol=2)
Expand Down