From ec5c504ca9ec2b11cfa19d26357895bb481857f8 Mon Sep 17 00:00:00 2001 From: Adam Fowler Date: Thu, 25 Sep 2025 14:01:00 +0100 Subject: [PATCH] Remove hostname and ip from ValkeyNodeDescription Signed-off-by: Adam Fowler --- .../Cluster/ValkeyNodeDescription.swift | 16 ------------- .../ValkeyNodeDescriptionProtocol.swift | 14 ++--------- .../Valkey/Cluster/ValkeyNodeDiscovery.swift | 23 +++---------------- .../ClusterIntegrationTests.swift | 2 +- 4 files changed, 6 insertions(+), 49 deletions(-) diff --git a/Sources/Valkey/Cluster/ValkeyNodeDescription.swift b/Sources/Valkey/Cluster/ValkeyNodeDescription.swift index 4434ca9e..d71f4c6f 100644 --- a/Sources/Valkey/Cluster/ValkeyNodeDescription.swift +++ b/Sources/Valkey/Cluster/ValkeyNodeDescription.swift @@ -31,16 +31,6 @@ package struct ValkeyNodeDescription: Identifiable, Hashable, Sendable { ValkeyNodeID(endpoint: self.endpoint, port: self.port) } - /// The hostname of the Valkey node, if available. - /// - /// This may be `nil` if the node is only known by IP address. - package var host: String? - - /// The IP address of the Valkey node, if available. - /// - /// This may be `nil` if the node is only known by hostname. - package var ip: String? - /// The network endpoint (hostname or IP) used to connect to this node. /// /// This property is required and is used as part of the node's unique identifier. @@ -59,8 +49,6 @@ package struct ValkeyNodeDescription: Identifiable, Hashable, Sendable { /// - Parameter description: A value conforming to `ValkeyNodeDescriptionProtocol` that provides /// the necessary node information. package init(description: any ValkeyNodeDescriptionProtocol) { - self.host = description.host - self.ip = description.ip self.endpoint = description.endpoint self.port = description.port } @@ -74,8 +62,6 @@ package struct ValkeyNodeDescription: Identifiable, Hashable, Sendable { /// - Note: If both TLS and regular ports are available, the TLS port takes precedence. /// If no port is specified, the default Valkey port (6379) is used. package init(description: ValkeyClusterDescription.Node) { - self.host = description.hostname - self.ip = description.ip self.endpoint = description.endpoint self.port = description.tlsPort ?? description.port ?? 6379 } @@ -86,8 +72,6 @@ package struct ValkeyNodeDescription: Identifiable, Hashable, Sendable { /// /// - Parameter redirectionError: A `ValkeyClusterRedirectionError` instance. package init(redirectionError: ValkeyClusterRedirectionError) { - self.host = nil - self.ip = nil self.endpoint = redirectionError.endpoint self.port = redirectionError.port } diff --git a/Sources/Valkey/Cluster/ValkeyNodeDescriptionProtocol.swift b/Sources/Valkey/Cluster/ValkeyNodeDescriptionProtocol.swift index f7aad4b2..75ba4812 100644 --- a/Sources/Valkey/Cluster/ValkeyNodeDescriptionProtocol.swift +++ b/Sources/Valkey/Cluster/ValkeyNodeDescriptionProtocol.swift @@ -21,20 +21,10 @@ import NIOCore /// The protocol requires both hostname and IP address properties to be available, though either may be nil /// depending on how the node is identified. The ``endpoint`` property provides the actual connection target. public protocol ValkeyNodeDescriptionProtocol: Sendable, Equatable { - /// The node's host name, if available. - /// - /// This may be nil if the node is identified solely by IP address. - var host: String? { get } - - /// The node's IP address, if available. - /// - /// This may be nil if the node is identified solely by hostname. - var ip: String? { get } - /// The node's connection endpoint string. /// - /// This should typically be the ``host`` if the node has a routable hostname, - /// otherwise it should be the ``ip``. This property is used to establish + /// This should typically be the hostname if the node has a routable hostname, + /// otherwise it should be the ip. This property is used to establish /// network connections to the node. var endpoint: String { get } diff --git a/Sources/Valkey/Cluster/ValkeyNodeDiscovery.swift b/Sources/Valkey/Cluster/ValkeyNodeDiscovery.swift index 57d07a6e..496dd9ba 100644 --- a/Sources/Valkey/Cluster/ValkeyNodeDiscovery.swift +++ b/Sources/Valkey/Cluster/ValkeyNodeDiscovery.swift @@ -43,33 +43,16 @@ public protocol ValkeyNodeDiscovery: Sendable { public struct ValkeyStaticNodeDiscovery: ValkeyNodeDiscovery { /// A description of a single node in the Valkey cluster. public struct NodeDescription: ValkeyNodeDescriptionProtocol { - public var host: String? - public var ip: String? public var endpoint: String public var port: Int /// Initializes a `NodeDescription` with a host and optional IP. /// /// - Parameters: - /// - host: The host name of the node. - /// - ip: The optional IP address of the node. + /// - endpoint: The node endpoint. /// - port: The port number the node listens on (default is 6379). - public init(host: String, ip: String? = nil, port: Int = 6379) { - self.host = host - self.ip = ip - self.endpoint = host - self.port = port - } - - /// Initializes a `NodeDescription` with an IP address. - /// - /// - Parameters: - /// - ip: The IP address of the node. - /// - port: The port number the node listens on (default is 6379). - public init(ip: String, port: Int = 6379) { - self.host = nil - self.ip = ip - self.endpoint = ip + public init(endpoint: String, port: Int = 6379) { + self.endpoint = endpoint self.port = port } } diff --git a/Tests/ClusterIntegrationTests/ClusterIntegrationTests.swift b/Tests/ClusterIntegrationTests/ClusterIntegrationTests.swift index d88b3902..8516b5df 100644 --- a/Tests/ClusterIntegrationTests/ClusterIntegrationTests.swift +++ b/Tests/ClusterIntegrationTests/ClusterIntegrationTests.swift @@ -470,7 +470,7 @@ struct ClusterIntegrationTests { ) async throws -> T { let client = ValkeyClusterClient( clientConfiguration: nodeClientConfiguration, - nodeDiscovery: ValkeyStaticNodeDiscovery(nodeAddresses.map { .init(host: $0.host, port: $0.port) }), + nodeDiscovery: ValkeyStaticNodeDiscovery(nodeAddresses.map { .init(endpoint: $0.host, port: $0.port) }), logger: logger )