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

Function test_arrlen_dollar

tests/test_json.py:795–840  ·  view source on GitHub ↗
(client)

Source from the content-addressed store, hash-verified

793
794@pytest.mark.redismod
795def test_arrlen_dollar(client):
796 client.json().set(
797 "doc1",
798 "$",
799 {
800 "a": ["foo"],
801 "nested1": {"a": ["hello", None, "world"]},
802 "nested2": {"a": 31},
803 },
804 )
805
806 # Test multi
807 assert client.json().arrlen("doc1", "$..a") == [1, 3, None]
808 assert client.json().arrappend("doc1", "$..a", "non", "abba", "stanza") == [
809 4,
810 6,
811 None,
812 ]
813
814 client.json().clear("doc1", "$.a")
815 assert client.json().arrlen("doc1", "$..a") == [0, 6, None]
816 # Test single
817 assert client.json().arrlen("doc1", "$.nested1.a") == [6]
818
819 # Test missing key
820 with pytest.raises(exceptions.ResponseError):
821 client.json().arrappend("non_existing_doc", "$..a")
822
823 client.json().set(
824 "doc1",
825 "$",
826 {
827 "a": ["foo"],
828 "nested1": {"a": ["hello", None, "world"]},
829 "nested2": {"a": 31},
830 },
831 )
832 # Test multi (return result of last path)
833 assert client.json().arrlen("doc1", "$..a") == [1, 3, None]
834 assert client.json().arrappend("doc1", "..a", "non", "abba", "stanza") == 6
835
836 # Test single
837 assert client.json().arrlen("doc1", ".nested1.a") == 6
838
839 # Test missing key
840 assert client.json().arrlen("non_existing_doc", "..a") is None
841
842
843@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