File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -353,9 +353,15 @@ public final class ValkeyClusterClient: Sendable {
353353 _ commands: Commands
354354 ) async throws -> [ Result < RESPToken , Error > ] where Commands. Element == any ValkeyCommand {
355355 let hashSlot = try self . hashSlot ( for: commands. flatMap { $0. keysAffected } )
356-
356+ let readOnlyCommand = commands. reduce ( true ) { $0 && $1. isReadOnly }
357+ let nodeSelection =
358+ if readOnlyCommand {
359+ self . clientConfiguration. readOnlyReplicaSelection. clusterNodeSelection
360+ } else {
361+ ValkeyClusterNodeSelection . primary
362+ }
357363 var clientSelector : ( ) async throws -> ValkeyNodeClient = {
358- try await self . nodeClient ( for: hashSlot. map { [ $0] } ?? [ ] )
364+ try await self . nodeClient ( for: hashSlot. map { [ $0] } ?? [ ] , nodeSelection : nodeSelection )
359365 }
360366
361367 var asking = false
Original file line number Diff line number Diff line change @@ -11,6 +11,9 @@ package enum ValkeyClusterNodeSelection: Sendable {
1111 case primary
1212 case cycleReplicas( Int )
1313
14+ /// Select node from node ids
15+ /// - Parameter nodeIDs: Primary and replica nodes
16+ /// - Returns: ID of selected node
1417 @usableFromInline
1518 func select( nodeIDs: ValkeyShardNodeIDs ) -> ValkeyNodeID {
1619 switch self {
@@ -22,7 +25,10 @@ package enum ValkeyClusterNodeSelection: Sendable {
2225 }
2326 }
2427}
28+
29+ @available ( valkeySwift 1 . 0 , * )
2530extension ValkeyClientConfiguration . ReadOnlyReplicaSelection {
31+ /// Convert from read only replica selection to node selection
2632 @usableFromInline
2733 var clusterNodeSelection : ValkeyClusterNodeSelection {
2834 switch self . value {
You can’t perform that action at this time.
0 commit comments