| 817 | |
| 818 | @pytest.mark.redismod |
| 819 | async 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 |