Skip to content

Commit 53b5822

Browse files
authored
Add list of commands that should only be added to ValkeyConnection (#167)
Signed-off-by: Adam Fowler <[email protected]>
1 parent 1af722d commit 53b5822

File tree

4 files changed

+212
-164
lines changed

4 files changed

+212
-164
lines changed

Sources/Valkey/Commands/ConnectionCommands.swift

Lines changed: 104 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -813,16 +813,6 @@ extension ValkeyClientProtocol {
813813
try await execute(CLIENT())
814814
}
815815

816-
/// Instructs the server whether to track the keys in the next request.
817-
///
818-
/// - Documentation: [CLIENT CACHING](https://valkey.io/commands/client-caching)
819-
/// - Available: 6.0.0
820-
/// - Complexity: O(1)
821-
@inlinable
822-
public func clientCaching(mode: CLIENT.CACHING.Mode) async throws {
823-
_ = try await execute(CLIENT.CACHING(mode: mode))
824-
}
825-
826816
/// A client claims its capability.
827817
///
828818
/// - Documentation: [CLIENT CAPA](https://valkey.io/commands/client-capa)
@@ -833,20 +823,6 @@ extension ValkeyClientProtocol {
833823
_ = try await execute(CLIENT.CAPA(capabilities: capabilities))
834824
}
835825

836-
/// Returns the name of the connection.
837-
///
838-
/// - Documentation: [CLIENT GETNAME](https://valkey.io/commands/client-getname)
839-
/// - Available: 2.6.9
840-
/// - Complexity: O(1)
841-
/// - Response: One of the following
842-
/// * [String]: The connection name of the current connection
843-
/// * [Null]: Connection name was not set
844-
@inlinable
845-
@discardableResult
846-
public func clientGetname() async throws -> ByteBuffer? {
847-
try await execute(CLIENT.GETNAME())
848-
}
849-
850826
/// Returns the client ID to which the connection's tracking notifications are redirected.
851827
///
852828
/// - Documentation: [CLIENT GETREDIR](https://valkey.io/commands/client-getredir)
@@ -874,18 +850,6 @@ extension ValkeyClientProtocol {
874850
try await execute(CLIENT.HELP())
875851
}
876852

877-
/// Returns the unique client ID of the connection.
878-
///
879-
/// - Documentation: [CLIENT ID](https://valkey.io/commands/client-id)
880-
/// - Available: 5.0.0
881-
/// - Complexity: O(1)
882-
/// - Response: [Integer]: The id of the client
883-
@inlinable
884-
@discardableResult
885-
public func clientId() async throws -> Int {
886-
try await execute(CLIENT.ID())
887-
}
888-
889853
/// Mark this client as an import source when server is in import mode.
890854
///
891855
/// - Documentation: [CLIENT IMPORT-SOURCE](https://valkey.io/commands/client-import-source)
@@ -896,18 +860,6 @@ extension ValkeyClientProtocol {
896860
_ = try await execute(CLIENT.IMPORTSOURCE(enabled: enabled))
897861
}
898862

899-
/// Returns information about the connection.
900-
///
901-
/// - Documentation: [CLIENT INFO](https://valkey.io/commands/client-info)
902-
/// - Available: 6.2.0
903-
/// - Complexity: O(1)
904-
/// - Response: [String]: A unique string, as described at the CLIENT LIST page, for the current client.
905-
@inlinable
906-
@discardableResult
907-
public func clientInfo() async throws -> ByteBuffer {
908-
try await execute(CLIENT.INFO())
909-
}
910-
911863
/// Terminates open connections.
912864
///
913865
/// - Documentation: [CLIENT KILL](https://valkey.io/commands/client-kill)
@@ -1005,58 +957,6 @@ extension ValkeyClientProtocol {
1005957
_ = try await execute(CLIENT.REPLY(action: action))
1006958
}
1007959

1008-
/// Sets information specific to the client or connection.
1009-
///
1010-
/// - Documentation: [CLIENT SETINFO](https://valkey.io/commands/client-setinfo)
1011-
/// - Available: 7.2.0
1012-
/// - Complexity: O(1)
1013-
@inlinable
1014-
public func clientSetinfo(attr: CLIENT.SETINFO.Attr) async throws {
1015-
_ = try await execute(CLIENT.SETINFO(attr: attr))
1016-
}
1017-
1018-
/// Sets the connection name.
1019-
///
1020-
/// - Documentation: [CLIENT SETNAME](https://valkey.io/commands/client-setname)
1021-
/// - Available: 2.6.9
1022-
/// - Complexity: O(1)
1023-
@inlinable
1024-
public func clientSetname<ConnectionName: RESPStringRenderable>(connectionName: ConnectionName) async throws {
1025-
_ = try await execute(CLIENT.SETNAME(connectionName: connectionName))
1026-
}
1027-
1028-
/// Controls server-assisted client-side caching for the connection.
1029-
///
1030-
/// - Documentation: [CLIENT TRACKING](https://valkey.io/commands/client-tracking)
1031-
/// - Available: 6.0.0
1032-
/// - Complexity: O(1). Some options may introduce additional complexity.
1033-
/// - Response: "OK": If the client was successfully put into or taken out of tracking mode.
1034-
@inlinable
1035-
public func clientTracking(
1036-
status: CLIENT.TRACKING.Status,
1037-
clientId: Int? = nil,
1038-
prefixes: [String] = [],
1039-
bcast: Bool = false,
1040-
optin: Bool = false,
1041-
optout: Bool = false,
1042-
noloop: Bool = false
1043-
) async throws {
1044-
_ = try await execute(
1045-
CLIENT.TRACKING(status: status, clientId: clientId, prefixes: prefixes, bcast: bcast, optin: optin, optout: optout, noloop: noloop)
1046-
)
1047-
}
1048-
1049-
/// Returns information about server-assisted client-side caching for the connection.
1050-
///
1051-
/// - Documentation: [CLIENT TRACKINGINFO](https://valkey.io/commands/client-trackinginfo)
1052-
/// - Available: 6.2.0
1053-
/// - Complexity: O(1)
1054-
@inlinable
1055-
@discardableResult
1056-
public func clientTrackinginfo() async throws -> RESPToken.Map {
1057-
try await execute(CLIENT.TRACKINGINFO())
1058-
}
1059-
1060960
/// Unblocks a client blocked by a blocking command from a different connection.
1061961
///
1062962
/// - Documentation: [CLIENT UNBLOCK](https://valkey.io/commands/client-unblock)
@@ -1154,3 +1054,107 @@ extension ValkeyClientProtocol {
11541054
}
11551055

11561056
}
1057+
1058+
@available(valkeySwift 1.0, *)
1059+
extension ValkeyConnection {
1060+
/// Instructs the server whether to track the keys in the next request.
1061+
///
1062+
/// - Documentation: [CLIENT CACHING](https://valkey.io/commands/client-caching)
1063+
/// - Available: 6.0.0
1064+
/// - Complexity: O(1)
1065+
@inlinable
1066+
public func clientCaching(mode: CLIENT.CACHING.Mode) async throws {
1067+
_ = try await execute(CLIENT.CACHING(mode: mode))
1068+
}
1069+
1070+
/// Returns the name of the connection.
1071+
///
1072+
/// - Documentation: [CLIENT GETNAME](https://valkey.io/commands/client-getname)
1073+
/// - Available: 2.6.9
1074+
/// - Complexity: O(1)
1075+
/// - Response: One of the following
1076+
/// * [String]: The connection name of the current connection
1077+
/// * [Null]: Connection name was not set
1078+
@inlinable
1079+
@discardableResult
1080+
public func clientGetname() async throws -> ByteBuffer? {
1081+
try await execute(CLIENT.GETNAME())
1082+
}
1083+
1084+
/// Returns the unique client ID of the connection.
1085+
///
1086+
/// - Documentation: [CLIENT ID](https://valkey.io/commands/client-id)
1087+
/// - Available: 5.0.0
1088+
/// - Complexity: O(1)
1089+
/// - Response: [Integer]: The id of the client
1090+
@inlinable
1091+
@discardableResult
1092+
public func clientId() async throws -> Int {
1093+
try await execute(CLIENT.ID())
1094+
}
1095+
1096+
/// Returns information about the connection.
1097+
///
1098+
/// - Documentation: [CLIENT INFO](https://valkey.io/commands/client-info)
1099+
/// - Available: 6.2.0
1100+
/// - Complexity: O(1)
1101+
/// - Response: [String]: A unique string, as described at the CLIENT LIST page, for the current client.
1102+
@inlinable
1103+
@discardableResult
1104+
public func clientInfo() async throws -> ByteBuffer {
1105+
try await execute(CLIENT.INFO())
1106+
}
1107+
1108+
/// Sets information specific to the client or connection.
1109+
///
1110+
/// - Documentation: [CLIENT SETINFO](https://valkey.io/commands/client-setinfo)
1111+
/// - Available: 7.2.0
1112+
/// - Complexity: O(1)
1113+
@inlinable
1114+
public func clientSetinfo(attr: CLIENT.SETINFO.Attr) async throws {
1115+
_ = try await execute(CLIENT.SETINFO(attr: attr))
1116+
}
1117+
1118+
/// Sets the connection name.
1119+
///
1120+
/// - Documentation: [CLIENT SETNAME](https://valkey.io/commands/client-setname)
1121+
/// - Available: 2.6.9
1122+
/// - Complexity: O(1)
1123+
@inlinable
1124+
public func clientSetname<ConnectionName: RESPStringRenderable>(connectionName: ConnectionName) async throws {
1125+
_ = try await execute(CLIENT.SETNAME(connectionName: connectionName))
1126+
}
1127+
1128+
/// Controls server-assisted client-side caching for the connection.
1129+
///
1130+
/// - Documentation: [CLIENT TRACKING](https://valkey.io/commands/client-tracking)
1131+
/// - Available: 6.0.0
1132+
/// - Complexity: O(1). Some options may introduce additional complexity.
1133+
/// - Response: "OK": If the client was successfully put into or taken out of tracking mode.
1134+
@inlinable
1135+
public func clientTracking(
1136+
status: CLIENT.TRACKING.Status,
1137+
clientId: Int? = nil,
1138+
prefixes: [String] = [],
1139+
bcast: Bool = false,
1140+
optin: Bool = false,
1141+
optout: Bool = false,
1142+
noloop: Bool = false
1143+
) async throws {
1144+
_ = try await execute(
1145+
CLIENT.TRACKING(status: status, clientId: clientId, prefixes: prefixes, bcast: bcast, optin: optin, optout: optout, noloop: noloop)
1146+
)
1147+
}
1148+
1149+
/// Returns information about server-assisted client-side caching for the connection.
1150+
///
1151+
/// - Documentation: [CLIENT TRACKINGINFO](https://valkey.io/commands/client-trackinginfo)
1152+
/// - Available: 6.2.0
1153+
/// - Complexity: O(1)
1154+
@inlinable
1155+
@discardableResult
1156+
public func clientTrackinginfo() async throws -> RESPToken.Map {
1157+
try await execute(CLIENT.TRACKINGINFO())
1158+
}
1159+
1160+
}

