Skip to content

Commit 64d0d01

Browse files
committed
Fix up some optional return types
1 parent 1e9d693 commit 64d0d01

File tree

11 files changed

+45
-34
lines changed

11 files changed

+45
-34
lines changed

Sources/RedisCommands/BitmapCommands.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
// This file is autogenerated by RedisCommandsBuilder
1616

1717
import NIOCore
18-
import RESP
1918
import Redis
19+
import RESP
2020

2121
#if canImport(FoundationEssentials)
2222
import FoundationEssentials
@@ -302,13 +302,13 @@ extension RESPCommand {
302302
/// - Response: One of the following:
303303
/// * [Integer](https:/redis.io/docs/reference/protocol-spec#integers): the position of the first bit set to 1 or 0 according to the request
304304
/// * [Integer](https:/redis.io/docs/reference/protocol-spec#integers): `-1`. In case the `bit` argument is 1 and the string is empty or composed of just zero bytes
305-
///
305+
///
306306
/// 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.
307-
///
307+
///
308308
/// 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.
309-
///
309+
///
310310
/// 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**.
311-
///
311+
///
312312
/// However, this behavior changes if you are looking for clear bits and specify a range with both _start_ and _end_.
313313
/// 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.
314314
@inlinable
@@ -442,13 +442,13 @@ extension RedisConnection {
442442
/// - Returns: One of the following:
443443
/// * [Integer](https:/redis.io/docs/reference/protocol-spec#integers): the position of the first bit set to 1 or 0 according to the request
444444
/// * [Integer](https:/redis.io/docs/reference/protocol-spec#integers): `-1`. In case the `bit` argument is 1 and the string is empty or composed of just zero bytes
445-
///
445+
///
446446
/// 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.
447-
///
447+
///
448448
/// 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.
449-
///
449+
///
450450
/// 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**.
451-
///
451+
///
452452
/// However, this behavior changes if you are looking for clear bits and specify a range with both _start_ and _end_.
453453
/// 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.
454454
@inlinable

Sources/RedisCommands/ConnectionCommands.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ extension RedisConnection {
798798
/// - Returns: [Map](https:/redis.io/docs/reference/protocol-spec#maps): a list of tracking information sections and their respective values.
799799
@inlinable
800800
public func clientTrackinginfo() async throws -> RESPToken {
801-
try await send("CLIENT", "TRACKINGINFO").converting()
801+
try await send("CLIENT", "TRACKINGINFO")
802802
}
803803

804804
/// Unblocks a client blocked by a blocking command from a different connection.

Sources/RedisCommands/GenericCommands.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -903,8 +903,8 @@ extension RedisConnection {
903903
/// [Integer](https:/redis.io/docs/reference/protocol-spec#integers): the counter's value.
904904
/// [Null](https:/redis.io/docs/reference/protocol-spec#nulls): if _key_ doesn't exist.
905905
@inlinable
906-
public func objectFreq(key: RedisKey) async throws -> RESPToken {
907-
try await send("OBJECT", "FREQ", key)
906+
public func objectFreq(key: RedisKey) async throws -> Int? {
907+
try await send("OBJECT", "FREQ", key).converting()
908908
}
909909

910910
/// Returns helpful text about the different subcommands.
@@ -929,8 +929,8 @@ extension RedisConnection {
929929
/// [Integer](https:/redis.io/docs/reference/protocol-spec#integers): the idle time in seconds.
930930
/// [Null](https:/redis.io/docs/reference/protocol-spec#nulls): if _key_ doesn't exist.
931931
@inlinable
932-
public func objectIdletime(key: RedisKey) async throws -> RESPToken {
933-
try await send("OBJECT", "IDLETIME", key)
932+
public func objectIdletime(key: RedisKey) async throws -> Int? {
933+
try await send("OBJECT", "IDLETIME", key).converting()
934934
}
935935

936936
/// Returns the reference count of a value of a key.
@@ -943,8 +943,8 @@ extension RedisConnection {
943943
/// [Integer](https:/redis.io/docs/reference/protocol-spec#integers): the number of references.
944944
/// [Null](https:/redis.io/docs/reference/protocol-spec#nulls): if _key_ doesn't exist.
945945
@inlinable
946-
public func objectRefcount(key: RedisKey) async throws -> RESPToken {
947-
try await send("OBJECT", "REFCOUNT", key)
946+
public func objectRefcount(key: RedisKey) async throws -> Int? {
947+
try await send("OBJECT", "REFCOUNT", key).converting()
948948
}
949949

950950
/// Removes the expiration time of a key.

Sources/RedisCommands/HashCommands.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ extension RedisConnection {
377377
/// - Returns: [Map](https:/redis.io/docs/reference/protocol-spec#maps): a map of fields and their values stored in the hash, or an empty list when key does not exist.
378378
@inlinable
379379
public func hgetall(key: RedisKey) async throws -> RESPToken {
380-
try await send("HGETALL", key).converting()
380+
try await send("HGETALL", key)
381381
}
382382

383383
/// Increments the integer value of a field in a hash by a number. Uses 0 as initial value if the field doesn't exist.

Sources/RedisCommands/ScriptingCommands.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ extension RedisConnection {
665665
/// - Returns: [Map](https:/redis.io/docs/reference/protocol-spec#maps): information about the function that's currently running and information about the available execution engines.
666666
@inlinable
667667
public func functionStats() async throws -> RESPToken {
668-
try await send("FUNCTION", "STATS").converting()
668+
try await send("FUNCTION", "STATS")
669669
}
670670

671671
/// Sets the debug mode of server-side Lua scripts.

Sources/RedisCommands/ServerCommands.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,7 +1491,7 @@ extension RedisConnection {
14911491
/// - Returns: [Map](https:/redis.io/docs/reference/protocol-spec#maps): a map where each key is a command name, and each value is the documentary information.
14921492
@inlinable
14931493
public func commandDocs(commandName: String? = nil) async throws -> RESPToken {
1494-
try await send("COMMAND", "DOCS", commandName).converting()
1494+
try await send("COMMAND", "DOCS", commandName)
14951495
}
14961496

14971497
/// Returns documentary information about one, multiple or all commands.
@@ -1503,7 +1503,7 @@ extension RedisConnection {
15031503
/// - Returns: [Map](https:/redis.io/docs/reference/protocol-spec#maps): a map where each key is a command name, and each value is the documentary information.
15041504
@inlinable
15051505
public func commandDocs(commandNames: [String]) async throws -> RESPToken {
1506-
try await send("COMMAND", "DOCS", commandNames).converting()
1506+
try await send("COMMAND", "DOCS", commandNames)
15071507
}
15081508

15091509
/// Extracts the key names from an arbitrary command.
@@ -1611,7 +1611,7 @@ extension RedisConnection {
16111611
/// - Returns: [Map](https:/redis.io/docs/reference/protocol-spec#maps): a list of configuration parameters matching the provided arguments.
16121612
@inlinable
16131613
public func configGet(parameter: String) async throws -> RESPToken {
1614-
try await send("CONFIG", "GET", parameter).converting()
1614+
try await send("CONFIG", "GET", parameter)
16151615
}
16161616

16171617
/// Returns the effective values of configuration parameters.
@@ -1623,7 +1623,7 @@ extension RedisConnection {
16231623
/// - Returns: [Map](https:/redis.io/docs/reference/protocol-spec#maps): a list of configuration parameters matching the provided arguments.
16241624
@inlinable
16251625
public func configGet(parameters: [String]) async throws -> RESPToken {
1626-
try await send("CONFIG", "GET", parameters).converting()
1626+
try await send("CONFIG", "GET", parameters)
16271627
}
16281628

16291629
/// Returns helpful text about the different subcommands.
@@ -1819,7 +1819,7 @@ extension RedisConnection {
18191819
/// - Returns: [Map](https:/redis.io/docs/reference/protocol-spec#maps): a map where each key is a command name, and each value is a map with the total calls, and an inner map of the histogram time buckets.
18201820
@inlinable
18211821
public func latencyHistogram(command: String? = nil) async throws -> RESPToken {
1822-
try await send("LATENCY", "HISTOGRAM", command).converting()
1822+
try await send("LATENCY", "HISTOGRAM", command)
18231823
}
18241824

18251825
/// Returns the cumulative distribution of latencies of a subset or all commands.
@@ -1831,7 +1831,7 @@ extension RedisConnection {
18311831
/// - Returns: [Map](https:/redis.io/docs/reference/protocol-spec#maps): a map where each key is a command name, and each value is a map with the total calls, and an inner map of the histogram time buckets.
18321832
@inlinable
18331833
public func latencyHistogram(commands: [String]) async throws -> RESPToken {
1834-
try await send("LATENCY", "HISTOGRAM", commands).converting()
1834+
try await send("LATENCY", "HISTOGRAM", commands)
18351835
}
18361836

18371837
/// Returns timestamp-latency samples for an event.
@@ -1950,7 +1950,7 @@ extension RedisConnection {
19501950
/// - Returns: [Map](https:/redis.io/docs/reference/protocol-spec#maps): memory usage metrics and their values.
19511951
@inlinable
19521952
public func memoryStats() async throws -> RESPToken {
1953-
try await send("MEMORY", "STATS").converting()
1953+
try await send("MEMORY", "STATS")
19541954
}
19551955

19561956
/// Estimates the memory usage of a key.

Sources/RedisCommands/SortedSetCommands.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,8 +1450,8 @@ extension RedisConnection {
14501450
/// * [Double](https:/redis.io/docs/reference/protocol-spec#doubles): the score of the member (a double-precision floating point number).
14511451
/// * [Nil](https:/redis.io/docs/reference/protocol-spec#bulk-strings): if _member_ does not exist in the sorted set, or the key does not exist.
14521452
@inlinable
1453-
public func zscore(key: RedisKey, member: String) async throws -> RESPToken {
1454-
try await send("ZSCORE", key, member)
1453+
public func zscore(key: RedisKey, member: String) async throws -> Double? {
1454+
try await send("ZSCORE", key, member).converting()
14551455
}
14561456

14571457
/// Returns the union of multiple sorted sets.

Sources/RedisCommands/StreamCommands.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ extension RedisConnection {
800800
/// * [Map](https:/redis.io/docs/reference/protocol-spec#maps): when the _FULL_ argument was given, a list of information about a stream in extended form.
801801
@inlinable
802802
public func xinfoStream(key: RedisKey, fullBlock: RESPCommand.XINFOSTREAMFullBlock? = nil) async throws -> RESPToken {
803-
try await send("XINFO", "STREAM", key, fullBlock).converting()
803+
try await send("XINFO", "STREAM", key, fullBlock)
804804
}
805805

806806
/// Return the number of messages in a stream.

Sources/RedisCommands/StringCommands.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,8 +493,8 @@ extension RedisConnection {
493493
/// - Returns: [Bulk string](https:/redis.io/docs/reference/protocol-spec#bulk-strings): the value of `key`
494494
/// [Null](https:/redis.io/docs/reference/protocol-spec#nulls): if `key` does not exist.
495495
@inlinable
496-
public func getex(key: RedisKey, expiration: RESPCommand.GETEXExpiration? = nil) async throws -> RESPToken {
497-
try await send("GETEX", key, expiration)
496+
public func getex(key: RedisKey, expiration: RESPCommand.GETEXExpiration? = nil) async throws -> String? {
497+
try await send("GETEX", key, expiration).converting()
498498
}
499499

500500
/// Returns a substring of the string stored at a key.

Sources/RedisCommandsBuilder/RedisCommandsRender.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,13 @@ extension String {
157157
let arguments = (command.arguments ?? [])
158158
var converting: Bool = false
159159
var returnType: String = " -> RESPToken"
160+
if name == "OBJECT REFCOUNT" {
161+
print("sdf")
162+
}
160163
if let type = getReturnType(reply: reply) {
161164
if type == "Void" {
162165
returnType = ""
163-
} else {
166+
} else if type != "RESPToken" {
164167
converting = true
165168
returnType = " -> \(type)"
166169
}
@@ -286,10 +289,10 @@ private func getReturnType(reply replies: [String]) -> String? {
286289
if replies.count == 1 {
287290
return getReturnType(reply: replies[0])
288291
} else if replies.count > 1 {
289-
var returnType = getReturnType(reply: replies[0].dropFirst(2))
292+
var returnType = getReturnType(reply: replies[0].dropPrefix("* "))
290293
var `optional` = false
291294
for value in replies.dropFirst(1) {
292-
if let returnType2 = getReturnType(reply: value.dropFirst(2)) {
295+
if let returnType2 = getReturnType(reply: value.dropPrefix("* ")) {
293296
if returnType == "Void" {
294297
returnType = returnType2
295298
optional = true
@@ -333,7 +336,7 @@ private func getReturnType(reply: some StringProtocol) -> String? {
333336
}
334337
}
335338
return "[RESPToken]"
336-
} else if reply.hasPrefix("[Null") {
339+
} else if reply.hasPrefix("[Null") || reply.hasPrefix("[Nil") {
337340
return "Void"
338341
} else if reply.hasPrefix("[Simple error") {
339342
return nil

0 commit comments

Comments
 (0)