@@ -18,17 +18,30 @@ import NIO
18
18
19
19
extension RedisClient {
20
20
/// Get the value of a key.
21
- /// - Note: This operation only works with string values.
22
- /// The `EventLoopFuture` will fail with a `RedisError` if the value is not a string, such as a Set.
23
21
///
24
22
/// [https://redis.io/commands/get](https://redis.io/commands/get)
25
23
/// - Parameter key: The key to fetch the value from.
26
24
/// - Returns: The string value stored at the key provided, otherwise `nil` if the key does not exist.
27
25
@inlinable
28
26
public func get( _ key: String ) -> EventLoopFuture < String ? > {
27
+ return self . get ( key, as: String . self)
28
+ }
29
+
30
+ /// Get the value of a key, converting it to the desired type.
31
+ ///
32
+ /// [https://redis.io/commands/get](https://redis.io/commands/get)
33
+ /// - Parameters:
34
+ /// - key: The key to fetch the value from.
35
+ /// - type: The desired type to convert the stored data to.
36
+ /// - Returns: The converted value stored at the key provided, otherwise `nil` if the key does not exist or fails the conversion.
37
+ @inlinable
38
+ public func get< StoredType: RESPValueConvertible > (
39
+ _ key: String ,
40
+ as type: StoredType . Type
41
+ ) -> EventLoopFuture < StoredType ? > {
29
42
let args = [ RESPValue ( bulk: key) ]
30
43
return send ( command: " GET " , with: args)
31
- . map { return $0 . string }
44
+ . map { return StoredType ( fromRESP : $0 ) }
32
45
}
33
46
34
47
/// Gets the values of all specified keys, using `.null` to represent non-existant values.
0 commit comments