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

Function test_objkeys_dollar

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

Source from the content-addressed store, hash-verified

957
958@pytest.mark.redismod
959async def test_objkeys_dollar(decoded_r: redis.Redis):
960 await decoded_r.json().set(
961 "doc1",
962 "$",
963 {
964 "nested1": {"a": {"foo": 10, "bar": 20}},
965 "a": ["foo"],
966 "nested2": {"a": {"baz": 50}},
967 },
968 )
969
970 # Test single
971 assert await decoded_r.json().objkeys("doc1", "$.nested1.a") == [["foo", "bar"]]
972
973 # Test legacy
974 assert await decoded_r.json().objkeys("doc1", ".*.a") == ["foo", "bar"]
975 # Test single
976 assert await decoded_r.json().objkeys("doc1", ".nested2.a") == ["baz"]
977
978 # Test missing key
979 assert await decoded_r.json().objkeys("non_existing_doc", "..a") is None
980
981 # Test non existing doc
982 with pytest.raises(exceptions.ResponseError):
983 assert await decoded_r.json().objkeys("non_existing_doc", "$..a") == []
984
985 assert await decoded_r.json().objkeys("doc1", "$..nowhere") == []
986
987
988@pytest.mark.redismod

Callers

nothing calls this directly

Calls 3

objkeysMethod · 0.80
setMethod · 0.45
jsonMethod · 0.45

Tested by

no test coverage detected