@@ -293,6 +293,60 @@ extension RedisClient {
293
293
. map { $0 == 1 }
294
294
}
295
295
296
+ /// Sets a key to the provided value and an expiration timeout in seconds.
297
+ ///
298
+ /// See [https://redis.io/commands/setex](https://redis.io/commands/setex)
299
+ /// - Important: Regardless of the type of data stored at the key, it will be overwritten to a "string" data type.
300
+ ///
301
+ /// ie. If the key is a reference to a Sorted Set, its value will be overwritten to be a "string" data type.
302
+ /// - Important: The actual expiration used will be the specified value or `1`, whichever is larger.
303
+ /// - Parameters:
304
+ /// - key: The key to use to uniquely identify this value.
305
+ /// - value: The value to set the key to.
306
+ /// - expiration: The number of seconds after which to expire the key.
307
+ /// - Returns: A `NIO.EventLoopFuture` that resolves if the operation was successful.
308
+ @inlinable
309
+ public func setex< Value: RESPValueConvertible > (
310
+ _ key: RedisKey ,
311
+ to value: Value ,
312
+ expirationInSeconds expiration: Int
313
+ ) -> EventLoopFuture < Void > {
314
+ let args : [ RESPValue ] = [
315
+ . init( from: key) ,
316
+ . init( from: max ( 1 , expiration) ) ,
317
+ value. convertedToRESPValue ( )
318
+ ]
319
+ return self . send ( command: " SETEX " , with: args)
320
+ . map { _ in ( ) }
321
+ }
322
+
323
+ /// Sets a key to the provided value and an expiration timeout in milliseconds.
324
+ ///
325
+ /// See [https://redis.io/commands/psetex](https://redis.io/commands/psetex)
326
+ /// - Important: Regardless of the type of data stored at the key, it will be overwritten to a "string" data type.
327
+ ///
328
+ /// ie. If the key is a reference to a Sorted Set, its value will be overwritten to be a "string" data type.
329
+ /// - Important: The actual expiration used will be the specified value or `1`, whichever is larger.
330
+ /// - Parameters:
331
+ /// - key: The key to use to uniquely identify this value.
332
+ /// - value: The value to set the key to.
333
+ /// - expiration: The number of milliseconds after which to expire the key.
334
+ /// - Returns: A `NIO.EventLoopFuture` that resolves if the operation was successful.
335
+ @inlinable
336
+ public func psetex< Value: RESPValueConvertible > (
337
+ _ key: RedisKey ,
338
+ to value: Value ,
339
+ expirationInMilliseconds expiration: Int
340
+ ) -> EventLoopFuture < Void > {
341
+ let args : [ RESPValue ] = [
342
+ . init( from: key) ,
343
+ . init( from: max ( 1 , expiration) ) ,
344
+ value. convertedToRESPValue ( )
345
+ ]
346
+ return self . send ( command: " PSETEX " , with: args)
347
+ . map { _ in ( ) }
348
+ }
349
+
296
350
/// Sets each key to their respective new value, overwriting existing values.
297
351
/// - Note: Use `msetnx(_:)` if you don't want to overwrite values.
298
352
///
0 commit comments