Sources/Valkey/Commands/TransactionsCommands.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,24 @@ extension ValkeyConnection {
120120
_ = try await execute(MULTI())
121121
}
122122

123+
/// Forgets about watched keys of a transaction.
124+
///
125+
/// - Documentation: [UNWATCH](https://valkey.io/commands/unwatch)
126+
/// - Available: 2.2.0
127+
/// - Complexity: O(1)
128+
@inlinable
129+
public func unwatch() async throws {
130+
_ = try await execute(UNWATCH())
131+
}
132+
133+
/// Monitors changes to keys to determine the execution of a transaction.
134+
///
135+
/// - Documentation: [WATCH](https://valkey.io/commands/watch)
136+
/// - Available: 2.2.0
137+
/// - Complexity: O(1) for every key.
138+
@inlinable
139+
public func watch(keys: [ValkeyKey]) async throws {
140+
_ = try await execute(WATCH(keys: keys))
141+
}
142+
123143
}

Sources/Valkey/Connection/ValkeyConnection.swift

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -381,31 +381,7 @@ public final actor ValkeyConnection: ValkeyClientProtocol, Sendable {
381381
#endif
382382
}
383383

384-
/// Add WATCH, UNWATCH commands to ValkeyConnection.
385-
@available(valkeySwift 1.0, *)
386-
extension ValkeyConnection {
387-
/// Forgets about watched keys of a transaction.
388-
///
389-
/// - Documentation: [UNWATCH](https://valkey.io/commands/unwatch)
390-
/// - Available: 2.2.0
391-
/// - Complexity: O(1)
392-
@inlinable
393-
public func unwatch() async throws {
394-
_ = try await execute(UNWATCH())
395-
}
396-
397-
/// Monitors changes to keys to determine the execution of a transaction.
398-
///
399-
/// - Documentation: [WATCH](https://valkey.io/commands/watch)
400-
/// - Available: 2.2.0
401-
/// - Complexity: O(1) for every key.
402-
@inlinable
403-
public func watch(keys: [ValkeyKey]) async throws {
404-
_ = try await execute(WATCH(keys: keys))
405-
}
406-
}
407-
408-
// Used in ValkeyConnection.execute(_:)
384+
// Used in ValkeyConnection.pipeline
409385
@usableFromInline
410386
struct AutoIncrementingInteger {
411387
@usableFromInline

0 commit comments

Comments
 (0)