Skip to content

Commit 6643490

Browse files
authored
Add public init functions to command block types (#7)
1 parent 7758445 commit 6643490

File tree

11 files changed

+360
-0
lines changed

11 files changed

+360
-0
lines changed

Sources/Valkey/Commands/BitmapCommands.swift

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ public struct BITCOUNT: RESPCommand {
4141
@usableFromInline let end: Int
4242
@usableFromInline let unit: RangeUnit?
4343

44+
45+
@inlinable public init(start: Int, end: Int, unit: RangeUnit? = nil) {
46+
self.start = start
47+
self.end = end
48+
self.unit = unit
49+
}
50+
4451
@inlinable
4552
public func encode(into commandEncoder: inout RESPCommandEncoder) -> Int {
4653
var count = 0
@@ -71,6 +78,12 @@ public struct BITFIELD: RESPCommand {
7178
@usableFromInline let encoding: String
7279
@usableFromInline let offset: Int
7380

81+
82+
@inlinable public init(encoding: String, offset: Int) {
83+
self.encoding = encoding
84+
self.offset = offset
85+
}
86+
7487
@inlinable
7588
public func encode(into commandEncoder: inout RESPCommandEncoder) -> Int {
7689
var count = 0
@@ -98,6 +111,13 @@ public struct BITFIELD: RESPCommand {
98111
@usableFromInline let offset: Int
99112
@usableFromInline let value: Int
100113

114+
115+
@inlinable public init(encoding: String, offset: Int, value: Int) {
116+
self.encoding = encoding
117+
self.offset = offset
118+
self.value = value
119+
}
120+
101121
@inlinable
102122
public func encode(into commandEncoder: inout RESPCommandEncoder) -> Int {
103123
var count = 0
@@ -112,6 +132,13 @@ public struct BITFIELD: RESPCommand {
112132
@usableFromInline let offset: Int
113133
@usableFromInline let increment: Int
114134

135+
136+
@inlinable public init(encoding: String, offset: Int, increment: Int) {
137+
self.encoding = encoding
138+
self.offset = offset
139+
self.increment = increment
140+
}
141+
115142
@inlinable
116143
public func encode(into commandEncoder: inout RESPCommandEncoder) -> Int {
117144
var count = 0
@@ -137,6 +164,12 @@ public struct BITFIELD: RESPCommand {
137164
@usableFromInline let overflowBlock: OperationWriteOverflowBlock?
138165
@usableFromInline let writeOperation: OperationWriteWriteOperation
139166

167+
168+
@inlinable public init(overflowBlock: OperationWriteOverflowBlock? = nil, writeOperation: OperationWriteWriteOperation) {
169+
self.overflowBlock = overflowBlock
170+
self.writeOperation = writeOperation
171+
}
172+
140173
@inlinable
141174
public func encode(into commandEncoder: inout RESPCommandEncoder) -> Int {
142175
var count = 0
@@ -178,6 +211,12 @@ public struct BITFIELDRO: RESPCommand {
178211
@usableFromInline let encoding: String
179212
@usableFromInline let offset: Int
180213

214+
215+
@inlinable public init(encoding: String, offset: Int) {
216+
self.encoding = encoding
217+
self.offset = offset
218+
}
219+
181220
@inlinable
182221
public func encode(into commandEncoder: inout RESPCommandEncoder) -> Int {
183222
var count = 0
@@ -254,6 +293,12 @@ public struct BITPOS: RESPCommand {
254293
@usableFromInline let end: Int
255294
@usableFromInline let unit: RangeEndUnitBlockUnit?
256295

296+
297+
@inlinable public init(end: Int, unit: RangeEndUnitBlockUnit? = nil) {
298+
self.end = end
299+
self.unit = unit
300+
}
301+
257302
@inlinable
258303
public func encode(into commandEncoder: inout RESPCommandEncoder) -> Int {
259304
var count = 0
@@ -266,6 +311,12 @@ public struct BITPOS: RESPCommand {
266311
@usableFromInline let start: Int
267312
@usableFromInline let endUnitBlock: RangeEndUnitBlock?
268313

314+
315+
@inlinable public init(start: Int, endUnitBlock: RangeEndUnitBlock? = nil) {
316+
self.start = start
317+
self.endUnitBlock = endUnitBlock
318+
}
319+
269320
@inlinable
270321
public func encode(into commandEncoder: inout RESPCommandEncoder) -> Int {
271322
var count = 0

Sources/Valkey/Commands/ClusterCommands.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ public enum CLUSTER {
4545
@usableFromInline let startSlot: Int
4646
@usableFromInline let endSlot: Int
4747

48+
49+
@inlinable public init(startSlot: Int, endSlot: Int) {
50+
self.startSlot = startSlot
51+
self.endSlot = endSlot
52+
}
53+
4854
@inlinable
4955
public func encode(into commandEncoder: inout RESPCommandEncoder) -> Int {
5056
var count = 0
@@ -130,6 +136,12 @@ public enum CLUSTER {
130136
@usableFromInline let startSlot: Int
131137
@usableFromInline let endSlot: Int
132138

139+
140+
@inlinable public init(startSlot: Int, endSlot: Int) {
141+
self.startSlot = startSlot
142+
self.endSlot = endSlot
143+
}
144+
133145
@inlinable
134146
public func encode(into commandEncoder: inout RESPCommandEncoder) -> Int {
135147
var count = 0

Sources/Valkey/Commands/ConnectionCommands.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,12 @@ public struct HELLO: RESPCommand {
514514
@usableFromInline let username: String
515515
@usableFromInline let password: String
516516

517+
518+
@inlinable public init(username: String, password: String) {
519+
self.username = username
520+
self.password = password
521+
}
522+
517523
@inlinable
518524
public func encode(into commandEncoder: inout RESPCommandEncoder) -> Int {
519525
var count = 0
@@ -527,6 +533,13 @@ public struct HELLO: RESPCommand {
527533
@usableFromInline let auth: ArgumentsAuth?
528534
@usableFromInline let clientname: String?
529535

536+
537+
@inlinable public init(protover: Int, auth: ArgumentsAuth? = nil, clientname: String? = nil) {
538+
self.protover = protover
539+
self.auth = auth
540+
self.clientname = clientname
541+
}
542+
530543
@inlinable
531544
public func encode(into commandEncoder: inout RESPCommandEncoder) -> Int {
532545
var count = 0

Sources/Valkey/Commands/GenericCommands.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,12 @@ public struct MIGRATE: RESPCommand {
283283
@usableFromInline let username: String
284284
@usableFromInline let password: String
285285

286+
287+
@inlinable public init(username: String, password: String) {
288+
self.username = username
289+
self.password = password
290+
}
291+
286292
@inlinable
287293
public func encode(into commandEncoder: inout RESPCommandEncoder) -> Int {
288294
var count = 0
@@ -565,6 +571,12 @@ public struct SORT: RESPCommand {
565571
@usableFromInline let offset: Int
566572
@usableFromInline let count: Int
567573

574+
575+
@inlinable public init(offset: Int, count: Int) {
576+
self.offset = offset
577+
self.count = count
578+
}
579+
568580
@inlinable
569581
public func encode(into commandEncoder: inout RESPCommandEncoder) -> Int {
570582
var count = 0
@@ -616,6 +628,12 @@ public struct SORTRO: RESPCommand {
616628
@usableFromInline let offset: Int
617629
@usableFromInline let count: Int
618630

631+
632+
@inlinable public init(offset: Int, count: Int) {
633+
self.offset = offset
634+
self.count = count
635+
}
636+
619637
@inlinable
620638
public func encode(into commandEncoder: inout RESPCommandEncoder) -> Int {
621639
var count = 0

Sources/Valkey/Commands/GeoCommands.swift

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ public struct GEOADD: RESPCommand {
4141
@usableFromInline let latitude: Double
4242
@usableFromInline let member: String
4343

44+
45+
@inlinable public init(longitude: Double, latitude: Double, member: String) {
46+
self.longitude = longitude
47+
self.latitude = latitude
48+
self.member = member
49+
}
50+
4451
@inlinable
4552
public func encode(into commandEncoder: inout RESPCommandEncoder) -> Int {
4653
var count = 0
@@ -162,6 +169,12 @@ public struct GEORADIUS: RESPCommand {
162169
@usableFromInline let count: Int
163170
@usableFromInline let any: Bool
164171

172+
173+
@inlinable public init(count: Int, any: Bool = false) {
174+
self.count = count
175+
self.any = any
176+
}
177+
165178
@inlinable
166179
public func encode(into commandEncoder: inout RESPCommandEncoder) -> Int {
167180
var count = 0
@@ -249,6 +262,12 @@ public struct GEORADIUSBYMEMBER: RESPCommand {
249262
@usableFromInline let count: Int
250263
@usableFromInline let any: Bool
251264

265+
266+
@inlinable public init(count: Int, any: Bool = false) {
267+
self.count = count
268+
self.any = any
269+
}
270+
252271
@inlinable
253272
public func encode(into commandEncoder: inout RESPCommandEncoder) -> Int {
254273
var count = 0
@@ -334,6 +353,12 @@ public struct GEORADIUSBYMEMBERRO: RESPCommand {
334353
@usableFromInline let count: Int
335354
@usableFromInline let any: Bool
336355

356+
357+
@inlinable public init(count: Int, any: Bool = false) {
358+
self.count = count
359+
self.any = any
360+
}
361+
337362
@inlinable
338363
public func encode(into commandEncoder: inout RESPCommandEncoder) -> Int {
339364
var count = 0
@@ -405,6 +430,12 @@ public struct GEORADIUSRO: RESPCommand {
405430
@usableFromInline let count: Int
406431
@usableFromInline let any: Bool
407432

433+
434+
@inlinable public init(count: Int, any: Bool = false) {
435+
self.count = count
436+
self.any = any
437+
}
438+
408439
@inlinable
409440
public func encode(into commandEncoder: inout RESPCommandEncoder) -> Int {
410441
var count = 0
@@ -462,6 +493,12 @@ public struct GEOSEARCH: RESPCommand {
462493
@usableFromInline let longitude: Double
463494
@usableFromInline let latitude: Double
464495

496+
497+
@inlinable public init(longitude: Double, latitude: Double) {
498+
self.longitude = longitude
499+
self.latitude = latitude
500+
}
501+
465502
@inlinable
466503
public func encode(into commandEncoder: inout RESPCommandEncoder) -> Int {
467504
var count = 0
@@ -502,6 +539,12 @@ public struct GEOSEARCH: RESPCommand {
502539
@usableFromInline let radius: Double
503540
@usableFromInline let unit: ByCircleUnit
504541

542+
543+
@inlinable public init(radius: Double, unit: ByCircleUnit) {
544+
self.radius = radius
545+
self.unit = unit
546+
}
547+
505548
@inlinable
506549
public func encode(into commandEncoder: inout RESPCommandEncoder) -> Int {
507550
var count = 0
@@ -531,6 +574,13 @@ public struct GEOSEARCH: RESPCommand {
531574
@usableFromInline let height: Double
532575
@usableFromInline let unit: ByBoxUnit
533576

577+
578+
@inlinable public init(width: Double, height: Double, unit: ByBoxUnit) {
579+
self.width = width
580+
self.height = height
581+
self.unit = unit
582+
}
583+
534584
@inlinable
535585
public func encode(into commandEncoder: inout RESPCommandEncoder) -> Int {
536586
var count = 0
@@ -568,6 +618,12 @@ public struct GEOSEARCH: RESPCommand {
568618
@usableFromInline let count: Int
569619
@usableFromInline let any: Bool
570620

621+
622+
@inlinable public init(count: Int, any: Bool = false) {
623+
self.count = count
624+
self.any = any
625+
}
626+
571627
@inlinable
572628
public func encode(into commandEncoder: inout RESPCommandEncoder) -> Int {
573629
var count = 0
@@ -609,6 +665,12 @@ public struct GEOSEARCHSTORE: RESPCommand {
609665
@usableFromInline let longitude: Double
610666
@usableFromInline let latitude: Double
611667

668+
669+
@inlinable public init(longitude: Double, latitude: Double) {
670+
self.longitude = longitude
671+
self.latitude = latitude
672+
}
673+
612674
@inlinable
613675
public func encode(into commandEncoder: inout RESPCommandEncoder) -> Int {
614676
var count = 0
@@ -649,6 +711,12 @@ public struct GEOSEARCHSTORE: RESPCommand {
649711
@usableFromInline let radius: Double
650712
@usableFromInline let unit: ByCircleUnit
651713

714+
715+
@inlinable public init(radius: Double, unit: ByCircleUnit) {
716+
self.radius = radius
717+
self.unit = unit
718+
}
719+
652720
@inlinable
653721
public func encode(into commandEncoder: inout RESPCommandEncoder) -> Int {
654722
var count = 0
@@ -678,6 +746,13 @@ public struct GEOSEARCHSTORE: RESPCommand {
678746
@usableFromInline let height: Double
679747
@usableFromInline let unit: ByBoxUnit
680748

749+
750+
@inlinable public init(width: Double, height: Double, unit: ByBoxUnit) {
751+
self.width = width
752+
self.height = height
753+
self.unit = unit
754+
}
755+
681756
@inlinable
682757
public func encode(into commandEncoder: inout RESPCommandEncoder) -> Int {
683758
var count = 0
@@ -715,6 +790,12 @@ public struct GEOSEARCHSTORE: RESPCommand {
715790
@usableFromInline let count: Int
716791
@usableFromInline let any: Bool
717792

793+
794+
@inlinable public init(count: Int, any: Bool = false) {
795+
self.count = count
796+
self.any = any
797+
}
798+
718799
@inlinable
719800
public func encode(into commandEncoder: inout RESPCommandEncoder) -> Int {
720801
var count = 0

0 commit comments

Comments
 (0)