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

Method __init__

redis/commands/json/__init__.py:29–123  ·  view source on GitHub ↗

Create a client for talking to json. :param decoder: :type json.JSONDecoder: An instance of json.JSONDecoder :param encoder: :type json.JSONEncoder: An instance of json.JSONEncoder

(
        self, client, version=None, decoder=JSONDecoder(), encoder=JSONEncoder()
    )

Source from the content-addressed store, hash-verified

27 """
28
29 def __init__(
30 self, client, version=None, decoder=JSONDecoder(), encoder=JSONEncoder()
31 ):
32 """
33 Create a client for talking to json.
34
35 :param decoder:
36 :type json.JSONDecoder: An instance of json.JSONDecoder
37
38 :param encoder:
39 :type json.JSONEncoder: An instance of json.JSONEncoder
40 """
41 # Set the module commands' callbacks
42 _MODULE_CALLBACKS = {
43 "JSON.ARRPOP": self._decode,
44 "JSON.DEBUG": self._decode,
45 "JSON.GET": self._decode,
46 "JSON.MERGE": lambda r: r and nativestr(r) == "OK",
47 "JSON.MGET": bulk_of_jsons(self._decode),
48 "JSON.MSET": lambda r: r and nativestr(r) == "OK",
49 "JSON.RESP": self._decode,
50 "JSON.SET": lambda r: r and nativestr(r) == "OK",
51 "JSON.TOGGLE": self._decode,
52 }
53
54 _RESP2_MODULE_CALLBACKS = {
55 "JSON.ARRAPPEND": self._decode,
56 "JSON.ARRINDEX": self._decode,
57 "JSON.ARRINSERT": self._decode,
58 "JSON.ARRLEN": self._decode,
59 "JSON.ARRTRIM": self._decode,
60 "JSON.CLEAR": int,
61 "JSON.DEL": int,
62 "JSON.FORGET": int,
63 "JSON.GET": self._decode,
64 "JSON.NUMINCRBY": lambda r, **kwargs: self._decode(r),
65 "JSON.NUMMULTBY": lambda r, **kwargs: self._decode(r),
66 "JSON.OBJKEYS": self._decode,
67 "JSON.STRAPPEND": self._decode,
68 "JSON.OBJLEN": self._decode,
69 "JSON.STRLEN": self._decode,
70 "JSON.TOGGLE": self._decode,
71 }
72
73 _RESP3_MODULE_CALLBACKS = {}
74 # RESP2 wire normalised to the unified shape from the reverted
75 # unification PR: NUMINCRBY/NUMMULTBY are always arrays,
76 # JSON.RESP uses native floats, and missing JSON.TYPE keys stay
77 # ``None`` instead of becoming ``[None]``.
78 _RESP2_UNIFIED_MODULE_CALLBACKS = {
79 "JSON.CLEAR": int,
80 "JSON.DEL": int,
81 "JSON.FORGET": int,
82 "JSON.NUMINCRBY": self._decode_json_numop,
83 "JSON.NUMMULTBY": self._decode_json_numop,
84 "JSON.RESP": self._decode_resp_command_unified,
85 "JSON.TYPE": lambda r: [r] if r is not None else r,
86 }

Callers

nothing calls this directly

Calls 7

_decodeMethod · 0.95
nativestrFunction · 0.85
bulk_of_jsonsFunction · 0.85
apply_module_callbacksFunction · 0.85
get_protocol_versionFunction · 0.50
get_legacy_responsesFunction · 0.50
set_response_callbackMethod · 0.45

Tested by

no test coverage detected