Skip to content

Commit 986eb4d

Browse files
authored
Enable swift-format soundness check, run swift-format on whole project (#133)
1 parent 827c31c commit 986eb4d

29 files changed

+1081
-174
lines changed

.github/workflows/soundness.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,3 @@ jobs:
1313
docs_check_container_image: swift:latest
1414
unacceptable_language_check_enabled: false # Valkey commands contain unacceptable language
1515
license_header_check_enabled: false # Temporarily disable
16-
format_check_enabled: false # Temporarily disable

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ let package = Package(
100100

101101
if ProcessInfo.processInfo.environment["ENABLE_VALKEY_BENCHMARKS"] != nil {
102102
package.dependencies.append(
103-
.package(url: "https://github.com/ordo-one/package-benchmark", from: "1.0.0"),
103+
.package(url: "https://github.com/ordo-one/package-benchmark", from: "1.0.0")
104104
)
105105
package.targets.append(
106106
.executableTarget(

Sources/Valkey/Cluster/ValkeyClusterClient.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,6 @@ public final class ValkeyClusterClient: Sendable {
135135
self.nodeDiscovery = nodeDiscovery
136136
}
137137

138-
139-
140138
// MARK: - Public methods -
141139

142140
/// Sends a command to the appropriate node in the Valkey cluster and returns the response.

Sources/Valkey/Commands/ConnectionCommands.swift

Lines changed: 72 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,15 @@ extension CLIENT {
316316
public var skipme: Skipme?
317317
public var maxage: Int?
318318

319-
@inlinable public init(clientType: ClientType? = nil, clientId: [Int] = [], username: String? = nil, addr: String? = nil, laddr: String? = nil, skipme: Skipme? = nil, maxage: Int? = nil) {
319+
@inlinable public init(
320+
clientType: ClientType? = nil,
321+
clientId: [Int] = [],
322+
username: String? = nil,
323+
addr: String? = nil,
324+
laddr: String? = nil,
325+
skipme: Skipme? = nil,
326+
maxage: Int? = nil
327+
) {
320328
self.clientType = clientType
321329
self.clientId = clientId
322330
self.username = username
@@ -327,7 +335,17 @@ extension CLIENT {
327335
}
328336

329337
@inlinable public func encode(into commandEncoder: inout ValkeyCommandEncoder) {
330-
commandEncoder.encodeArray("CLIENT", "LIST", RESPWithToken("TYPE", clientType), RESPWithToken("ID", clientId), RESPWithToken("USER", username), RESPWithToken("ADDR", addr), RESPWithToken("LADDR", laddr), RESPWithToken("SKIPME", skipme), RESPWithToken("MAXAGE", maxage))
338+
commandEncoder.encodeArray(
339+
"CLIENT",
340+
"LIST",
341+
RESPWithToken("TYPE", clientType),
342+
RESPWithToken("ID", clientId),
343+
RESPWithToken("USER", username),
344+
RESPWithToken("ADDR", addr),
345+
RESPWithToken("LADDR", laddr),
346+
RESPWithToken("SKIPME", skipme),
347+
RESPWithToken("MAXAGE", maxage)
348+
)
331349
}
332350
}
333351

@@ -525,7 +543,15 @@ extension CLIENT {
525543
public var optout: Bool
526544
public var noloop: Bool
527545

528-
@inlinable public init(status: Status, clientId: Int? = nil, prefix: [String] = [], bcast: Bool = false, optin: Bool = false, optout: Bool = false, noloop: Bool = false) {
546+
@inlinable public init(
547+
status: Status,
548+
clientId: Int? = nil,
549+
prefix: [String] = [],
550+
bcast: Bool = false,
551+
optin: Bool = false,
552+
optout: Bool = false,
553+
noloop: Bool = false
554+
) {
529555
self.status = status
530556
self.clientId = clientId
531557
self.prefix = prefix
@@ -536,7 +562,17 @@ extension CLIENT {
536562
}
537563

538564
@inlinable public func encode(into commandEncoder: inout ValkeyCommandEncoder) {
539-
commandEncoder.encodeArray("CLIENT", "TRACKING", status, RESPWithToken("REDIRECT", clientId), RESPWithToken("PREFIX", prefix), RESPPureToken("BCAST", bcast), RESPPureToken("OPTIN", optin), RESPPureToken("OPTOUT", optout), RESPPureToken("NOLOOP", noloop))
565+
commandEncoder.encodeArray(
566+
"CLIENT",
567+
"TRACKING",
568+
status,
569+
RESPWithToken("REDIRECT", clientId),
570+
RESPWithToken("PREFIX", prefix),
571+
RESPPureToken("BCAST", bcast),
572+
RESPPureToken("OPTIN", optin),
573+
RESPPureToken("OPTOUT", optout),
574+
RESPPureToken("NOLOOP", noloop)
575+
)
540576
}
541577
}
542578

@@ -904,8 +940,26 @@ extension ValkeyConnectionProtocol {
904940
/// - Complexity: O(N) where N is the number of client connections
905941
/// - Response: [String]: Information and statistics about client connections
906942
@inlinable
907-
public func clientList(clientType: CLIENT.LIST.ClientType? = nil, clientId: [Int] = [], username: String? = nil, addr: String? = nil, laddr: String? = nil, skipme: CLIENT.LIST.Skipme? = nil, maxage: Int? = nil) async throws -> ByteBuffer {
908-
try await send(command: CLIENT.LIST(clientType: clientType, clientId: clientId, username: username, addr: addr, laddr: laddr, skipme: skipme, maxage: maxage))
943+
public func clientList(
944+
clientType: CLIENT.LIST.ClientType? = nil,
945+
clientId: [Int] = [],
946+
username: String? = nil,
947+
addr: String? = nil,
948+
laddr: String? = nil,
949+
skipme: CLIENT.LIST.Skipme? = nil,
950+
maxage: Int? = nil
951+
) async throws -> ByteBuffer {
952+
try await send(
953+
command: CLIENT.LIST(
954+
clientType: clientType,
955+
clientId: clientId,
956+
username: username,
957+
addr: addr,
958+
laddr: laddr,
959+
skipme: skipme,
960+
maxage: maxage
961+
)
962+
)
909963
}
910964

911965
/// Sets the client eviction mode of the connection.
@@ -978,8 +1032,18 @@ extension ValkeyConnectionProtocol {
9781032
/// - Complexity: O(1). Some options may introduce additional complexity.
9791033
/// - Response: "OK": If the client was successfully put into or taken out of tracking mode.
9801034
@inlinable
981-
public func clientTracking(status: CLIENT.TRACKING.Status, clientId: Int? = nil, prefix: [String] = [], bcast: Bool = false, optin: Bool = false, optout: Bool = false, noloop: Bool = false) async throws {
982-
_ = try await send(command: CLIENT.TRACKING(status: status, clientId: clientId, prefix: prefix, bcast: bcast, optin: optin, optout: optout, noloop: noloop))
1035+
public func clientTracking(
1036+
status: CLIENT.TRACKING.Status,
1037+
clientId: Int? = nil,
1038+
prefix: [String] = [],
1039+
bcast: Bool = false,
1040+
optin: Bool = false,
1041+
optout: Bool = false,
1042+
noloop: Bool = false
1043+
) async throws {
1044+
_ = try await send(
1045+
command: CLIENT.TRACKING(status: status, clientId: clientId, prefix: prefix, bcast: bcast, optin: optin, optout: optout, noloop: noloop)
1046+
)
9831047
}
9841048

9851049
/// Returns information about server-assisted client-side caching for the connection.

Sources/Valkey/Commands/GenericCommands.swift

Lines changed: 150 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,17 @@ public struct MIGRATE<Host: RESPStringRenderable>: ValkeyCommand {
397397
public var authentication: Authentication?
398398
public var keys: [ValkeyKey]
399399

400-
@inlinable public init(host: Host, port: Int, keySelector: KeySelector, destinationDb: Int, timeout: Int, copy: Bool = false, replace: Bool = false, authentication: Authentication? = nil, keys: [ValkeyKey] = []) {
400+
@inlinable public init(
401+
host: Host,
402+
port: Int,
403+
keySelector: KeySelector,
404+
destinationDb: Int,
405+
timeout: Int,
406+
copy: Bool = false,
407+
replace: Bool = false,
408+
authentication: Authentication? = nil,
409+
keys: [ValkeyKey] = []
410+
) {
401411
self.host = host
402412
self.port = port
403413
self.keySelector = keySelector
@@ -412,7 +422,18 @@ public struct MIGRATE<Host: RESPStringRenderable>: ValkeyCommand {
412422
public var keysAffected: [ValkeyKey] { keys }
413423

414424
@inlinable public func encode(into commandEncoder: inout ValkeyCommandEncoder) {
415-
commandEncoder.encodeArray("MIGRATE", RESPBulkString(host), port, keySelector, destinationDb, timeout, RESPPureToken("COPY", copy), RESPPureToken("REPLACE", replace), authentication, RESPWithToken("KEYS", keys))
425+
commandEncoder.encodeArray(
426+
"MIGRATE",
427+
RESPBulkString(host),
428+
port,
429+
keySelector,
430+
destinationDb,
431+
timeout,
432+
RESPPureToken("COPY", copy),
433+
RESPPureToken("REPLACE", replace),
434+
authentication,
435+
RESPWithToken("KEYS", keys)
436+
)
416437
}
417438
}
418439

@@ -640,7 +661,15 @@ public struct RESTORE<SerializedValue: RESPStringRenderable>: ValkeyCommand {
640661
public var seconds: Int?
641662
public var frequency: Int?
642663

643-
@inlinable public init(key: ValkeyKey, ttl: Int, serializedValue: SerializedValue, replace: Bool = false, absttl: Bool = false, seconds: Int? = nil, frequency: Int? = nil) {
664+
@inlinable public init(
665+
key: ValkeyKey,
666+
ttl: Int,
667+
serializedValue: SerializedValue,
668+
replace: Bool = false,
669+
absttl: Bool = false,
670+
seconds: Int? = nil,
671+
frequency: Int? = nil
672+
) {
644673
self.key = key
645674
self.ttl = ttl
646675
self.serializedValue = serializedValue
@@ -653,7 +682,16 @@ public struct RESTORE<SerializedValue: RESPStringRenderable>: ValkeyCommand {
653682
public var keysAffected: CollectionOfOne<ValkeyKey> { .init(key) }
654683

655684
@inlinable public func encode(into commandEncoder: inout ValkeyCommandEncoder) {
656-
commandEncoder.encodeArray("RESTORE", key, ttl, RESPBulkString(serializedValue), RESPPureToken("REPLACE", replace), RESPPureToken("ABSTTL", absttl), RESPWithToken("IDLETIME", seconds), RESPWithToken("FREQ", frequency))
685+
commandEncoder.encodeArray(
686+
"RESTORE",
687+
key,
688+
ttl,
689+
RESPBulkString(serializedValue),
690+
RESPPureToken("REPLACE", replace),
691+
RESPPureToken("ABSTTL", absttl),
692+
RESPWithToken("IDLETIME", seconds),
693+
RESPWithToken("FREQ", frequency)
694+
)
657695
}
658696
}
659697

@@ -727,7 +765,15 @@ public struct SORT: ValkeyCommand {
727765
public var sorting: Bool
728766
public var destination: ValkeyKey?
729767

730-
@inlinable public init(key: ValkeyKey, byPattern: String? = nil, limit: Limit? = nil, getPattern: [String] = [], order: Order? = nil, sorting: Bool = false, destination: ValkeyKey? = nil) {
768+
@inlinable public init(
769+
key: ValkeyKey,
770+
byPattern: String? = nil,
771+
limit: Limit? = nil,
772+
getPattern: [String] = [],
773+
order: Order? = nil,
774+
sorting: Bool = false,
775+
destination: ValkeyKey? = nil
776+
) {
731777
self.key = key
732778
self.byPattern = byPattern
733779
self.limit = limit
@@ -740,7 +786,16 @@ public struct SORT: ValkeyCommand {
740786
public var keysAffected: [ValkeyKey] { (destination.map { [$0] } ?? []) + [key] }
741787

742788
@inlinable public func encode(into commandEncoder: inout ValkeyCommandEncoder) {
743-
commandEncoder.encodeArray("SORT", key, RESPWithToken("BY", byPattern), RESPWithToken("LIMIT", limit), RESPWithToken("GET", getPattern), order, RESPPureToken("ALPHA", sorting), RESPWithToken("STORE", destination))
789+
commandEncoder.encodeArray(
790+
"SORT",
791+
key,
792+
RESPWithToken("BY", byPattern),
793+
RESPWithToken("LIMIT", limit),
794+
RESPWithToken("GET", getPattern),
795+
order,
796+
RESPPureToken("ALPHA", sorting),
797+
RESPWithToken("STORE", destination)
798+
)
744799
}
745800
}
746801

@@ -791,7 +846,14 @@ public struct SORTRO: ValkeyCommand {
791846
public var order: Order?
792847
public var sorting: Bool
793848

794-
@inlinable public init(key: ValkeyKey, byPattern: String? = nil, limit: Limit? = nil, getPattern: [String] = [], order: Order? = nil, sorting: Bool = false) {
849+
@inlinable public init(
850+
key: ValkeyKey,
851+
byPattern: String? = nil,
852+
limit: Limit? = nil,
853+
getPattern: [String] = [],
854+
order: Order? = nil,
855+
sorting: Bool = false
856+
) {
795857
self.key = key
796858
self.byPattern = byPattern
797859
self.limit = limit
@@ -805,7 +867,15 @@ public struct SORTRO: ValkeyCommand {
805867
public var isReadOnly: Bool { true }
806868

807869
@inlinable public func encode(into commandEncoder: inout ValkeyCommandEncoder) {
808-
commandEncoder.encodeArray("SORT_RO", key, RESPWithToken("BY", byPattern), RESPWithToken("LIMIT", limit), RESPWithToken("GET", getPattern), order, RESPPureToken("ALPHA", sorting))
870+
commandEncoder.encodeArray(
871+
"SORT_RO",
872+
key,
873+
RESPWithToken("BY", byPattern),
874+
RESPWithToken("LIMIT", limit),
875+
RESPWithToken("GET", getPattern),
876+
order,
877+
RESPPureToken("ALPHA", sorting)
878+
)
809879
}
810880
}
811881

@@ -1049,8 +1119,30 @@ extension ValkeyConnectionProtocol {
10491119
/// * "OK": Success.
10501120
/// * "NOKEY": No keys were found in the source instance.
10511121
@inlinable
1052-
public func migrate<Host: RESPStringRenderable>(host: Host, port: Int, keySelector: MIGRATE<Host>.KeySelector, destinationDb: Int, timeout: Int, copy: Bool = false, replace: Bool = false, authentication: MIGRATE<Host>.Authentication? = nil, keys: [ValkeyKey] = []) async throws -> String? {
1053-
try await send(command: MIGRATE(host: host, port: port, keySelector: keySelector, destinationDb: destinationDb, timeout: timeout, copy: copy, replace: replace, authentication: authentication, keys: keys))
1122+
public func migrate<Host: RESPStringRenderable>(
1123+
host: Host,
1124+
port: Int,
1125+
keySelector: MIGRATE<Host>.KeySelector,
1126+
destinationDb: Int,
1127+
timeout: Int,
1128+
copy: Bool = false,
1129+
replace: Bool = false,
1130+
authentication: MIGRATE<Host>.Authentication? = nil,
1131+
keys: [ValkeyKey] = []
1132+
) async throws -> String? {
1133+
try await send(
1134+
command: MIGRATE(
1135+
host: host,
1136+
port: port,
1137+
keySelector: keySelector,
1138+
destinationDb: destinationDb,
1139+
timeout: timeout,
1140+
copy: copy,
1141+
replace: replace,
1142+
authentication: authentication,
1143+
keys: keys
1144+
)
1145+
)
10541146
}
10551147

10561148
/// Moves a key to another database.
@@ -1244,8 +1336,26 @@ extension ValkeyConnectionProtocol {
12441336
/// * 5.0.0: Added the `IDLETIME` and `FREQ` options.
12451337
/// - Complexity: O(1) to create the new key and additional O(N*M) to reconstruct the serialized value, where N is the number of objects composing the value and M their average size. For small string values the time complexity is thus O(1)+O(1*M) where M is small, so simply O(1). However for sorted set values the complexity is O(N*M*log(N)) because inserting values into sorted sets is O(log(N)).
12461338
@inlinable
1247-
public func restore<SerializedValue: RESPStringRenderable>(key: ValkeyKey, ttl: Int, serializedValue: SerializedValue, replace: Bool = false, absttl: Bool = false, seconds: Int? = nil, frequency: Int? = nil) async throws {
1248-
_ = try await send(command: RESTORE(key: key, ttl: ttl, serializedValue: serializedValue, replace: replace, absttl: absttl, seconds: seconds, frequency: frequency))
1339+
public func restore<SerializedValue: RESPStringRenderable>(
1340+
key: ValkeyKey,
1341+
ttl: Int,
1342+
serializedValue: SerializedValue,
1343+
replace: Bool = false,
1344+
absttl: Bool = false,
1345+
seconds: Int? = nil,
1346+
frequency: Int? = nil
1347+
) async throws {
1348+
_ = try await send(
1349+
command: RESTORE(
1350+
key: key,
1351+
ttl: ttl,
1352+
serializedValue: serializedValue,
1353+
replace: replace,
1354+
absttl: absttl,
1355+
seconds: seconds,
1356+
frequency: frequency
1357+
)
1358+
)
12491359
}
12501360

12511361
/// Iterates over the key names in the database.
@@ -1270,8 +1380,26 @@ extension ValkeyConnectionProtocol {
12701380
/// * [Integer]: When the store option is specified the command returns the number of sorted elements in the destination list.
12711381
/// * [Array]: When not passing the store option the command returns a list of sorted elements.
12721382
@inlinable
1273-
public func sort(key: ValkeyKey, byPattern: String? = nil, limit: SORT.Limit? = nil, getPattern: [String] = [], order: SORT.Order? = nil, sorting: Bool = false, destination: ValkeyKey? = nil) async throws -> SORT.Response {
1274-
try await send(command: SORT(key: key, byPattern: byPattern, limit: limit, getPattern: getPattern, order: order, sorting: sorting, destination: destination))
1383+
public func sort(
1384+
key: ValkeyKey,
1385+
byPattern: String? = nil,
1386+
limit: SORT.Limit? = nil,
1387+
getPattern: [String] = [],
1388+
order: SORT.Order? = nil,
1389+
sorting: Bool = false,
1390+
destination: ValkeyKey? = nil
1391+
) async throws -> SORT.Response {
1392+
try await send(
1393+
command: SORT(
1394+
key: key,
1395+
byPattern: byPattern,
1396+
limit: limit,
1397+
getPattern: getPattern,
1398+
order: order,
1399+
sorting: sorting,
1400+
destination: destination
1401+
)
1402+
)
12751403
}
12761404

12771405
/// Returns the sorted elements of a list, a set, or a sorted set.
@@ -1281,7 +1409,14 @@ extension ValkeyConnectionProtocol {
12811409
/// - Complexity: O(N+M*log(M)) where N is the number of elements in the list or set to sort, and M the number of returned elements. When the elements are not sorted, complexity is O(N).
12821410
/// - Response: [Array]: A list of sorted elements.
12831411
@inlinable
1284-
public func sortRo(key: ValkeyKey, byPattern: String? = nil, limit: SORTRO.Limit? = nil, getPattern: [String] = [], order: SORTRO.Order? = nil, sorting: Bool = false) async throws -> RESPToken.Array {
1412+
public func sortRo(
1413+
key: ValkeyKey,
1414+
byPattern: String? = nil,
1415+
limit: SORTRO.Limit? = nil,
1416+
getPattern: [String] = [],
1417+
order: SORTRO.Order? = nil,
1418+
sorting: Bool = false
1419+
) async throws -> RESPToken.Array {
12851420
try await send(command: SORTRO(key: key, byPattern: byPattern, limit: limit, getPattern: getPattern, order: order, sorting: sorting))
12861421
}
12871422

0 commit comments

Comments
 (0)