Skip to content

Commit c6bcd99

Browse files
authored
Only implement WATCH, UNWATCH on ValkeyConnection (#157)
1 parent c7ab601 commit c6bcd99

File tree

4 files changed

+27
-21
lines changed

4 files changed

+27
-21
lines changed

Sources/Valkey/Commands/ServerCommands.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2203,6 +2203,7 @@ extension ValkeyConnectionProtocol {
22032203
/// - Available: 2.8.12
22042204
/// - Complexity: O(1)
22052205
@inlinable
2206+
@discardableResult
22062207
public func role() async throws -> ROLE.Response {
22072208
try await send(command: ROLE())
22082209
}

Sources/Valkey/Commands/TransactionsCommands.swift

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -120,24 +120,4 @@ extension ValkeyConnection {
120120
_ = try await send(command: 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 send(command: 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 send(command: WATCH(keys: keys))
141-
}
142-
143123
}

Sources/Valkey/Connection/ValkeyConnection.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,30 @@ public final actor ValkeyConnection: ValkeyConnectionProtocol, Sendable {
379379
#endif
380380
}
381381

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

Sources/_ValkeyCommandsBuilder/ValkeyCommandsRender.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ func renderValkeyCommands(_ commands: [String: ValkeyCommand], fullCommandList:
120120
}
121121

122122
/// Remove subscribe functions as we implement our own versions in code
123-
let subscribeFunctions = ["SUBSCRIBE", "PSUBSCRIBE", "SSUBSCRIBE", "UNSUBSCRIBE", "PUNSUBSCRIBE", "SUNSUBSCRIBE"]
123+
/// Remove watch functions as they are only valid on a single connection
124+
let subscribeFunctions = ["SUBSCRIBE", "PSUBSCRIBE", "SSUBSCRIBE", "UNSUBSCRIBE", "PUNSUBSCRIBE", "SUNSUBSCRIBE", "UNWATCH", "WATCH"]
124125
keys.removeAll { subscribeFunctions.contains($0) }
125126

126127
// transaction commands should be added to ValkeyConnection as they require a single connection.

0 commit comments

Comments
 (0)