| 778 | |
| 779 | @pytest.mark.redismod |
| 780 | async def test_arrinsert_dollar(decoded_r: redis.Redis): |
| 781 | await decoded_r.json().set( |
| 782 | "doc1", |
| 783 | "$", |
| 784 | { |
| 785 | "a": ["foo"], |
| 786 | "nested1": {"a": ["hello", None, "world"]}, |
| 787 | "nested2": {"a": 31}, |
| 788 | }, |
| 789 | ) |
| 790 | # Test multi |
| 791 | res = await decoded_r.json().arrinsert("doc1", "$..a", "1", "bar", "racuda") |
| 792 | assert res == [3, 5, None] |
| 793 | |
| 794 | res = [ |
| 795 | { |
| 796 | "a": ["foo", "bar", "racuda"], |
| 797 | "nested1": {"a": ["hello", "bar", "racuda", None, "world"]}, |
| 798 | "nested2": {"a": 31}, |
| 799 | } |
| 800 | ] |
| 801 | assert await decoded_r.json().get("doc1", "$") == res |
| 802 | # Test single |
| 803 | assert await decoded_r.json().arrinsert("doc1", "$.nested1.a", -2, "baz") == [6] |
| 804 | res = [ |
| 805 | { |
| 806 | "a": ["foo", "bar", "racuda"], |
| 807 | "nested1": {"a": ["hello", "bar", "racuda", "baz", None, "world"]}, |
| 808 | "nested2": {"a": 31}, |
| 809 | } |
| 810 | ] |
| 811 | assert await decoded_r.json().get("doc1", "$") == res |
| 812 | |
| 813 | # Test missing key |
| 814 | with pytest.raises(exceptions.ResponseError): |
| 815 | await decoded_r.json().arrappend("non_existing_doc", "$..a") |
| 816 | |
| 817 | |
| 818 | @pytest.mark.redismod |