@@ -139,6 +139,60 @@ async def get(
139139 return cast (bytes , await client .custom_command (args ))
140140
141141
142+ async def arrlen (
143+ client : TGlideClient ,
144+ key : TEncodable ,
145+ path : Optional [TEncodable ] = None ,
146+ ) -> Optional [TJsonResponse [int ]]:
147+ """
148+ Retrieves the length of the array at the specified `path` within the JSON document stored at `key`.
149+
150+ Args:
151+ client (TGlideClient): The client to execute the command.
152+ key (TEncodable): The key of the JSON document.
153+ path (Optional[TEncodable]): The path within the JSON document. Defaults to None.
154+
155+ Returns:
156+ Optional[TJsonResponse[int]]:
157+ For JSONPath (`path` starts with `$`):
158+ Returns a list of integer replies for every possible path, indicating the length of the array,
159+ or None for JSON values matching the path that are not an array.
160+ If `path` doesn't exist, an empty array will be returned.
161+ For legacy path (`path` doesn't starts with `$`):
162+ Returns the length of the array at `path`.
163+ If multiple paths match, the length of the first array match is returned.
164+ If the JSON value at `path` is not a array or if `path` doesn't exist, an error is raised.
165+ If `key` doesn't exist, None is returned.
166+
167+ Examples:
168+ >>> from glide import json
169+ >>> await json.set(client, "doc", "$", '{"a": [1, 2, 3], "b": {"a": [1, 2], "c": {"a": 42}}}')
170+ b'OK' # JSON is successfully set for doc
171+ >>> await json.arrlen(client, "doc", "$")
172+ [None] # No array at the root path.
173+ >>> await json.arrlen(client, "doc", "$.a")
174+ [3] # Retrieves the length of the array at path $.a.
175+ >>> await json.arrlen(client, "doc", "$..a")
176+ [3, 2, None] # Retrieves lengths of arrays found at all levels of the path `..a`.
177+ >>> await json.arrlen(client, "doc", "..a")
178+ 3 # Legacy path retrieves the first array match at path `..a`.
179+ >>> await json.arrlen(client, "non_existing_key", "$.a")
180+ None # Returns None because the key does not exist.
181+
182+ >>> await json.set(client, "doc", "$", '[1, 2, 3, 4]')
183+ b'OK' # JSON is successfully set for doc
184+ >>> await json.arrlen(client, "doc")
185+ 4 # Retrieves lengths of arrays in root.
186+ """
187+ args = ["JSON.ARRLEN" , key ]
188+ if path :
189+ args .append (path )
190+ return cast (
191+ Optional [TJsonResponse [int ]],
192+ await client .custom_command (args ),
193+ )
194+
195+
142196async def delete (
143197 client : TGlideClient ,
144198 key : TEncodable ,
0 commit comments