Skip to content

Commit 2d038fe

Browse files
authored
Create commands.json from files in valkey/src/commands (#59)
* Create commands.json from files in valkey/src/commands - These files are most up to date and are designed to be built off. The file we were using is really for updating the website. - I wrote a small jq script to get the commands in a format we can use. - The format is still slightly different so had to fixup some code in the renderer - These are built from the 8.0.3 tagged build. * Basic ReplySchema decoding * Don't use reply file at all * Cleanup comment output * Int arrays
1 parent f22484d commit 2d038fe

25 files changed

+25298
-20926
lines changed

Sources/Valkey/Commands/BitmapCommands.swift

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import Foundation
2424

2525
/// Counts the number of set bits (population counting) in a string.
2626
public struct BITCOUNT: ValkeyCommand {
27-
public enum RangeUnit: RESPRenderable, Sendable {
27+
public enum RangeEndUnitBlockUnit: RESPRenderable, Sendable {
2828
case byte
2929
case bit
3030

@@ -39,30 +39,48 @@ public struct BITCOUNT: ValkeyCommand {
3939
}
4040
}
4141
}
42-
public struct Range: RESPRenderable, Sendable {
43-
@usableFromInline let start: Int
42+
public struct RangeEndUnitBlock: RESPRenderable, Sendable {
4443
@usableFromInline let end: Int
45-
@usableFromInline let unit: RangeUnit?
44+
@usableFromInline let unit: RangeEndUnitBlockUnit?
4645

4746

48-
@inlinable public init(start: Int, end: Int, unit: RangeUnit? = nil) {
49-
self.start = start
47+
@inlinable public init(end: Int, unit: RangeEndUnitBlockUnit? = nil) {
5048
self.end = end
5149
self.unit = unit
5250
}
5351

5452
@inlinable
5553
public var respEntries: Int {
56-
start.respEntries + end.respEntries + unit.respEntries
54+
end.respEntries + unit.respEntries
5755
}
5856

5957
@inlinable
6058
public func encode(into commandEncoder: inout ValkeyCommandEncoder) {
61-
start.encode(into: &commandEncoder)
6259
end.encode(into: &commandEncoder)
6360
unit.encode(into: &commandEncoder)
6461
}
6562
}
63+
public struct Range: RESPRenderable, Sendable {
64+
@usableFromInline let start: Int
65+
@usableFromInline let endUnitBlock: RangeEndUnitBlock?
66+
67+
68+
@inlinable public init(start: Int, endUnitBlock: RangeEndUnitBlock? = nil) {
69+
self.start = start
70+
self.endUnitBlock = endUnitBlock
71+
}
72+
73+
@inlinable
74+
public var respEntries: Int {
75+
start.respEntries + endUnitBlock.respEntries
76+
}
77+
78+
@inlinable
79+
public func encode(into commandEncoder: inout ValkeyCommandEncoder) {
80+
start.encode(into: &commandEncoder)
81+
endUnitBlock.encode(into: &commandEncoder)
82+
}
83+
}
6684
public typealias Response = Int
6785

6886
public var key: ValkeyKey
@@ -229,7 +247,7 @@ public struct BITFIELD: ValkeyCommand {
229247
}
230248
}
231249
}
232-
public typealias Response = RESPToken.Array?
250+
public typealias Response = RESPToken.Array
233251

234252
public var key: ValkeyKey
235253
public var operation: [Operation]
@@ -269,7 +287,7 @@ public struct BITFIELDRO: ValkeyCommand {
269287
offset.encode(into: &commandEncoder)
270288
}
271289
}
272-
public typealias Response = RESPToken.Array
290+
public typealias Response = [Int]
273291

274292
public var key: ValkeyKey
275293
public var getBlock: [GetBlock]
@@ -450,8 +468,7 @@ extension ValkeyConnection {
450468
/// - Documentation: [BITCOUNT](https:/valkey.io/commands/bitcount)
451469
/// - Version: 2.6.0
452470
/// - Complexity: O(N)
453-
/// - Categories: @read, @bitmap, @slow
454-
/// - Returns: [Integer](https:/valkey.io/topics/protocol/#integers): the number of bits set to 1.
471+
/// - Returns: [Integer]: The number of bits set to 1.
455472
@inlinable
456473
public func bitcount(key: ValkeyKey, range: BITCOUNT.Range? = nil) async throws -> Int {
457474
try await send(command: BITCOUNT(key: key, range: range))
@@ -462,12 +479,11 @@ extension ValkeyConnection {
462479
/// - Documentation: [BITFIELD](https:/valkey.io/commands/bitfield)
463480
/// - Version: 3.2.0
464481
/// - Complexity: O(1) for each subcommand specified
465-
/// - Categories: @write, @bitmap, @slow
466-
/// - Returns: One of the following:
467-
/// * [Array](https:/valkey.io/topics/protocol/#arrays): each entry being the corresponding result of the sub-command given at the same position.
468-
/// * [Null](https:/valkey.io/topics/protocol/#nulls): if OVERFLOW FAIL was given and overflows or underflows are detected.
482+
/// - Returns: One of the following
483+
/// * [Array]: The result of the subcommand at the same position
484+
/// * [Array]: In case OVERFLOW FAIL was given and overflows or underflows detected
469485
@inlinable
470-
public func bitfield(key: ValkeyKey, operation: [BITFIELD.Operation] = []) async throws -> RESPToken.Array? {
486+
public func bitfield(key: ValkeyKey, operation: [BITFIELD.Operation] = []) async throws -> RESPToken.Array {
471487
try await send(command: BITFIELD(key: key, operation: operation))
472488
}
473489

@@ -476,10 +492,9 @@ extension ValkeyConnection {
476492
/// - Documentation: [BITFIELD_RO](https:/valkey.io/commands/bitfield_ro)
477493
/// - Version: 6.0.0
478494
/// - Complexity: O(1) for each subcommand specified
479-
/// - Categories: @read, @bitmap, @fast
480-
/// - Returns: [Array](https:/valkey.io/topics/protocol/#arrays): each entry being the corresponding result of the sub-command given at the same position.
495+
/// - Returns: [Array]: The result of the subcommand at the same position
481496
@inlinable
482-
public func bitfieldRo(key: ValkeyKey, getBlock: [BITFIELDRO.GetBlock] = []) async throws -> RESPToken.Array {
497+
public func bitfieldRo(key: ValkeyKey, getBlock: [BITFIELDRO.GetBlock] = []) async throws -> [Int] {
483498
try await send(command: BITFIELDRO(key: key, getBlock: getBlock))
484499
}
485500

@@ -488,8 +503,7 @@ extension ValkeyConnection {
488503
/// - Documentation: [BITOP](https:/valkey.io/commands/bitop)
489504
/// - Version: 2.6.0
490505
/// - Complexity: O(N)
491-
/// - Categories: @write, @bitmap, @slow
492-
/// - Returns: [Integer](https:/valkey.io/topics/protocol/#integers): the size of the string stored in the destination key is equal to the size of the longest input string.
506+
/// - Returns: [Integer]: The size of the string stored in the destination key, that is equal to the size of the longest input string.
493507
@inlinable
494508
public func bitop(operation: BITOP.Operation, destkey: ValkeyKey, key: [ValkeyKey]) async throws -> Int {
495509
try await send(command: BITOP(operation: operation, destkey: destkey, key: key))
@@ -500,19 +514,9 @@ extension ValkeyConnection {
500514
/// - Documentation: [BITPOS](https:/valkey.io/commands/bitpos)
501515
/// - Version: 2.8.7
502516
/// - Complexity: O(N)
503-
/// - Categories: @read, @bitmap, @slow
504-
/// - Returns: One of the following:
505-
/// * [Integer](https:/valkey.io/topics/protocol/#integers): the position of the first bit set to 1 or 0 according to the request
506-
/// * [Integer](https:/valkey.io/topics/protocol/#integers): `-1`. In case the `bit` argument is 1 and the string is empty or composed of just zero bytes
507-
///
508-
/// If we look for set bits (the bit argument is 1) and the string is empty or composed of just zero bytes, -1 is returned.
509-
///
510-
/// If we look for clear bits (the bit argument is 0) and the string only contains bits set to 1, the function returns the first bit not part of the string on the right. So if the string is three bytes set to the value `0xff` the command `BITPOS key 0` will return 24, since up to bit 23 all the bits are 1.
511-
///
512-
/// The function considers the right of the string as padded with zeros if you look for clear bits and specify no range or the _start_ argument **only**.
513-
///
514-
/// However, this behavior changes if you are looking for clear bits and specify a range with both _start_ and _end_.
515-
/// If a clear bit isn't found in the specified range, the function returns -1 as the user specified a clear range and there are no 0 bits in that range.
517+
/// - Returns: One of the following
518+
/// * [Integer]: The position of the first bit set to 1 or 0 according to the request.
519+
/// * -1: In case the `bit` argument is 1 and the string is empty or composed of just zero bytes.
516520
@inlinable
517521
public func bitpos(key: ValkeyKey, bit: Int, range: BITPOS.Range? = nil) async throws -> Int {
518522
try await send(command: BITPOS(key: key, bit: bit, range: range))
@@ -523,10 +527,7 @@ extension ValkeyConnection {
523527
/// - Documentation: [GETBIT](https:/valkey.io/commands/getbit)
524528
/// - Version: 2.2.0
525529
/// - Complexity: O(1)
526-
/// - Categories: @read, @bitmap, @fast
527-
/// - Returns: The bit value stored at _offset_, one of the following:
528-
/// * [Integer](https:/valkey.io/topics/protocol/#integers): `0`.
529-
/// * [Integer](https:/valkey.io/topics/protocol/#integers): `1`.
530+
/// - Returns: The bit value stored at offset.
530531
@inlinable
531532
public func getbit(key: ValkeyKey, offset: Int) async throws -> Int {
532533
try await send(command: GETBIT(key: key, offset: offset))
@@ -537,8 +538,7 @@ extension ValkeyConnection {
537538
/// - Documentation: [SETBIT](https:/valkey.io/commands/setbit)
538539
/// - Version: 2.2.0
539540
/// - Complexity: O(1)
540-
/// - Categories: @write, @bitmap, @slow
541-
/// - Returns: [Integer](https:/valkey.io/topics/protocol/#integers): the original bit value stored at _offset_.
541+
/// - Returns: The original bit value stored at offset.
542542
@inlinable
543543
public func setbit(key: ValkeyKey, offset: Int, value: Int) async throws -> Int {
544544
try await send(command: SETBIT(key: key, offset: offset, value: value))

0 commit comments

Comments
 (0)