Skip to content

Commit

Permalink
backport 1110 to 2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
ephraimfeldblum committed Jan 30, 2024
1 parent d06c956 commit c5e2c22
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@
.settings/

wordlist.dic
config.txt
20 changes: 7 additions & 13 deletions tests/pytest/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,44 +381,38 @@ def testMgetCommand(env):
"""Test REJSON.MGET command"""
r = env

# Skip on Redis Unstable
_version = "99"
res = r.con.execute_command('INFO')
if(version.parse(res['redis_version']) >= version.parse(_version)):
env.skipOnCluster()

# Set up a few keys
for d in range(0, 5):
key = 'doc:{}'.format(d)
key = '{{doc}}:{}'.format(d)
r.cmd('DEL', key)
r.expect('JSON.SET', key, '.', json.dumps(docs['basic'])).ok()

# Test an MGET that succeeds on all keys
raw = r.execute_command('JSON.MGET', *['doc:{}'.format(d) for d in range(0, 5)] + ['.'])
raw = r.execute_command('JSON.MGET', *['{{doc}}:{}'.format(d) for d in range(0, 5)] + ['.'])
r.assertEqual(len(raw), 5)
for d in range(0, 5):
key = 'doc:{}'.format(d)
key = '{{doc}}:{}'.format(d)
r.assertEqual(json.loads(raw[d]), docs['basic'], d)

# Test an MGET that fails for one key
r.cmd('DEL', 'test')
r.assertOk(r.execute_command('JSON.SET', 'test', '.', '{"bool":false}'))
raw = r.execute_command('JSON.MGET', 'test', 'doc:0', 'foo', '.bool')
r.assertOk(r.execute_command('JSON.SET', '{doc}:test', '.', '{"bool":false}'))
raw = r.execute_command('JSON.MGET', '{doc}:test', '{doc}:0', '{doc}:foo', '.bool')
r.assertEqual(len(raw), 3)
r.assertFalse(json.loads(raw[0]))
r.assertTrue(json.loads(raw[1]))
r.assertEqual(raw[2], None)

# Test that MGET on missing path
raw = r.execute_command('JSON.MGET', 'doc:0', 'doc:1', '42isnotapath')
raw = r.execute_command('JSON.MGET', '{doc}:0', '{doc}:1', '42isnotapath')
r.assertEqual(len(raw), 2)
r.assertEqual(raw[0], None)
r.assertEqual(raw[1], None)

# Test that MGET fails on path errors
r.cmd('DEL', 'test')
r.assertOk(r.execute_command('JSON.SET', 'test', '.', '{"bull":4.2}'))
raw = r.execute_command('JSON.MGET', 'doc:0', 'test', 'doc:1', '.bool')
raw = r.execute_command('JSON.MGET', '{doc}:0', 'test', '{doc}:1', '.bool')
r.assertEqual(len(raw), 3)
r.assertTrue(json.loads(raw[0]))
r.assertEqual(raw[1], None)
Expand Down

0 comments on commit c5e2c22

Please sign in to comment.