MCPcopy
hub / github.com/redis/redis-py / test_arrlen_dollar

Function test_arrlen_dollar

tests/test_asyncio/test_json.py:819–861  ·  view source on GitHub ↗
(decoded_r: redis.Redis)

Source from the content-addressed store, hash-verified

817
818@pytest.mark.redismod
819async def test_arrlen_dollar(decoded_r: redis.Redis):
820 await decoded_r.json().set(
821 "doc1",
822 "$",
823 {
824 "a": ["foo"],
825 "nested1": {"a": ["hello", None, "world"]},
826 "nested2": {"a": 31},
827 },
828 )
829
830 # Test multi
831 assert await decoded_r.json().arrlen("doc1", "$..a") == [1, 3, None]
832 res = await decoded_r.json().arrappend("doc1", "$..a", "non", "abba", "stanza")
833 assert res == [4, 6, None]
834
835 await decoded_r.json().clear("doc1", "$.a")
836 assert await decoded_r.json().arrlen("doc1", "$..a") == [0, 6, None]
837 # Test single
838 assert await decoded_r.json().arrlen("doc1", "$.nested1.a") == [6]
839
840 # Test missing key
841 with pytest.raises(exceptions.ResponseError):
842 await decoded_r.json().arrappend("non_existing_doc", "$..a")
843
844 await decoded_r.json().set(
845 "doc1",
846 "$",
847 {
848 "a": ["foo"],
849 "nested1": {"a": ["hello", None, "world"]},
850 "nested2": {"a": 31},
851 },
852 )
853 # Test multi (return result of last path)
854 assert await decoded_r.json().arrlen("doc1", "$..a") == [1, 3, None]
855 assert await decoded_r.json().arrappend("doc1", "..a", "non", "abba", "stanza") == 6
856
857 # Test single
858 assert await decoded_r.json().arrlen("doc1", ".nested1.a") == 6
859
860 # Test missing key
861 assert await decoded_r.json().arrlen("non_existing_doc", "..a") is None
862
863
864@pytest.mark.redismod

Callers

nothing calls this directly

Calls 5

arrlenMethod · 0.80
arrappendMethod · 0.80
setMethod · 0.45
jsonMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected