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

Function apply_module_callbacks

redis/commands/helpers.py:150–184  ·  view source on GitHub ↗

Return the merged module-callback dict for the given (protocol, legacy_responses) combination. Mirrors the selection used by :func:`redis._parsers.response_callbacks.get_response_callbacks` for the core callbacks: ``common`` is overlaid with the protocol-specific dict matching `

(
    user_protocol: Optional[int],
    legacy_responses: bool,
    *,
    common: Dict[str, Callable[..., Any]],
    resp2: Dict[str, Callable[..., Any]],
    resp3: Dict[str, Callable[..., Any]],
    resp2_unified: Optional[Dict[str, Callable[..., Any]]] = None,
    resp3_unified: Optional[Dict[str, Callable[..., Any]]] = None,
    resp3_to_resp2_legacy: Optional[Dict[str, Callable[..., Any]]] = None,
)

Source from the content-addressed store, hash-verified

148
149
150def apply_module_callbacks(
151 user_protocol: Optional[int],
152 legacy_responses: bool,
153 *,
154 common: Dict[str, Callable[..., Any]],
155 resp2: Dict[str, Callable[..., Any]],
156 resp3: Dict[str, Callable[..., Any]],
157 resp2_unified: Optional[Dict[str, Callable[..., Any]]] = None,
158 resp3_unified: Optional[Dict[str, Callable[..., Any]]] = None,
159 resp3_to_resp2_legacy: Optional[Dict[str, Callable[..., Any]]] = None,
160) -> Dict[str, Callable[..., Any]]:
161 """Return the merged module-callback dict for the given (protocol,
162 legacy_responses) combination.
163
164 Mirrors the selection used by
165 :func:`redis._parsers.response_callbacks.get_response_callbacks` for
166 the core callbacks: ``common`` is overlaid with the protocol-specific
167 dict matching ``user_protocol`` and ``legacy_responses``.
168 ``resp2_unified`` defaults to ``resp2``, ``resp3_unified`` to ``resp3``,
169 and ``resp3_to_resp2_legacy`` to an empty dict.
170 """
171 callbacks: Dict[str, Callable[..., Any]] = dict(common)
172 if legacy_responses:
173 if user_protocol is None:
174 callbacks.update(resp3_to_resp2_legacy or {})
175 elif user_protocol in (3, "3"):
176 callbacks.update(resp3)
177 else:
178 callbacks.update(resp2)
179 else:
180 if user_protocol is None or user_protocol in (3, "3"):
181 callbacks.update(resp3_unified if resp3_unified is not None else resp3)
182 else:
183 callbacks.update(resp2_unified if resp2_unified is not None else resp2)
184 return callbacks
185
186
187def at_most_one_value_set(iterable: Iterable[Any]):

Callers 8

__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85

Calls 1

updateMethod · 0.80

Tested by

no test coverage detected