@@ -15,7 +15,7 @@ class MaintenanceState(enum.Enum):
1515 MOVING = "moving"
1616 MAINTENANCE = "maintenance"
1717
18-
18+
1919class EndpointType :
2020 """Constants for valid endpoint types used in CLIENT MAINT_NOTIFICATIONS command."""
2121
@@ -25,7 +25,6 @@ class EndpointType:
2525 EXTERNAL_FQDN = "external-fqdn"
2626 NONE = "none"
2727
28-
2928 @classmethod
3029 def get_valid_types (cls ):
3130 """Return a set of all valid endpoint types."""
@@ -37,7 +36,7 @@ def get_valid_types(cls):
3736 cls .NONE ,
3837 }
3938
40-
39+
4140if TYPE_CHECKING :
4241 from redis .connection import (
4342 BlockingConnectionPool ,
@@ -424,60 +423,6 @@ def _is_private_fqdn(host: str) -> bool:
424423 return False
425424
426425
427- def _get_resolved_ip_from_connection (
428- connection : "ConnectionInterface" ,
429- ) -> Optional [str ]:
430- """
431- Extract the resolved IP address from an established connection.
432-
433- First tries to get the actual IP from the socket (most accurate),
434- then falls back to DNS resolution if needed.
435-
436- Args:
437- connection: The connection object to extract the IP from
438-
439- Returns:
440- str: The resolved IP address, or None if it cannot be determined
441- """
442- import socket
443-
444- # Method 1: Try to get the actual IP from the established socket connection
445- # This is most accurate as it shows the exact IP being used
446- try :
447- sock = getattr (connection , "_sock" , None )
448- if sock is not None :
449- peer_addr = sock .getpeername ()
450- if peer_addr and len (peer_addr ) >= 1 :
451- # For TCP sockets, peer_addr is typically (host, port) tuple
452- # Return just the host part
453- return peer_addr [0 ]
454- except (AttributeError , OSError ):
455- # Socket might not be connected or getpeername() might fail
456- pass
457-
458- # Method 2: Fallback to DNS resolution of the host
459- # This is less accurate but works when socket is not available
460- try :
461- host = getattr (connection , "host" , None )
462- port = getattr (connection , "port" , 6379 )
463- if host :
464- # Use getaddrinfo to resolve the hostname to IP
465- # This mimics what the connection would do during _connect()
466- addr_info = socket .getaddrinfo (
467- host , port , socket .AF_UNSPEC , socket .SOCK_STREAM
468- )
469- if addr_info :
470- # Return the IP from the first result
471- # addr_info[0] is (family, socktype, proto, canonname, sockaddr)
472- # sockaddr[0] is the IP address
473- return addr_info [0 ][4 ][0 ]
474- except (AttributeError , OSError , socket .gaierror ):
475- # DNS resolution might fail
476- pass
477-
478- return None
479-
480-
481426class MaintenanceEventsConfig :
482427 """
483428 Configuration class for maintenance events handling behaviour. Events are received through
@@ -531,7 +476,6 @@ def __init__(
531476
532477 self .endpoint_type = endpoint_type
533478
534-
535479 def __repr__ (self ) -> str :
536480 return (
537481 f"{ self .__class__ .__name__ } ("
0 commit comments