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

Support Object in ARRINDEX #81

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion src/redisjson.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion test/pytest/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why double quotes and backslash when you could simply say:

self.assertEqual(r.execute_command('JSON.ARRINDEX', 'test', '.arr', '{"val":4}'), 7)


def testArrTrimCommand(self):
"""Test JSON.ARRTRIM command"""
Expand Down