-
Notifications
You must be signed in to change notification settings - Fork 332
/
Copy pathtest_resp3.py
360 lines (264 loc) · 19.1 KB
/
test_resp3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
# -*- coding: utf-8 -*-
import sys
import os
import redis
import json
from RLTest import Env
from common import *
from includes import *
from RLTest import Defaults
from functools import reduce
Defaults.decode_responses = True
class testResp3():
def __init__(self):
self.env = Env(protocol=3)
def test_resp3_set_get_json_format(self):
r = self.env
r.skipOnVersionSmaller('7.0')
r.assertTrue(r.execute_command('SET', 'test_not_JSON', 'test_not_JSON'))
# Test JSON.SET RESP3
r.assertOk(r.execute_command('JSON.SET', 'test_resp3', '$', '{"a1":{"b":{"c":true,"d":null}},"a2":{"b":{"c":2}}}'))
# Test JSON.GET RESP3
r.assertEqual(r.execute_command('JSON.GET', 'test_resp3', 'FORMAT', 'EXPAND1', '$'), [['{"a1":{"b":{"c":true,"d":null}},"a2":{"b":{"c":2}}}']])
r.assertEqual(r.execute_command('JSON.GET', 'test_resp3', 'FORMAT', 'EXPAND1', '$..b'), [['{"c":true,"d":null}', '{"c":2}']])
r.assertEqual(r.execute_command('JSON.GET', 'test_resp3', 'FORMAT', 'EXPAND1', '$.a1', '$.a2'), [['{"b":{"c":true,"d":null}}'], ['{"b":{"c":2}}']])
r.assertEqual(r.execute_command('JSON.GET', 'test_resp3', 'FORMAT', 'EXPAND1', '$.a1', '$.a3', '$.a2'), [['{"b":{"c":true,"d":null}}'], [], ['{"b":{"c":2}}']])
r.assertEqual(r.execute_command('JSON.GET', 'test_resp3', 'FORMAT', 'EXPAND1', '$.a3'), [[]])
# TEST JSON.GET with none existent key
r.assertEqual(r.execute_command('JSON.GET', 'test_no_such_key', '$.a3'), None)
# TEST JSON.GET with not a JSON key
r.expect('JSON.GET', 'test_not_JSON', '$.a3').raiseError()
# Test wrong FORMAT
r.expect('JSON.GET', 'test_resp3', 'FORMAT', 'JSON', '.a[1]').raiseError().contains("wrong reply format")
r.expect('JSON.GET', 'test_resp3', 'FORMAT', 'JSON', '$.a[1]').raiseError().contains("wrong reply format")
# Currently STRINGS is not supported (only STRING)
r.expect('JSON.GET', 'test_resp3', 'FORMAT', 'STRINGS', '$.a[1]').raiseError().contains("wrong reply format")
r.expect('JSON.GET', 'test_resp3', 'FORMAT', 'STRINGS', '$a[1]').raiseError().contains("wrong reply format")
def test_resp3_set_get_expand_format(self):
r = self.env
r.skipOnVersionSmaller('7.0')
r.assertTrue(r.execute_command('SET', 'test_not_JSON', 'test_not_JSON'))
# Test JSON.SET RESP3
json_doc = {"a1":{"b":{"c":True,"d":None}},"a2":{"b":{"c":2, "e":[1,True, {"f":None}]}}}
r.assertOk(r.execute_command('JSON.SET', 'test_resp3', '$', json.dumps(json_doc)))
# Test JSON.GET RESP3
r.assertEqual(r.execute_command('JSON.GET', 'test_resp3', 'FORMAT', 'EXPAND', '$'), [[{'a1': {'b': {'c': True, 'd': None}}, 'a2': {'b': {'e': [1, True, {'f': None}], 'c': 2}}}]])
r.assertEqual(r.execute_command('JSON.GET', 'test_resp3', 'FORMAT', 'EXPAND','$..b'), [[{'d': None, 'c': True}, {'c': 2, 'e': [1, True, {'f': None}]}]])
r.assertEqual(r.execute_command('JSON.GET', 'test_resp3', 'FORMAT', 'EXPAND','$.a1', '$.a2'), [[{'b': {'d': None, 'c': True}}], [{'b': {'e': [1, True, {'f': None}], 'c': 2}}]])
r.assertEqual(r.execute_command('JSON.GET', 'test_resp3', 'FORMAT', 'EXPAND','$.a1', '$.a3', '$.a2'), [[{'b': {'c': True, 'd': None}}], [], [{'b': {'c': 2, 'e': [1, True, {'f': None}]}}]])
r.assertEqual(r.execute_command('JSON.GET', 'test_resp3', 'FORMAT', 'EXPAND','$.a3'), [[]])
# Test JSON.GET RESP3 with default format (STRING)
r.assertEqual(json.loads(r.execute_command('JSON.GET', 'test_resp3', '$')),
[json_doc])
r.assertEqual(json.loads(r.execute_command('JSON.GET', 'test_resp3','$..b')),
[{'c': True, 'd': None}, {'c': 2, 'e': [1, True, {'f': None}]}])
r.assertEqual(json.loads(r.execute_command('JSON.GET', 'test_resp3','$.a1', '$.a2')),
{'$.a1': [{'b': {'c': True, 'd': None}}], '$.a2': [{'b': {'c': 2, 'e': [1, True, {'f': None}]}}]})
r.assertEqual(json.loads(r.execute_command('JSON.GET', 'test_resp3','$.a1', '$.a3', '$.a2')),
{'$.a1': [{'b': {'c': True, 'd': None}}], '$.a3': [], '$.a2': [{'b': {'c': 2, 'e': [1, True, {'f': None}]}}]})
r.assertEqual(json.loads(r.execute_command('JSON.GET', 'test_resp3','$.a3')),
[])
# TEST JSON.GET with none existent key
r.assertEqual(r.execute_command('JSON.GET', 'test_no_such_key', 'FORMAT', 'EXPAND','$.a3'), None)
# TEST JSON.GET with not a JSON key
r.expect('JSON.GET', 'test_not_JSON', 'FORMAT', 'EXPAND','$.a3').raiseError()
def test_resp3_set_get_string_format(self):
r = self.env
r.skipOnVersionSmaller('7.0')
r.assertTrue(r.execute_command('SET', 'test_not_JSON', 'test_not_JSON'))
# Test JSON.SET RESP3
r.assertOk(r.execute_command('JSON.SET', 'test_resp3', '$', '{"a1":{"b":{"c":true,"d":null}},"a2":{"b":{"c":2}}}'))
# Test JSON.GET RESP3
r.assertEqual(r.execute_command('JSON.GET', 'test_resp3', 'FORMAT', 'STRING', '$'), '[{"a1":{"b":{"c":true,"d":null}},"a2":{"b":{"c":2}}}]')
r.assertEqual(r.execute_command('JSON.GET', 'test_resp3', 'FORMAT', 'STRING', '$..b'), '[{"c":true,"d":null},{"c":2}]')
r.assertEqual(json.loads(r.execute_command('JSON.GET', 'test_resp3', 'FORMAT', 'STRING', '$.a1', '$.a2')), {"$.a2":[{"b":{"c":2}}],"$.a1":[{"b":{"c":True,"d":None}}]})
r.assertEqual(json.loads(r.execute_command('JSON.GET', 'test_resp3', 'FORMAT', 'STRING', '.a1', '$.a2')), {"$.a2":[{"b":{"c":2}}],".a1":[{"b":{"c":True,"d":None}}]})
r.assertEqual(json.loads(r.execute_command('JSON.GET', 'test_resp3', 'FORMAT', 'STRING', '$.a1', '$.a3', '$.a2')), {"$.a3":[],"$.a2":[{"b":{"c":2}}],"$.a1":[{"b":{"c":True,"d":None}}]})
r.assertEqual(r.execute_command('JSON.GET', 'test_resp3', 'FORMAT', 'STRING', '$.a3'), '[]')
# TEST JSON.GET with none existent key
r.assertEqual(r.execute_command('JSON.GET', 'test_no_such_key', '$.a3'), None)
# TEST JSON.GET with not a JSON key
r.expect('JSON.GET', 'test_not_JSON', '$.a3').raiseError()
# Test JSON.DEL RESP3
def test_resp_json_del(self):
r = self.env
r.skipOnVersionSmaller('7.0')
r.assertTrue(r.execute_command('SET', 'test_not_JSON', 'test_not_JSON'))
r.assertOk(r.execute_command('JSON.SET', 'test_resp3', '$', '{"a1":{"b":{"c":1}},"a2":{"b":{"c":2}}}'))
r.assertEqual(r.execute_command('JSON.DEL', 'test_resp3', '$..b'), 2)
# Test none existing path
r.assertEqual(r.execute_command('JSON.DEL', 'test_resp3', '$.a1.b'), 0)
# Test none existing key
r.assertEqual(r.execute_command('JSON.DEL', 'test_no_such_key', '$.a1.b'), 0)
# Test not a JSON key
r.expect('JSON.DEL', 'test_not_JSON', '$.a1.b').raiseError()
# Test JSON.NUMINCRBY RESP3
def test_resp_json_num_ops(self):
r = self.env
r.skipOnVersionSmaller('7.0')
r.assertTrue(r.execute_command('SET', 'test_not_JSON', 'test_not_JSON'))
r.assertOk(r.execute_command('JSON.SET', 'test_resp3', '$', '{"a1":{"b":{"c":1}},"a2":{"b":{"c":2.2}},"a3":{"b":{"c":"val"}}}'))
# Test NUMINCRBY
r.assertEqual(r.execute_command('JSON.NUMINCRBY', 'test_resp3', '$.a1.b.c', 1), [2])
r.assertEqual(r.execute_command('JSON.NUMINCRBY', 'test_resp3', '$..c', 2), [4, 4.2, None])
# Test NUMMULTBY
r.assertEqual(r.execute_command('JSON.NUMMULTBY', 'test_resp3', '$.a2.b.c', 2.3), [9.66])
r.assertEqual(r.execute_command('JSON.NUMMULTBY', 'test_resp3', '$..c', 2), [8, 19.32, None])
# Test none existing key
r.expect('JSON.NUMINCRBY', 'test_no_such_key', '$.a1.b', '1').raiseError()
# Test not a JSON key
r.expect('JSON.NUMMULTBY', 'test_not_JSON', '$.a1.b', '1').raiseError()
# Test JSON.MSET RESP3
def test_resp_json_mset(self):
r = self.env
r.skipOnVersionSmaller('7.0')
r.assertTrue(r.execute_command('SET', 'test_not_JSON', 'test_not_JSON'))
r.assertOk(r.execute_command('JSON.MSET', 'test_resp3_1{s}', '$', '{"a1":{"b":{"c":1}},"a2":{"b":{"c":2}}}', 'test_resp3_2{s}', '$', '{"a1":{"b":{"c":1}},"a2":{"b":{"c":2}}}'))
# Test none existing key
r.expect('JSON.MSET', 'test_no_such_key', '$.a1.b', '1').raiseError()
# Test not a JSON key
r.expect('JSON.MSET', 'test_not_JSON', '$.a1.b', '1').raiseError()
# Test JSON.MERGE RESP3
def test_resp_json_merge(self):
r = self.env
r.skipOnVersionSmaller('7.0')
r.assertTrue(r.execute_command('SET', 'test_not_JSON', 'test_not_JSON'))
r.assertOk(r.execute_command('JSON.SET', 'test_resp3', '$', '{"a1":{"b":{"c":1}},"a2":{"b":{"c":2}}}'))
r.assertOk(r.execute_command('JSON.MERGE', 'test_resp3', '$', '{"a3":4}'))
# Test none existing key
r.expect('JSON.MERGE', 'test_no_such_key', 'test_resp3_1', '$', '{"a3":4}').raiseError()
# Test not a JSON key
r.expect('JSON.MERGE', 'test_not_JSON', '$', '{"a3":4}').raiseError()
# Test JSON.TYPE RESP3
def test_resp_json_type(self):
r = self.env
r.skipOnVersionSmaller('7.0')
r.assertTrue(r.execute_command('SET', 'test_not_JSON', 'test_not_JSON'))
r.assertOk(r.execute_command('JSON.SET', 'test_resp3', '$', '{"a1":{"b":{"c":1}},"a2":{"b":{"c":true}}, "a4":[1.2,2,3.32], "c":null}'))
# Test JSON.TYPE RESP3
r.assertEqual(r.execute_command('JSON.TYPE', 'test_resp3', '$.a1.b.c'), [['integer']])
r.assertEqual(r.execute_command('JSON.TYPE', 'test_resp3', '$..b'), [['object', 'object']])
r.assertEqual(r.execute_command('JSON.TYPE', 'test_resp3', '$'), [['object']])
r.assertEqual(r.execute_command('JSON.TYPE', 'test_resp3', '$.a3'), [[]])
r.assertEqual(r.execute_command('JSON.TYPE', 'test_resp3', '$.a4'), [['array']])
r.assertEqual(r.execute_command('JSON.TYPE', 'test_resp3', '$.a4[*]'), [['number', 'integer', 'number']])
r.assertEqual(r.execute_command('JSON.TYPE', 'test_resp3', '$..c'), [['null', 'integer', 'boolean']])
# Test none existing key
r.assertEqual(r.execute_command('JSON.TYPE', 'test_no_such_key', '$.a1.b.c'), [None])
# Test not a JSON key
r.expect('JSON.TYPE', 'test_not_JSON', '$.a1.b.c').raiseError()
# Test JSON.ARRPOP RESP3 (Default FORMAT STRING)
def test_resp_json_arrpop(self):
r = self.env
r.skipOnVersionSmaller('7.0')
r.assertTrue(r.execute_command('JSON.SET', 'test_resp3', '$', '{"a":[{"b":2},{"g":[1,2]},3]}'))
# Test JSON.ARRPOP DEFAULT FORMAT (STRINGS)
r.assertEqual(list(map(lambda x:json.loads(x), r.execute_command('JSON.ARRPOP', 'test_resp3', '$.a', 1))), [{'g':[1,2]}])
r.assertEqual(list(map(lambda x:json.loads(x), r.execute_command('JSON.ARRPOP', 'test_resp3', '$.a'))), [3])
r.assertEqual(list(map(lambda x:json.loads(x), r.execute_command('JSON.ARRPOP', 'test_resp3', '$.a', 0))), [{'b': 2}])
# Test JSON.ARRPOP FORMAT STRINGS
r.assertTrue(r.execute_command('JSON.SET', 'test_resp3', '$', '{"a":[{"b":2},{"g":[1,2]},3]}'))
r.assertEqual(list(map(lambda x:json.loads(x), r.execute_command('JSON.ARRPOP', 'test_resp3', 'FORMAT', 'STRINGS', '$.a', 1))), [{'g':[1,2]}])
r.assertEqual(list(map(lambda x:json.loads(x), r.execute_command('JSON.ARRPOP', 'test_resp3', 'FORMAT', 'STRINGS', '$.a'))), [3])
r.assertEqual(list(map(lambda x:json.loads(x), r.execute_command('JSON.ARRPOP', 'test_resp3', 'FORMAT', 'STRINGS', '$.a', 0))), [{'b': 2}])
# Test not a JSON key
r.assertTrue(r.execute_command('SET', 'test_not_JSON', 'test_not_JSON'))
r.expect('JSON.ARRPOP', 'test_not_JSON', '$.a1').raiseError()
# Test FORMAT is set with at least one key
r.expect('JSON.ARRPOP', 'FORMAT', 'EXPAND', '$.a1').raiseError()
# Test wrong FORMAT
r.expect('JSON.ARRPOP', 'test_resp3', 'FORMAT', 'JSON', '.a[1]').raiseError().contains("wrong reply format")
r.expect('JSON.ARRPOP', 'test_resp3', 'FORMAT', 'JSON', '$.a[1]').raiseError().contains("wrong reply format")
r.expect('JSON.ARRPOP', 'test_resp3', 'FORMAT', 'STRING', '$.a[1]').raiseError().contains("wrong reply format")
r.expect('JSON.ARRPOP', 'test_resp3', 'FORMAT', 'STRING', '$a[1]').raiseError().contains("wrong reply format")
# Test JSON.ARRPOP RESP3 with FORMAT EXPAND
def test_resp_json_arrpop_format_expand(self):
r = self.env
r.skipOnVersionSmaller('7.0')
r.assertTrue(r.execute_command('JSON.SET', 'test_resp3', '$', '{"a":[{"b":2},{"g":[1,2]},3]}'))
# Test JSON.TYPE RESP3
r.assertEqual(r.execute_command('JSON.ARRPOP', 'test_resp3', 'FORMAT', 'EXPAND', '$.a', 1), [{'g':[1,2]}])
r.assertEqual(r.execute_command('JSON.ARRPOP', 'test_resp3', 'FORMAT', 'EXPAND', '$.a'), [3])
r.assertEqual(r.execute_command('JSON.ARRPOP', 'test_resp3', 'FORMAT', 'EXPAND', '$.a', 0), [{'b': 2}])
# Test FORMAT EXPAND with legacy path
r.expect('JSON.ARRPOP', 'test_resp3', 'FORMAT', 'EXPAND', '.a[1]').raiseError()
# Test not a JSON key
r.assertTrue(r.execute_command('SET', 'test_not_JSON', 'test_not_JSON'))
r.expect('JSON.ARRPOP', 'test_not_JSON', 'FORMAT', 'EXPAND', '$.a1').raiseError()
# Test JSON.ARRPOP RESP3 with FORMAT EXPAND1
def test_resp_json_arrpop_format_expand1(self):
r = self.env
r.skipOnVersionSmaller('7.0')
r.assertTrue(r.execute_command('JSON.SET', 'test_resp3', '$', '{"a":[{"b":2},{"g":[1,2]},3]}'))
# Test JSON.TYPE RESP3
r.assertEqual(r.execute_command('JSON.ARRPOP', 'test_resp3', 'FORMAT', 'EXPAND1', '$.a', 1), ['{"g":[1,2]}'])
r.assertEqual(r.execute_command('JSON.ARRPOP', 'test_resp3', 'FORMAT', 'EXPAND1', '$.a'), [3])
r.assertEqual(r.execute_command('JSON.ARRPOP', 'test_resp3', 'FORMAT', 'EXPAND1', '$.a', 0), ['{"b":2}'])
# Test not a JSON key
r.assertTrue(r.execute_command('SET', 'test_not_JSON', 'test_not_JSON'))
r.expect('JSON.ARRPOP', 'test_not_JSON', 'FORMAT', 'JSON', '$.a1').raiseError()
# Test JSON.ARRPOP RESP3 with FORMAT STRING
def test_resp_json_arrpop_format_strings(self):
r = self.env
r.skipOnVersionSmaller('7.0')
r.assertTrue(r.execute_command('JSON.SET', 'test_resp3', '$', '{"a":[{"b":2},{"g":[1,2]},3]}'))
# Test JSON.TYPE RESP3
r.assertEqual(r.execute_command('JSON.ARRPOP', 'test_resp3', 'FORMAT', 'STRINGS', '$.a', 1), ['{"g":[1,2]}'])
r.assertEqual(r.execute_command('JSON.ARRPOP', 'test_resp3', 'FORMAT', 'STRINGS', '$.a'), ['3'])
r.assertEqual(r.execute_command('JSON.ARRPOP', 'test_resp3', 'FORMAT', 'STRINGS', '$.a', 0), ['{"b":2}'])
# Test FORMAT JSON with legacy path
r.expect('JSON.ARRPOP', 'test_resp3', 'FORMAT', 'STRINGS', '.a[1]').raiseError()
# Test not a JSON key
r.assertTrue(r.execute_command('SET', 'test_not_JSON', 'test_not_JSON'))
r.expect('JSON.ARRPOP', 'test_not_JSON', 'FORMAT', 'STRINGS', '$.a1').raiseError()
# Test FORMAT with wrong argument
r.expect('JSON.ARRPOP', 'test_resp3', 'FORMAT', 'JSON', '.a[1]').raiseError()
# Test JSON.MGET RESP3 default format
def test_resp_json_mget(self):
r = self.env
r.skipOnVersionSmaller('7.0')
r.assertTrue(r.execute_command('JSON.SET', '{test}resp3_1', '$', '{"a":1, "b":{"f":"g"}, "c":3}'))
r.assertTrue(r.execute_command('JSON.SET', '{test}resp3_2', '$', '{"a":5, "b":[true, 3, null], "d":7}'))
# Test JSON.MGET RESP3 with default FORMAT STRING
r.assertEqual(list(map(lambda x:json.loads(x) if x else None, r.execute_command('JSON.MGET', '{test}resp3_1', '{test}resp3_2', '$.not'))), [[], []])
r.assertEqual(list(map(lambda x:json.loads(x) if x else None, r.execute_command('JSON.MGET', '{test}resp3_1', '{test}resp3_2', '{test}not_JSON', '$.b'))), [[{'f': 'g'}], [[True, 3, None]], None])
r.assertEqual(list(map(lambda x:json.loads(x), r.execute_command('JSON.MGET', '{test}resp3_1', '{test}resp3_2', '$'))), [[{'a': 1, 'b': {'f': 'g'}, 'c': 3}], [{'b': [True, 3, None], 'd': 7, 'a': 5}]])
r.assertEqual(list(map(lambda x:json.loads(x), r.execute_command('JSON.MGET', '{test}resp3_1', '{test}resp3_2', '$..*'))), [[1, {'f': 'g'}, 3, 'g'], [5, [True, 3, None], 7, True, 3, None]])
# Test different commands with RESP3 when default path is used
def test_resp_default_path(self):
r = self.env
r.skipOnVersionSmaller('7.0')
# 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'), 443)
r.assertEqual(r.execute_command('JSON.DEL', 'test_resp3'), 1)
# Test JSON.strX commands on object type when default path is used
string = 'test_resp3_str'
length = len(string)
r.assertTrue(r.execute_command('JSON.SET', 'test_resp3_str', '$', fr'"{string}"'))
r.assertEqual(r.execute_command('JSON.STRLEN', 'test_resp3_str'), length)
string = '_append'
length = length + len(string)
r.assertTrue(r.execute_command('JSON.STRAPPEND', 'test_resp3_str', fr'"{string}"'))
r.assertEqual(r.execute_command('JSON.STRLEN', 'test_resp3_str'), length)
# 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.executeCommand('JSON.ARRPOP', 'test_resp3_arr'), '"dud"')
r.assertEqual(r.execute_command('JSON.ARRLEN', 'test_resp3_arr'), 2)
def test_fail_with_resp2():
r = Env(protocol=2)
r.assertOk(r.execute_command('JSON.SET', 'doc', '$', '{"a":[1, 2, 3], "FORMAT": [1]}'))
# JSON.GET key [INDENT indent] [NEWLINE newline] [SPACE space] [FORMAT STRING|EXPAND] [path [path ...]]
r.expect('JSON.GET', 'doc', 'FORMAT', 'EXPAND', '$').error().contains('not supported on RESP2')
# Token beyond the first path are not considered as subcommands anymore
r.assertEqual(json.loads(r.execute_command('JSON.GET', 'doc', 'INDENT', ' ', '$.a[0]', 'FORMAT', 'EXPAND')), [1])
# JSON.ARRPOP <key> [FORMAT {STRINGS|EXPAND1|EXPAND}] [path [index]]
r.expect('JSON.ARRPOP', 'doc', 'FORMAT', 'STRINGS', '$', 0).error().contains('not supported on RESP2')
r.expect('JSON.ARRPOP', 'doc', 'FORMAT', '$', 0).error().contains('wrong reply format')
r.assertEqual(r.execute_command('JSON.ARRPOP', 'doc', 'FORMAT'), '1')