-
Notifications
You must be signed in to change notification settings - Fork 13
Generic node description #230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
260878e
Add associatedtype NodeDescription to ValkeyNodeConnectionPoolFactory
adam-fowler 184813a
Add separate ValkeyNodeConnectionPoolFactory for cluster and standalone
adam-fowler 3a59e06
Remove ConnectionPool typealias
adam-fowler 361ee8a
Merge branch 'main' into generic-node-description
adam-fowler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
Sources/Valkey/Cluster/ValkeyClusterNodeClientFactory.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// | ||
// This source file is part of the valkey-swift project | ||
// Copyright (c) 2025 the valkey-swift project authors | ||
// | ||
// See LICENSE.txt for license information | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
import Logging | ||
import NIOCore | ||
|
||
/// A factory for creating ``ValkeyNode`` instances to connect to specific nodes. | ||
/// | ||
/// This factory is used by the ``ValkeyClusterClient`` to create client instances | ||
/// for each node in the cluster as needed. | ||
@available(valkeySwift 1.0, *) | ||
@usableFromInline | ||
package struct ValkeyClusterNodeClientFactory: ValkeyNodeConnectionPoolFactory { | ||
var logger: Logger | ||
var configuration: ValkeyClientConfiguration | ||
var eventLoopGroup: any EventLoopGroup | ||
let connectionIDGenerator = ConnectionIDGenerator() | ||
let connectionFactory: ValkeyConnectionFactory | ||
|
||
/// Creates a new `ValkeyClusterNodeClientFactory` instance. | ||
/// | ||
/// - Parameters: | ||
/// - logger: The logger used for diagnostic information. | ||
/// - configuration: Configuration for the Valkey clients created by this factory. | ||
/// - eventLoopGroup: The event loop group to use for client connections. | ||
package init( | ||
logger: Logger, | ||
configuration: ValkeyClientConfiguration, | ||
connectionFactory: ValkeyConnectionFactory, | ||
eventLoopGroup: any EventLoopGroup | ||
) { | ||
self.logger = logger | ||
self.configuration = configuration | ||
self.connectionFactory = connectionFactory | ||
self.eventLoopGroup = eventLoopGroup | ||
} | ||
|
||
/// Creates a connection pool (client) for a specific node in the cluster. | ||
/// | ||
/// - Parameter nodeDescription: Description of the node to connect to. | ||
/// - Returns: A configured `ValkeyNode` instance ready to connect to the specified node. | ||
@usableFromInline | ||
package func makeConnectionPool(nodeDescription: ValkeyNodeDescription) -> ValkeyNodeClient { | ||
let address = ValkeyServerAddress.hostname(nodeDescription.endpoint, port: nodeDescription.port) | ||
return ValkeyNodeClient( | ||
address, | ||
connectionIDGenerator: self.connectionIDGenerator, | ||
connectionFactory: self.connectionFactory, | ||
eventLoopGroup: self.eventLoopGroup, | ||
logger: self.logger | ||
) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,9 +15,6 @@ import NIOCore | |
@available(valkeySwift 1.0, *) | ||
@usableFromInline | ||
package struct ValkeyNodeClientFactory: ValkeyNodeConnectionPoolFactory { | ||
@usableFromInline | ||
package typealias ConnectionPool = ValkeyNodeClient | ||
|
||
var logger: Logger | ||
var configuration: ValkeyClientConfiguration | ||
var eventLoopGroup: any EventLoopGroup | ||
|
@@ -47,29 +44,9 @@ package struct ValkeyNodeClientFactory: ValkeyNodeConnectionPoolFactory { | |
/// - Parameter nodeDescription: Description of the node to connect to. | ||
/// - Returns: A configured `ValkeyNode` instance ready to connect to the specified node. | ||
@usableFromInline | ||
package func makeConnectionPool(nodeDescription: ValkeyNodeDescription) -> ValkeyNodeClient { | ||
let serverAddress = ValkeyServerAddress.hostname( | ||
nodeDescription.endpoint, | ||
port: nodeDescription.port | ||
) | ||
|
||
return ValkeyNodeClient( | ||
serverAddress, | ||
connectionIDGenerator: self.connectionIDGenerator, | ||
connectionFactory: self.connectionFactory, | ||
eventLoopGroup: self.eventLoopGroup, | ||
logger: self.logger | ||
) | ||
} | ||
|
||
/// Creates a connection pool (client) for a specific node in the cluster. | ||
/// | ||
/// - Parameter nodeDescription: Description of the node to connect to. | ||
/// - Returns: A configured `ValkeyNode` instance ready to connect to the specified node. | ||
@usableFromInline | ||
package func makeConnectionPool(serverAddress: ValkeyServerAddress) -> ValkeyNodeClient { | ||
package func makeConnectionPool(nodeDescription: ValkeyServerAddress) -> ValkeyNodeClient { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you intend to return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above |
||
ValkeyNodeClient( | ||
serverAddress, | ||
nodeDescription, | ||
connectionIDGenerator: self.connectionIDGenerator, | ||
connectionFactory: self.connectionFactory, | ||
eventLoopGroup: self.eventLoopGroup, | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you intend to return
ConnectionPool
here ?package typealias ConnectionPool = ValkeyNodeClient
is defined, butConnectionPool
is not being used in the file.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This type conforms to the protocol
ValkeyNodeConnectionPoolFactory
. This protocol has an associatedtypeConnectionPool
. When you create a concrete type that conforms to a protocol with an asssociatedtype you need to indicate what the associated type is. In this caseConnectionPool
isValkeyNodeClient
.You can do this by defining the protocol requirements using that type or add a typealias. We have ended up doing both here. There is no harm in this but yeah I guess it does look a little weird.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the typealias because it isn't necessary