Skip to content

Commit 1ae551f

Browse files
authored
Remove key parameter label on first function parameter, add plural for array parameters (#139)
1 parent 986eb4d commit 1ae551f

28 files changed

+1337
-1306
lines changed

Benchmarks/ValkeyBenchmarks/ValkeyBenchmarks.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ let benchmarks: @Sendable () -> Void = {
5252
benchmark.startMeasurement()
5353

5454
for _ in benchmark.scaledIterations {
55-
let foo = try await connection.get(key: "foo")
55+
let foo = try await connection.get("foo")
5656
precondition(foo.map { String(buffer: $0) } == "Bar")
5757
}
5858

@@ -91,7 +91,7 @@ let benchmarks: @Sendable () -> Void = {
9191
}
9292

9393
Benchmark("ValkeyCommandEncoder – Simple GET", configuration: .init(metrics: defaultMetrics, scalingFactor: .kilo)) { benchmark in
94-
let command = GET(key: "foo")
94+
let command = GET("foo")
9595
benchmark.startMeasurement()
9696

9797
var encoder = ValkeyCommandEncoder()
@@ -105,7 +105,7 @@ let benchmarks: @Sendable () -> Void = {
105105

106106
Benchmark("ValkeyCommandEncoder – Simple MGET 15 keys", configuration: .init(metrics: defaultMetrics, scalingFactor: .kilo)) { benchmark in
107107
let keys = (0..<15).map { ValkeyKey("foo-\($0)") }
108-
let command = MGET(key: keys)
108+
let command = MGET(keys: keys)
109109
benchmark.startMeasurement()
110110

111111
var encoder = ValkeyCommandEncoder()

Sources/Valkey/Commands/BitmapCommands.swift

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public struct BITCOUNT: ValkeyCommand {
8585
public var key: ValkeyKey
8686
public var range: Range?
8787

88-
@inlinable public init(key: ValkeyKey, range: Range? = nil) {
88+
@inlinable public init(_ key: ValkeyKey, range: Range? = nil) {
8989
self.key = key
9090
self.range = range
9191
}
@@ -248,17 +248,17 @@ public struct BITFIELD: ValkeyCommand {
248248
public typealias Response = RESPToken.Array
249249

250250
public var key: ValkeyKey
251-
public var operation: [Operation]
251+
public var operations: [Operation]
252252

253-
@inlinable public init(key: ValkeyKey, operation: [Operation] = []) {
253+
@inlinable public init(_ key: ValkeyKey, operations: [Operation] = []) {
254254
self.key = key
255-
self.operation = operation
255+
self.operations = operations
256256
}
257257

258258
public var keysAffected: CollectionOfOne<ValkeyKey> { .init(key) }
259259

260260
@inlinable public func encode(into commandEncoder: inout ValkeyCommandEncoder) {
261-
commandEncoder.encodeArray("BITFIELD", key, operation)
261+
commandEncoder.encodeArray("BITFIELD", key, operations)
262262
}
263263
}
264264

@@ -288,19 +288,19 @@ public struct BITFIELDRO: ValkeyCommand {
288288
public typealias Response = [Int]
289289

290290
public var key: ValkeyKey
291-
public var getBlock: [GetBlock]
291+
public var getBlocks: [GetBlock]
292292

293-
@inlinable public init(key: ValkeyKey, getBlock: [GetBlock] = []) {
293+
@inlinable public init(_ key: ValkeyKey, getBlocks: [GetBlock] = []) {
294294
self.key = key
295-
self.getBlock = getBlock
295+
self.getBlocks = getBlocks
296296
}
297297

298298
public var keysAffected: CollectionOfOne<ValkeyKey> { .init(key) }
299299

300300
public var isReadOnly: Bool { true }
301301

302302
@inlinable public func encode(into commandEncoder: inout ValkeyCommandEncoder) {
303-
commandEncoder.encodeArray("BITFIELD_RO", key, RESPWithToken("GET", getBlock))
303+
commandEncoder.encodeArray("BITFIELD_RO", key, RESPWithToken("GET", getBlocks))
304304
}
305305
}
306306

@@ -330,18 +330,18 @@ public struct BITOP: ValkeyCommand {
330330

331331
public var operation: Operation
332332
public var destkey: ValkeyKey
333-
public var key: [ValkeyKey]
333+
public var keys: [ValkeyKey]
334334

335-
@inlinable public init(operation: Operation, destkey: ValkeyKey, key: [ValkeyKey]) {
335+
@inlinable public init(operation: Operation, destkey: ValkeyKey, keys: [ValkeyKey]) {
336336
self.operation = operation
337337
self.destkey = destkey
338-
self.key = key
338+
self.keys = keys
339339
}
340340

341-
public var keysAffected: [ValkeyKey] { key + [destkey] }
341+
public var keysAffected: [ValkeyKey] { keys + [destkey] }
342342

343343
@inlinable public func encode(into commandEncoder: inout ValkeyCommandEncoder) {
344-
commandEncoder.encodeArray("BITOP", operation, destkey, key)
344+
commandEncoder.encodeArray("BITOP", operation, destkey, keys)
345345
}
346346
}
347347

@@ -409,7 +409,7 @@ public struct BITPOS: ValkeyCommand {
409409
public var bit: Int
410410
public var range: Range?
411411

412-
@inlinable public init(key: ValkeyKey, bit: Int, range: Range? = nil) {
412+
@inlinable public init(_ key: ValkeyKey, bit: Int, range: Range? = nil) {
413413
self.key = key
414414
self.bit = bit
415415
self.range = range
@@ -432,7 +432,7 @@ public struct GETBIT: ValkeyCommand {
432432
public var key: ValkeyKey
433433
public var offset: Int
434434

435-
@inlinable public init(key: ValkeyKey, offset: Int) {
435+
@inlinable public init(_ key: ValkeyKey, offset: Int) {
436436
self.key = key
437437
self.offset = offset
438438
}
@@ -455,7 +455,7 @@ public struct SETBIT: ValkeyCommand {
455455
public var offset: Int
456456
public var value: Int
457457

458-
@inlinable public init(key: ValkeyKey, offset: Int, value: Int) {
458+
@inlinable public init(_ key: ValkeyKey, offset: Int, value: Int) {
459459
self.key = key
460460
self.offset = offset
461461
self.value = value
@@ -479,8 +479,8 @@ extension ValkeyConnectionProtocol {
479479
/// - Complexity: O(N)
480480
/// - Response: [Integer]: The number of bits set to 1.
481481
@inlinable
482-
public func bitcount(key: ValkeyKey, range: BITCOUNT.Range? = nil) async throws -> Int {
483-
try await send(command: BITCOUNT(key: key, range: range))
482+
public func bitcount(_ key: ValkeyKey, range: BITCOUNT.Range? = nil) async throws -> Int {
483+
try await send(command: BITCOUNT(key, range: range))
484484
}
485485

486486
/// Performs arbitrary bitfield integer operations on strings.
@@ -492,8 +492,8 @@ extension ValkeyConnectionProtocol {
492492
/// * [Array]: The result of the subcommand at the same position
493493
/// * [Array]: In case OVERFLOW FAIL was given and overflows or underflows detected
494494
@inlinable
495-
public func bitfield(key: ValkeyKey, operation: [BITFIELD.Operation] = []) async throws -> RESPToken.Array {
496-
try await send(command: BITFIELD(key: key, operation: operation))
495+
public func bitfield(_ key: ValkeyKey, operations: [BITFIELD.Operation] = []) async throws -> RESPToken.Array {
496+
try await send(command: BITFIELD(key, operations: operations))
497497
}
498498

499499
/// Performs arbitrary read-only bitfield integer operations on strings.
@@ -503,8 +503,8 @@ extension ValkeyConnectionProtocol {
503503
/// - Complexity: O(1) for each subcommand specified
504504
/// - Response: [Array]: The result of the subcommand at the same position
505505
@inlinable
506-
public func bitfieldRo(key: ValkeyKey, getBlock: [BITFIELDRO.GetBlock] = []) async throws -> [Int] {
507-
try await send(command: BITFIELDRO(key: key, getBlock: getBlock))
506+
public func bitfieldRo(_ key: ValkeyKey, getBlocks: [BITFIELDRO.GetBlock] = []) async throws -> [Int] {
507+
try await send(command: BITFIELDRO(key, getBlocks: getBlocks))
508508
}
509509

510510
/// Performs bitwise operations on multiple strings, and stores the result.
@@ -514,8 +514,8 @@ extension ValkeyConnectionProtocol {
514514
/// - Complexity: O(N)
515515
/// - Response: [Integer]: The size of the string stored in the destination key, that is equal to the size of the longest input string.
516516
@inlinable
517-
public func bitop(operation: BITOP.Operation, destkey: ValkeyKey, key: [ValkeyKey]) async throws -> Int {
518-
try await send(command: BITOP(operation: operation, destkey: destkey, key: key))
517+
public func bitop(operation: BITOP.Operation, destkey: ValkeyKey, keys: [ValkeyKey]) async throws -> Int {
518+
try await send(command: BITOP(operation: operation, destkey: destkey, keys: keys))
519519
}
520520

521521
/// Finds the first set (1) or clear (0) bit in a string.
@@ -529,8 +529,8 @@ extension ValkeyConnectionProtocol {
529529
/// * [Integer]: The position of the first bit set to 1 or 0 according to the request.
530530
/// * -1: In case the `bit` argument is 1 and the string is empty or composed of just zero bytes.
531531
@inlinable
532-
public func bitpos(key: ValkeyKey, bit: Int, range: BITPOS.Range? = nil) async throws -> Int {
533-
try await send(command: BITPOS(key: key, bit: bit, range: range))
532+
public func bitpos(_ key: ValkeyKey, bit: Int, range: BITPOS.Range? = nil) async throws -> Int {
533+
try await send(command: BITPOS(key, bit: bit, range: range))
534534
}
535535

536536
/// Returns a bit value by offset.
@@ -540,8 +540,8 @@ extension ValkeyConnectionProtocol {
540540
/// - Complexity: O(1)
541541
/// - Response: The bit value stored at offset.
542542
@inlinable
543-
public func getbit(key: ValkeyKey, offset: Int) async throws -> Int {
544-
try await send(command: GETBIT(key: key, offset: offset))
543+
public func getbit(_ key: ValkeyKey, offset: Int) async throws -> Int {
544+
try await send(command: GETBIT(key, offset: offset))
545545
}
546546

547547
/// Sets or clears the bit at offset of the string value. Creates the key if it doesn't exist.
@@ -551,8 +551,8 @@ extension ValkeyConnectionProtocol {
551551
/// - Complexity: O(1)
552552
/// - Response: The original bit value stored at offset.
553553
@inlinable
554-
public func setbit(key: ValkeyKey, offset: Int, value: Int) async throws -> Int {
555-
try await send(command: SETBIT(key: key, offset: offset, value: value))
554+
public func setbit(_ key: ValkeyKey, offset: Int, value: Int) async throws -> Int {
555+
try await send(command: SETBIT(key, offset: offset, value: value))
556556
}
557557

558558
}

Sources/Valkey/Commands/ClusterCommands.swift

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ public enum CLUSTER {
2828
/// Assigns new hash slots to a node.
2929
@_documentation(visibility: internal)
3030
public struct ADDSLOTS: ValkeyCommand {
31-
public var slot: [Int]
31+
public var slots: [Int]
3232

33-
@inlinable public init(slot: [Int]) {
34-
self.slot = slot
33+
@inlinable public init(slots: [Int]) {
34+
self.slots = slots
3535
}
3636

3737
@inlinable public func encode(into commandEncoder: inout ValkeyCommandEncoder) {
38-
commandEncoder.encodeArray("CLUSTER", "ADDSLOTS", slot)
38+
commandEncoder.encodeArray("CLUSTER", "ADDSLOTS", slots)
3939
}
4040
}
4141

@@ -62,14 +62,14 @@ public enum CLUSTER {
6262
endSlot.encode(into: &commandEncoder)
6363
}
6464
}
65-
public var range: [Range]
65+
public var ranges: [Range]
6666

67-
@inlinable public init(range: [Range]) {
68-
self.range = range
67+
@inlinable public init(ranges: [Range]) {
68+
self.ranges = ranges
6969
}
7070

7171
@inlinable public func encode(into commandEncoder: inout ValkeyCommandEncoder) {
72-
commandEncoder.encodeArray("CLUSTER", "ADDSLOTSRANGE", range)
72+
commandEncoder.encodeArray("CLUSTER", "ADDSLOTSRANGE", ranges)
7373
}
7474
}
7575

@@ -121,14 +121,14 @@ public enum CLUSTER {
121121
/// Sets hash slots as unbound for a node.
122122
@_documentation(visibility: internal)
123123
public struct DELSLOTS: ValkeyCommand {
124-
public var slot: [Int]
124+
public var slots: [Int]
125125

126-
@inlinable public init(slot: [Int]) {
127-
self.slot = slot
126+
@inlinable public init(slots: [Int]) {
127+
self.slots = slots
128128
}
129129

130130
@inlinable public func encode(into commandEncoder: inout ValkeyCommandEncoder) {
131-
commandEncoder.encodeArray("CLUSTER", "DELSLOTS", slot)
131+
commandEncoder.encodeArray("CLUSTER", "DELSLOTS", slots)
132132
}
133133
}
134134

@@ -155,14 +155,14 @@ public enum CLUSTER {
155155
endSlot.encode(into: &commandEncoder)
156156
}
157157
}
158-
public var range: [Range]
158+
public var ranges: [Range]
159159

160-
@inlinable public init(range: [Range]) {
161-
self.range = range
160+
@inlinable public init(ranges: [Range]) {
161+
self.ranges = ranges
162162
}
163163

164164
@inlinable public func encode(into commandEncoder: inout ValkeyCommandEncoder) {
165-
commandEncoder.encodeArray("CLUSTER", "DELSLOTSRANGE", range)
165+
commandEncoder.encodeArray("CLUSTER", "DELSLOTSRANGE", ranges)
166166
}
167167
}
168168

@@ -271,7 +271,7 @@ public enum CLUSTER {
271271

272272
public var key: Key
273273

274-
@inlinable public init(key: Key) {
274+
@inlinable public init(_ key: Key) {
275275
self.key = key
276276
}
277277

@@ -664,8 +664,8 @@ extension ValkeyConnectionProtocol {
664664
/// - Available: 3.0.0
665665
/// - Complexity: O(N) where N is the total number of hash slot arguments
666666
@inlinable
667-
public func clusterAddslots(slot: [Int]) async throws {
668-
_ = try await send(command: CLUSTER.ADDSLOTS(slot: slot))
667+
public func clusterAddslots(slots: [Int]) async throws {
668+
_ = try await send(command: CLUSTER.ADDSLOTS(slots: slots))
669669
}
670670

671671
/// Assigns new hash slot ranges to a node.
@@ -674,8 +674,8 @@ extension ValkeyConnectionProtocol {
674674
/// - Available: 7.0.0
675675
/// - Complexity: O(N) where N is the total number of the slots between the start slot and end slot arguments.
676676
@inlinable
677-
public func clusterAddslotsrange(range: [CLUSTER.ADDSLOTSRANGE.Range]) async throws {
678-
_ = try await send(command: CLUSTER.ADDSLOTSRANGE(range: range))
677+
public func clusterAddslotsrange(ranges: [CLUSTER.ADDSLOTSRANGE.Range]) async throws {
678+
_ = try await send(command: CLUSTER.ADDSLOTSRANGE(ranges: ranges))
679679
}
680680

681681
/// Advances the cluster config epoch.
@@ -719,8 +719,8 @@ extension ValkeyConnectionProtocol {
719719
/// - Available: 3.0.0
720720
/// - Complexity: O(N) where N is the total number of hash slot arguments
721721
@inlinable
722-
public func clusterDelslots(slot: [Int]) async throws {
723-
_ = try await send(command: CLUSTER.DELSLOTS(slot: slot))
722+
public func clusterDelslots(slots: [Int]) async throws {
723+
_ = try await send(command: CLUSTER.DELSLOTS(slots: slots))
724724
}
725725

726726
/// Sets hash slot ranges as unbound for a node.
@@ -729,8 +729,8 @@ extension ValkeyConnectionProtocol {
729729
/// - Available: 7.0.0
730730
/// - Complexity: O(N) where N is the total number of the slots between the start slot and end slot arguments.
731731
@inlinable
732-
public func clusterDelslotsrange(range: [CLUSTER.DELSLOTSRANGE.Range]) async throws {
733-
_ = try await send(command: CLUSTER.DELSLOTSRANGE(range: range))
732+
public func clusterDelslotsrange(ranges: [CLUSTER.DELSLOTSRANGE.Range]) async throws {
733+
_ = try await send(command: CLUSTER.DELSLOTSRANGE(ranges: ranges))
734734
}
735735

736736
/// Forces a replica to perform a manual failover of its primary.
@@ -803,8 +803,8 @@ extension ValkeyConnectionProtocol {
803803
/// - Complexity: O(N) where N is the number of bytes in the key
804804
/// - Response: [Integer]: The hash slot number for the specified key
805805
@inlinable
806-
public func clusterKeyslot<Key: RESPStringRenderable>(key: Key) async throws -> Int {
807-
try await send(command: CLUSTER.KEYSLOT(key: key))
806+
public func clusterKeyslot<Key: RESPStringRenderable>(_ key: Key) async throws -> Int {
807+
try await send(command: CLUSTER.KEYSLOT(key))
808808
}
809809

810810
/// Returns a list of all TCP links to and from peer nodes.

0 commit comments

Comments
 (0)