Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 14 additions & 17 deletions Sources/Valkey/Connection/ValkeyChannelHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ enum ValkeyRequest: Sendable {
@usableFromInline
final class ValkeyChannelHandler: ChannelInboundHandler {
struct Configuration {
let respVersion: ValkeyClientConfiguration.RESPVersion
let authentication: ValkeyClientConfiguration.Authentication?
let clientName: String?
}
Expand Down Expand Up @@ -218,23 +217,21 @@ final class ValkeyChannelHandler: ChannelInboundHandler {
@usableFromInline
func hello(context: ChannelHandlerContext) {
// send hello with protocol, authentication and client name details
if configuration.respVersion == .v3 || configuration.authentication != nil || configuration.clientName != nil {
self._send(
command: HELLO(
arguments: .init(
protover: configuration.respVersion.rawValue,
auth: configuration.authentication.map { .init(username: $0.username, password: $0.password) },
clientname: configuration.clientName
)
self._send(
command: HELLO(
arguments: .init(
protover: 3,
auth: configuration.authentication.map { .init(username: $0.username, password: $0.password) },
clientname: configuration.clientName
)
).assumeIsolated().whenComplete { result in
switch result {
case .failure(let error):
context.fireErrorCaught(error)
context.close(promise: nil)
case .success:
break
}
)
).assumeIsolated().whenComplete { result in
switch result {
case .failure(let error):
context.fireErrorCaught(error)
context.close(promise: nil)
case .success:
break
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Valkey/Connection/ValkeyConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public final class ValkeyConnection: Sendable {

package static func setupChannelAndConnect(
_ channel: any Channel,
configuration: ValkeyClientConfiguration,
configuration: ValkeyClientConfiguration = .init(),
clientName: String? = nil,
logger: Logger
) async throws -> ValkeyConnection {
Expand Down Expand Up @@ -269,7 +269,7 @@ public final class ValkeyConnection: Sendable {
break
}
let valkeyChannelHandler = ValkeyChannelHandler(
configuration: .init(respVersion: configuration.respVersion, authentication: configuration.authentication, clientName: clientName),
configuration: .init(authentication: configuration.authentication, clientName: clientName),
eventLoop: channel.eventLoop,
logger: logger
)
Expand Down
12 changes: 0 additions & 12 deletions Sources/Valkey/ValkeyClientConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@ import NIOSSL

/// Configuration for the Valkey client
public struct ValkeyClientConfiguration: Sendable {
public struct RESPVersion: Sendable, Equatable {
let rawValue: Int

public static var v2: Self { .init(rawValue: 2) }
public static var v3: Self { .init(rawValue: 3) }
}

public struct TLS: Sendable {
enum Base {
case disable
Expand All @@ -47,24 +40,19 @@ public struct ValkeyClientConfiguration: Sendable {
}
}

/// Version of RESP protocol
public var respVersion: RESPVersion
/// authentication details
public var authentication: Authentication?
/// TLS setup
public var tls: TLS

/// Initialize ValkeyClientConfiguration
/// - Parameters
/// - respVersion: RESP protocol version to use
/// - authentication: Authentication details
/// - tlsConfiguration: TLS configuration
public init(
respVersion: RESPVersion = .v3,
authentication: Authentication? = nil,
tls: TLS = .disable
) {
self.respVersion = respVersion
self.authentication = authentication
self.tls = tls
}
Expand Down
1 change: 0 additions & 1 deletion Tests/IntegrationTests/ValkeyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,6 @@ struct GeneratedCommands {
group.addTask {
try await ValkeyClient(
.hostname(valkeyHostname, port: 6379),
configuration: .init(respVersion: .v3),
logger: logger
).withConnection(logger: logger) { connection in
try await connection.subscribe(to: "testSubscriptions") { subscription in
Expand Down
4 changes: 2 additions & 2 deletions Tests/ValkeyTests/Utils/NIOAsyncTestingChannel+hello.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import Testing
@testable import Valkey

extension NIOAsyncTestingChannel {
func processHello(version: ValkeyClientConfiguration.RESPVersion = .v3) async throws {
func processHello() async throws {
let hello = try await self.waitForOutboundWrite(as: ByteBuffer.self)
#expect(hello == RESPToken(.array([.bulkString("HELLO"), .bulkString("\(version.rawValue)")])).base)
#expect(hello == RESPToken(.array([.bulkString("HELLO"), .bulkString("3")])).base)
try await self.writeInbound(
RESPToken(
.map([
Expand Down
4 changes: 1 addition & 3 deletions Tests/ValkeyTests/ValkeyConnectionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ struct ConnectionTests {
_ = try await ValkeyConnection.setupChannelAndConnect(
channel,
configuration: .init(
respVersion: .v3,
authentication: .init(username: "john", password: "smith")
),
logger: logger
Expand All @@ -86,13 +85,12 @@ struct ConnectionTests {
let logger = Logger(label: "test")
_ = try await ValkeyConnection.setupChannelAndConnect(
channel,
configuration: .init(respVersion: .v2),
clientName: "Testing",
logger: logger
)

let outbound = try await channel.waitForOutboundWrite(as: ByteBuffer.self)
#expect(outbound == RESPToken(.command(["HELLO", "2", "SETNAME", "Testing"])).base)
#expect(outbound == RESPToken(.command(["HELLO", "3", "SETNAME", "Testing"])).base)
}

@Test
Expand Down