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

Function test_arrinsert_dollar

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

Source from the content-addressed store, hash-verified

778
779@pytest.mark.redismod
780async 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

Callers

nothing calls this directly

Calls 5

arrinsertMethod · 0.80
arrappendMethod · 0.80
setMethod · 0.45
jsonMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected