@@ -18,17 +18,30 @@ import NIO
1818
1919extension RedisClient {
2020 /// 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.
2321 ///
2422 /// [https://redis.io/commands/get](https://redis.io/commands/get)
2523 /// - Parameter key: The key to fetch the value from.
2624 /// - Returns: The string value stored at the key provided, otherwise `nil` if the key does not exist.
2725 @inlinable
2826 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 ? > {
2942 let args = [ RESPValue ( bulk: key) ]
3043 return send ( command: " GET " , with: args)
31- . map { return $0 . string }
44+ . map { return StoredType ( fromRESP : $0 ) }
3245 }
3346
3447 /// Gets the values of all specified keys, using `.null` to represent non-existant values.
0 commit comments