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

Function test_objkeys_dollar

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

Source from the content-addressed store, hash-verified

937
938@pytest.mark.redismod
939def test_objkeys_dollar(client):
940 client.json().set(
941 "doc1",
942 "$",
943 {
944 "nested1": {"a": {"foo": 10, "bar": 20}},
945 "a": ["foo"],
946 "nested2": {"a": {"baz": 50}},
947 },
948 )
949
950 # Test single
951 assert client.json().objkeys("doc1", "$.nested1.a") == [["foo", "bar"]]
952
953 # Test legacy
954 assert client.json().objkeys("doc1", ".*.a") == ["foo", "bar"]
955 # Test single
956 assert client.json().objkeys("doc1", ".nested2.a") == ["baz"]
957
958 # Test missing key
959 assert client.json().objkeys("non_existing_doc", "..a") is None
960
961 # Test non existing doc
962 with pytest.raises(exceptions.ResponseError):
963 assert client.json().objkeys("non_existing_doc", "$..a") == []
964
965 assert client.json().objkeys("doc1", "$..nowhere") == []
966
967
968@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