Skip to content

Commit 9161960

Browse files
committed
Unformatted commands files
1 parent 57bad7f commit 9161960

15 files changed

+133
-1065
lines changed

Sources/Valkey/Commands/ConnectionCommands.swift

Lines changed: 8 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -302,15 +302,7 @@ extension CLIENT {
302302
public var skipme: Skipme?
303303
public var maxage: Int?
304304

305-
@inlinable public init(
306-
clientType: ClientType? = nil,
307-
clientId: [Int] = [],
308-
username: String? = nil,
309-
addr: String? = nil,
310-
laddr: String? = nil,
311-
skipme: Skipme? = nil,
312-
maxage: Int? = nil
313-
) {
305+
@inlinable public init(clientType: ClientType? = nil, clientId: [Int] = [], username: String? = nil, addr: String? = nil, laddr: String? = nil, skipme: Skipme? = nil, maxage: Int? = nil) {
314306
self.clientType = clientType
315307
self.clientId = clientId
316308
self.username = username
@@ -321,17 +313,7 @@ extension CLIENT {
321313
}
322314

323315
@inlinable public func encode(into commandEncoder: inout ValkeyCommandEncoder) {
324-
commandEncoder.encodeArray(
325-
"CLIENT",
326-
"LIST",
327-
RESPWithToken("TYPE", clientType),
328-
RESPWithToken("ID", clientId),
329-
RESPWithToken("USER", username),
330-
RESPWithToken("ADDR", addr),
331-
RESPWithToken("LADDR", laddr),
332-
RESPWithToken("SKIPME", skipme),
333-
RESPWithToken("MAXAGE", maxage)
334-
)
316+
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))
335317
}
336318
}
337319

