Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/redis/_defaults.py: 36%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""Internal default helper functions shared across redis-py modules."""
3import socket
5# Connection defaults
7DEFAULT_SOCKET_TIMEOUT = 5 # 5s
8DEFAULT_SOCKET_CONNECT_TIMEOUT = DEFAULT_SOCKET_TIMEOUT
9DEFAULT_SOCKET_READ_SIZE = 32768 # 32KB
12def get_default_socket_keepalive_options() -> dict[int, int]:
13 options = {}
15 # Linux exposes TCP_KEEPIDLE; macOS exposes the equivalent TCP_KEEPALIVE.
16 # Some platforms expose neither and only support SO_KEEPALIVE itself.
17 tcp_keepidle = getattr(socket, "TCP_KEEPIDLE", None)
18 if tcp_keepidle is None:
19 tcp_keepidle = getattr(socket, "TCP_KEEPALIVE", None)
20 if tcp_keepidle is not None:
21 options[tcp_keepidle] = 30
23 # Not every platform exposes interval/probe tuning constants.
24 tcp_keepintvl = getattr(socket, "TCP_KEEPINTVL", None)
25 if tcp_keepintvl is not None:
26 options[tcp_keepintvl] = 5
28 # Not every platform exposes interval/probe tuning constants.
29 tcp_keepcnt = getattr(socket, "TCP_KEEPCNT", None)
30 if tcp_keepcnt is not None:
31 options[tcp_keepcnt] = 3
33 return options
36# Retry defaults
37DEFAULT_RETRY_COUNT = 10
38DEFAULT_RETRY_BASE = 0.01 # 10ms
39DEFAULT_RETRY_CAP = 1 # 1s