Skip to content

Commit 22615d7

Browse files
authored
Remove option to use RESP2 protocol (#62)
1 parent 2d038fe commit 22615d7

File tree

6 files changed

+19
-37
lines changed

6 files changed

+19
-37
lines changed

Sources/Valkey/Connection/ValkeyChannelHandler.swift

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ enum ValkeyRequest: Sendable {
4949
@usableFromInline
5050
final class ValkeyChannelHandler: ChannelInboundHandler {
5151
struct Configuration {
52-
let respVersion: ValkeyClientConfiguration.RESPVersion
5352
let authentication: ValkeyClientConfiguration.Authentication?
5453
let clientName: String?
5554
}
@@ -218,23 +217,21 @@ final class ValkeyChannelHandler: ChannelInboundHandler {
218217
@usableFromInline
219218
func hello(context: ChannelHandlerContext) {
220219
// send hello with protocol, authentication and client name details
221-
if configuration.respVersion == .v3 || configuration.authentication != nil || configuration.clientName != nil {
222-
self._send(
223-
command: HELLO(
224-
arguments: .init(
225-
protover: configuration.respVersion.rawValue,
226-
auth: configuration.authentication.map { .init(username: $0.username, password: $0.password) },
227-
clientname: configuration.clientName
228-
)
220+
self._send(
221+
command: HELLO(
222+
arguments: .init(
223+
protover: 3,
224+
auth: configuration.authentication.map { .init(username: $0.username, password: $0.password) },
225+
clientname: configuration.clientName
229226
)
230-
).assumeIsolated().whenComplete { result in
231-
switch result {
232-
case .failure(let error):
233-
context.fireErrorCaught(error)
234-
context.close(promise: nil)
235-
case .success:
236-
break
237-
}
227+
)
228+
).assumeIsolated().whenComplete { result in
229+
switch result {
230+
case .failure(let error):
231+
context.fireErrorCaught(error)
232+
context.close(promise: nil)
233+
case .success:
234+
break
238235
}
239236
}
240237
}

Sources/Valkey/Connection/ValkeyConnection.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public final class ValkeyConnection: Sendable {
219219

220220
package static func setupChannelAndConnect(
221221
_ channel: any Channel,
222-
configuration: ValkeyClientConfiguration,
222+
configuration: ValkeyClientConfiguration = .init(),
223223
clientName: String? = nil,
224224
logger: Logger
225225
) async throws -> ValkeyConnection {
@@ -269,7 +269,7 @@ public final class ValkeyConnection: Sendable {
269269
break
270270
}
271271
let valkeyChannelHandler = ValkeyChannelHandler(
272-
configuration: .init(respVersion: configuration.respVersion, authentication: configuration.authentication, clientName: clientName),
272+
configuration: .init(authentication: configuration.authentication, clientName: clientName),
273273
eventLoop: channel.eventLoop,
274274
logger: logger
275275
)

Sources/Valkey/ValkeyClientConfiguration.swift

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@ import NIOSSL
1616

1717
/// Configuration for the Valkey client
1818
public struct ValkeyClientConfiguration: Sendable {
19-
public struct RESPVersion: Sendable, Equatable {
20-
let rawValue: Int
21-
22-
public static var v2: Self { .init(rawValue: 2) }
23-
public static var v3: Self { .init(rawValue: 3) }
24-
}
25-
2619
public struct TLS: Sendable {
2720
enum Base {
2821
case disable
@@ -47,24 +40,19 @@ public struct ValkeyClientConfiguration: Sendable {
4740
}
4841
}
4942

50-
/// Version of RESP protocol
51-
public var respVersion: RESPVersion
5243
/// authentication details
5344
public var authentication: Authentication?
5445
/// TLS setup
5546
public var tls: TLS
5647

5748
/// Initialize ValkeyClientConfiguration
5849
/// - Parameters
59-
/// - respVersion: RESP protocol version to use
6050
/// - authentication: Authentication details
6151
/// - tlsConfiguration: TLS configuration
6252
public init(
63-
respVersion: RESPVersion = .v3,
6453
authentication: Authentication? = nil,
6554
tls: TLS = .disable
6655
) {
67-
self.respVersion = respVersion
6856
self.authentication = authentication
6957
self.tls = tls
7058
}

Tests/IntegrationTests/ValkeyTests.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,6 @@ struct GeneratedCommands {
502502
group.addTask {
503503
try await ValkeyClient(
504504
.hostname(valkeyHostname, port: 6379),
505-
configuration: .init(respVersion: .v3),
506505
logger: logger
507506
).withConnection(logger: logger) { connection in
508507
try await connection.subscribe(to: "testSubscriptions") { subscription in

Tests/ValkeyTests/Utils/NIOAsyncTestingChannel+hello.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ import Testing
1919
@testable import Valkey
2020

2121
extension NIOAsyncTestingChannel {
22-
func processHello(version: ValkeyClientConfiguration.RESPVersion = .v3) async throws {
22+
func processHello() async throws {
2323
let hello = try await self.waitForOutboundWrite(as: ByteBuffer.self)
24-
#expect(hello == RESPToken(.array([.bulkString("HELLO"), .bulkString("\(version.rawValue)")])).base)
24+
#expect(hello == RESPToken(.array([.bulkString("HELLO"), .bulkString("3")])).base)
2525
try await self.writeInbound(
2626
RESPToken(
2727
.map([

Tests/ValkeyTests/ValkeyConnectionTests.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ struct ConnectionTests {
7070
_ = try await ValkeyConnection.setupChannelAndConnect(
7171
channel,
7272
configuration: .init(
73-
respVersion: .v3,
7473
authentication: .init(username: "john", password: "smith")
7574
),
7675
logger: logger
@@ -86,13 +85,12 @@ struct ConnectionTests {
8685
let logger = Logger(label: "test")
8786
_ = try await ValkeyConnection.setupChannelAndConnect(
8887
channel,
89-
configuration: .init(respVersion: .v2),
9088
clientName: "Testing",
9189
logger: logger
9290
)
9391

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

9896
@Test

0 commit comments

Comments
 (0)