@@ -522,15 +504,7 @@ extension CLIENT {
522504
public var optout: Bool
523505
public var noloop: Bool
524506

525-
@inlinable public init(
526-
status: Status,
527-
clientId: Int? = nil,
528-
prefix: [String] = [],
529-
bcast: Bool = false,
530-
optin: Bool = false,
531-
optout: Bool = false,
532-
noloop: Bool = false
533-
) {
507+
@inlinable public init(status: Status, clientId: Int? = nil, prefix: [String] = [], bcast: Bool = false, optin: Bool = false, optout: Bool = false, noloop: Bool = false) {
534508
self.status = status
535509
self.clientId = clientId
536510
self.prefix = prefix
@@ -541,17 +515,7 @@ extension CLIENT {
541515
}
542516

543517
@inlinable public func encode(into commandEncoder: inout ValkeyCommandEncoder) {
544-
commandEncoder.encodeArray(
545-
"CLIENT",
546-
"TRACKING",
547-
status,
548-
RESPWithToken("REDIRECT", clientId),
549-
RESPWithToken("PREFIX", prefix),
550-
RESPPureToken("BCAST", bcast),
551-
RESPPureToken("OPTIN", optin),
552-
RESPPureToken("OPTOUT", optout),
553-
RESPPureToken("NOLOOP", noloop)
554-
)
518+
commandEncoder.encodeArray("CLIENT", "TRACKING", status, RESPWithToken("REDIRECT", clientId), RESPWithToken("PREFIX", prefix), RESPPureToken("BCAST", bcast), RESPPureToken("OPTIN", optin), RESPPureToken("OPTOUT", optout), RESPPureToken("NOLOOP", noloop))
555519
}
556520
}
557521

@@ -906,26 +870,8 @@ extension ValkeyConnectionProtocol {
906870
/// - Complexity: O(N) where N is the number of client connections
907871
/// - Returns: [String]: Information and statistics about client connections
908872
@inlinable
909-
public func clientList(
910-
clientType: CLIENT.LIST.ClientType? = nil,
911-
clientId: [Int] = [],
912-
username: String? = nil,
913-
addr: String? = nil,
914-
laddr: String? = nil,
915-
skipme: CLIENT.LIST.Skipme? = nil,
916-
maxage: Int? = nil
917-
) async throws -> CLIENT.LIST.Response {
918-
try await send(
919-
command: CLIENT.LIST(
920-
clientType: clientType,
921-
clientId: clientId,
922-
username: username,
923-
addr: addr,
924-
laddr: laddr,
925-
skipme: skipme,
926-
maxage: maxage
927-
)
928-
)
873+
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 -> CLIENT.LIST.Response {
874+
try await send(command: CLIENT.LIST(clientType: clientType, clientId: clientId, username: username, addr: addr, laddr: laddr, skipme: skipme, maxage: maxage))
929875
}
930876

931877
/// Sets the client eviction mode of the connection.
@@ -998,18 +944,8 @@ extension ValkeyConnectionProtocol {
998944
/// - Complexity: O(1). Some options may introduce additional complexity.
999945
/// - Returns: "OK": If the client was successfully put into or taken out of tracking mode.
1000946
@inlinable
1001-
public func clientTracking(
1002-
status: CLIENT.TRACKING.Status,
1003-
clientId: Int? = nil,
1004-
prefix: [String] = [],
1005-
bcast: Bool = false,
1006-
optin: Bool = false,
1007-
optout: Bool = false,
1008-
noloop: Bool = false
1009-
) async throws {
1010-
_ = try await send(
1011-
command: CLIENT.TRACKING(status: status, clientId: clientId, prefix: prefix, bcast: bcast, optin: optin, optout: optout, noloop: noloop)
1012-
)
947+
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 {
948+
_ = try await send(command: CLIENT.TRACKING(status: status, clientId: clientId, prefix: prefix, bcast: bcast, optin: optin, optout: optout, noloop: noloop))
1013949
}
1014950

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

Sources/Valkey/Commands/GenericCommands.swift

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

369-
@inlinable public init(
370-
host: Host,
371-
port: Int,
372-
keySelector: KeySelector,
373-
destinationDb: Int,
374-
timeout: Int,
375-
copy: Bool = false,
376-
replace: Bool = false,
377-
authentication: Authentication? = nil,
378-
keys: [ValkeyKey] = []
379-
) {
369+
@inlinable public init(host: Host, port: Int, keySelector: KeySelector, destinationDb: Int, timeout: Int, copy: Bool = false, replace: Bool = false, authentication: Authentication? = nil, keys: [ValkeyKey] = []) {
380370
self.host = host
381371
self.port = port
382372
self.keySelector = keySelector
@@ -391,18 +381,7 @@ public struct MIGRATE<Host: RESPStringRenderable>: ValkeyCommand {
391381
public var keysAffected: [ValkeyKey] { keys }
392382

393383
@inlinable public func encode(into commandEncoder: inout ValkeyCommandEncoder) {
394-
commandEncoder.encodeArray(
395-
"MIGRATE",
396-
RESPBulkString(host),
397-
port,
398-
keySelector,
399-
destinationDb,
400-
timeout,
401-
RESPPureToken("COPY", copy),
402-
RESPPureToken("REPLACE", replace),
403-
authentication,
404-
RESPWithToken("KEYS", keys)
405-
)
384+
commandEncoder.encodeArray("MIGRATE", RESPBulkString(host), port, keySelector, destinationDb, timeout, RESPPureToken("COPY", copy), RESPPureToken("REPLACE", replace), authentication, RESPWithToken("KEYS", keys))
406385
}
407386
}
408387

@@ -614,15 +593,7 @@ public struct RESTORE<SerializedValue: RESPStringRenderable>: ValkeyCommand {
614593
public var seconds: Int?
615594
public var frequency: Int?
616595

617-
@inlinable public init(
618-
key: ValkeyKey,
619-
ttl: Int,
620-
serializedValue: SerializedValue,
621-
replace: Bool = false,
622-
absttl: Bool = false,
623-
seconds: Int? = nil,
624-
frequency: Int? = nil
625-
) {
596+
@inlinable public init(key: ValkeyKey, ttl: Int, serializedValue: SerializedValue, replace: Bool = false, absttl: Bool = false, seconds: Int? = nil, frequency: Int? = nil) {
626597
self.key = key
627598
self.ttl = ttl
628599
self.serializedValue = serializedValue
@@ -635,16 +606,7 @@ public struct RESTORE<SerializedValue: RESPStringRenderable>: ValkeyCommand {
635606
public var keysAffected: CollectionOfOne<ValkeyKey> { .init(key) }
636607

637608
@inlinable public func encode(into commandEncoder: inout ValkeyCommandEncoder) {
638-
commandEncoder.encodeArray(
639-
"RESTORE",
640-
key,
641-
ttl,
642-
RESPBulkString(serializedValue),
643-
RESPPureToken("REPLACE", replace),
644-
RESPPureToken("ABSTTL", absttl),
645-
RESPWithToken("IDLETIME", seconds),
646-
RESPWithToken("FREQ", frequency)
647-
)
609+
commandEncoder.encodeArray("RESTORE", key, ttl, RESPBulkString(serializedValue), RESPPureToken("REPLACE", replace), RESPPureToken("ABSTTL", absttl), RESPWithToken("IDLETIME", seconds), RESPWithToken("FREQ", frequency))
648610
}
649611
}
650612

@@ -714,15 +676,7 @@ public struct SORT: ValkeyCommand {
714676
public var sorting: Bool
715677
public var destination: ValkeyKey?
716678

717-
@inlinable public init(
718-
key: ValkeyKey,
719-
byPattern: String? = nil,
720-
limit: Limit? = nil,
721-
getPattern: [String] = [],
722-
order: Order? = nil,
723-
sorting: Bool = false,
724-
destination: ValkeyKey? = nil
725-
) {
679+
@inlinable public init(key: ValkeyKey, byPattern: String? = nil, limit: Limit? = nil, getPattern: [String] = [], order: Order? = nil, sorting: Bool = false, destination: ValkeyKey? = nil) {
726680
self.key = key
727681
self.byPattern = byPattern
728682
self.limit = limit
@@ -735,16 +689,7 @@ public struct SORT: ValkeyCommand {
735689
public var keysAffected: [ValkeyKey] { [key] + (destination.map { [$0] } ?? []) }
736690

737691
@inlinable public func encode(into commandEncoder: inout ValkeyCommandEncoder) {
738-
commandEncoder.encodeArray(
739-
"SORT",
740-
key,
741-
RESPWithToken("BY", byPattern),
742-
RESPWithToken("LIMIT", limit),
743-
RESPWithToken("GET", getPattern),
744-
order,
745-
RESPPureToken("ALPHA", sorting),
746-
RESPWithToken("STORE", destination)
747-
)
692+
commandEncoder.encodeArray("SORT", key, RESPWithToken("BY", byPattern), RESPWithToken("LIMIT", limit), RESPWithToken("GET", getPattern), order, RESPPureToken("ALPHA", sorting), RESPWithToken("STORE", destination))
748693
}
749694
}
750695

@@ -794,14 +739,7 @@ public struct SORTRO: ValkeyCommand {
794739
public var order: Order?
795740
public var sorting: Bool
796741

797-
@inlinable public init(
798-
key: ValkeyKey,
799-
byPattern: String? = nil,
800-
limit: Limit? = nil,
801-
getPattern: [String] = [],
802-
order: Order? = nil,
803-
sorting: Bool = false
804-
) {
742+
@inlinable public init(key: ValkeyKey, byPattern: String? = nil, limit: Limit? = nil, getPattern: [String] = [], order: Order? = nil, sorting: Bool = false) {
805743
self.key = key
806744
self.byPattern = byPattern
807745
self.limit = limit
@@ -813,15 +751,7 @@ public struct SORTRO: ValkeyCommand {
813751
public var keysAffected: CollectionOfOne<ValkeyKey> { .init(key) }
814752

815753
@inlinable public func encode(into commandEncoder: inout ValkeyCommandEncoder) {
816-
commandEncoder.encodeArray(
817-
"SORT_RO",
818-
key,
819-
RESPWithToken("BY", byPattern),
820-
RESPWithToken("LIMIT", limit),
821-
RESPWithToken("GET", getPattern),
822-
order,
823-
RESPPureToken("ALPHA", sorting)
824-
)
754+
commandEncoder.encodeArray("SORT_RO", key, RESPWithToken("BY", byPattern), RESPWithToken("LIMIT", limit), RESPWithToken("GET", getPattern), order, RESPPureToken("ALPHA", sorting))
825755
}
826756
}
827757

@@ -1053,30 +983,8 @@ extension ValkeyConnectionProtocol {
1053983
/// * "OK": Success.
1054984
/// * "NOKEY": No keys were found in the source instance.
1055985
@inlinable
1056-
public func migrate<Host: RESPStringRenderable>(
1057-
host: Host,
1058-
port: Int,
1059-
keySelector: MIGRATE<Host>.KeySelector,
1060-
destinationDb: Int,
1061-
timeout: Int,
1062-
copy: Bool = false,
1063-
replace: Bool = false,
1064-
authentication: MIGRATE<Host>.Authentication? = nil,
1065-
keys: [ValkeyKey] = []
1066-
) async throws -> String? {
1067-
try await send(
1068-
command: MIGRATE(
1069-
host: host,
1070-
port: port,
1071-
keySelector: keySelector,
1072-
destinationDb: destinationDb,
1073-
timeout: timeout,
1074-
copy: copy,
1075-
replace: replace,
1076-
authentication: authentication,
1077-
keys: keys
1078-
)
1079-
)
986+
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? {
987+
try await send(command: MIGRATE(host: host, port: port, keySelector: keySelector, destinationDb: destinationDb, timeout: timeout, copy: copy, replace: replace, authentication: authentication, keys: keys))
1080988
}
1081989

1082990
/// Moves a key to another database.
@@ -1270,26 +1178,8 @@ extension ValkeyConnectionProtocol {
12701178
/// * 5.0.0: Added the `IDLETIME` and `FREQ` options.
12711179
/// - 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)).
12721180
@inlinable
1273-
public func restore<SerializedValue: RESPStringRenderable>(
1274-
key: ValkeyKey,
1275-
ttl: Int,
1276-
serializedValue: SerializedValue,
1277-
replace: Bool = false,
1278-
absttl: Bool = false,
1279-
seconds: Int? = nil,
1280-
frequency: Int? = nil
1281-
) async throws {
1282-
_ = try await send(
1283-
command: RESTORE(
1284-
key: key,
1285-
ttl: ttl,
1286-
serializedValue: serializedValue,
1287-
replace: replace,
1288-
absttl: absttl,
1289-
seconds: seconds,
1290-
frequency: frequency
1291-
)
1292-
)
1181+
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 {
1182+
_ = try await send(command: RESTORE(key: key, ttl: ttl, serializedValue: serializedValue, replace: replace, absttl: absttl, seconds: seconds, frequency: frequency))
12931183
}
12941184

12951185
/// Iterates over the key names in the database.
@@ -1314,26 +1204,8 @@ extension ValkeyConnectionProtocol {
13141204
/// * [Integer]: When the store option is specified the command returns the number of sorted elements in the destination list.
13151205
/// * [Array]: When not passing the store option the command returns a list of sorted elements.
13161206
@inlinable
1317-
public func sort(
1318-
key: ValkeyKey,
1319-
byPattern: String? = nil,
1320-
limit: SORT.Limit? = nil,
1321-
getPattern: [String] = [],
1322-
order: SORT.Order? = nil,
1323-
sorting: Bool = false,
1324-
destination: ValkeyKey? = nil
1325-
) async throws -> SORT.Response {
1326-
try await send(
1327-
command: SORT(
1328-
key: key,
1329-
byPattern: byPattern,
1330-
limit: limit,
1331-
getPattern: getPattern,
1332-
order: order,
1333-
sorting: sorting,
1334-
destination: destination
1335-
)
1336-
)
1207+
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 {
1208+
try await send(command: SORT(key: key, byPattern: byPattern, limit: limit, getPattern: getPattern, order: order, sorting: sorting, destination: destination))
13371209
}
13381210

13391211
/// Returns the sorted elements of a list, a set, or a sorted set.
@@ -1343,14 +1215,7 @@ extension ValkeyConnectionProtocol {
13431215
/// - 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).
13441216
/// - Returns: [Array]: A list of sorted elements.
13451217
@inlinable
1346-
public func sortRo(
1347-
key: ValkeyKey,
1348-
byPattern: String? = nil,
1349-
limit: SORTRO.Limit? = nil,
1350-
getPattern: [String] = [],
1351-
order: SORTRO.Order? = nil,
1352-
sorting: Bool = false
1353-
) async throws -> RESPToken.Array {
1218+
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 {
13541219
try await send(command: SORTRO(key: key, byPattern: byPattern, limit: limit, getPattern: getPattern, order: order, sorting: sorting))
13551220
}
13561221

0 commit comments

Comments
 (0)