Return the merged callback dict for the given (protocol, legacy) combination. ``user_protocol`` is the value the user supplied to the client constructor (``None`` means "not specified"). ``legacy_responses`` defaults to ``True`` and selects today's RESP2-style Python shapes even
(
user_protocol: Optional[int],
legacy_responses: bool,
)
| 472 | |
| 473 | |
| 474 | def get_response_callbacks( |
| 475 | user_protocol: Optional[int], |
| 476 | legacy_responses: bool, |
| 477 | ) -> dict[str, Callable[..., Any]]: |
| 478 | """Return the merged callback dict for the given (protocol, legacy) |
| 479 | combination. |
| 480 | |
| 481 | ``user_protocol`` is the value the user supplied to the client |
| 482 | constructor (``None`` means "not specified"). ``legacy_responses`` |
| 483 | defaults to ``True`` and selects today's RESP2-style Python shapes |
| 484 | even when the wire protocol is RESP3. |
| 485 | |
| 486 | Callers wrap the returned dict in ``CaseInsensitiveDict``. |
| 487 | """ |
| 488 | callbacks: dict[str, Callable[..., Any]] = dict(_RedisCallbacks) |
| 489 | if legacy_responses: |
| 490 | if user_protocol is None: |
| 491 | callbacks.update(_RedisCallbacksRESP3toRESP2Legacy) |
| 492 | elif user_protocol in (3, "3"): |
| 493 | callbacks.update(_RedisCallbacksRESP3) |
| 494 | else: |
| 495 | callbacks.update(_RedisCallbacksRESP2) |
| 496 | else: |
| 497 | if user_protocol is None or user_protocol in (3, "3"): |
| 498 | callbacks.update(_RedisCallbacksRESP3Unified) |
| 499 | else: |
| 500 | callbacks.update(_RedisCallbacksRESP2Unified) |
| 501 | return callbacks |