From 80ef377f5f63caa786d3f9603dd6c8503d6012a1 Mon Sep 17 00:00:00 2001 From: Guy Korland Date: Tue, 11 Feb 2020 13:53:03 +0200 Subject: [PATCH] Support Object in ARRINDEX --- src/redisjson.rs | 2 +- test/pytest/test.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/redisjson.rs b/src/redisjson.rs index 16a63b3..27ef66a 100644 --- a/src/redisjson.rs +++ b/src/redisjson.rs @@ -256,7 +256,7 @@ impl RedisJSON { return Ok(-1); } match serde_json::from_str(scalar)? { - Value::Array(_) | Value::Object(_) => Ok(-1), + Value::Array(_) => Ok(-1), v => { let end: usize = if end == 0 || end == -1 { // default end of array diff --git a/test/pytest/test.py b/test/pytest/test.py index e54add4..afcdcae 100644 --- a/test/pytest/test.py +++ b/test/pytest/test.py @@ -469,7 +469,7 @@ def testArrIndexCommand(self): r.flushdb() self.assertOk(r.execute_command('JSON.SET', 'test', - '.', '{ "arr": [0, 1, 2, 3, 2, 1, 0] }')) + '.', '{ "arr": [0, 1, 2, 3, 2, 1, 0, {"val": 4}, {"val": 9}] }')) self.assertEqual(r.execute_command('JSON.ARRINDEX', 'test', '.arr', 0), 0) self.assertEqual(r.execute_command('JSON.ARRINDEX', 'test', '.arr', 3), 3) self.assertEqual(r.execute_command('JSON.ARRINDEX', 'test', '.arr', 4), -1) @@ -485,6 +485,7 @@ def testArrIndexCommand(self): self.assertEqual(r.execute_command('JSON.ARRINDEX', 'test', '.arr', 3), 3) self.assertEqual(r.execute_command('JSON.ARRINDEX', 'test', '.arr', 2, 3), 4) # self.assertEqual(r.execute_command('JSON.ARRINDEX', 'test', '.arr', '[4]'), -1) + self.assertEqual(r.execute_command('JSON.ARRINDEX', 'test', '.arr', "{\"val\":4}"), 7) def testArrTrimCommand(self): """Test JSON.ARRTRIM command"""