@@ -25,6 +25,7 @@ extension RedisCommand {
25
25
/// - Parameters:
26
26
/// - key: The key of the list to pop from.
27
27
/// - timeout: The max time to wait for a value to use. `0`seconds means to wait indefinitely.
28
+ /// - Returns: The value popped from the list, otherwise `nil`.
28
29
public static func blpop( from key: RedisKey , timeout: TimeAmount = . seconds( 0 ) ) -> RedisCommand < RESPValue ? > {
29
30
return . _bpop( keyword: " BLPOP " , [ key] , timeout, { $0? . 1 } )
30
31
}
@@ -37,6 +38,7 @@ extension RedisCommand {
37
38
/// - Parameters:
38
39
/// - keys: The list of keys to pop from.
39
40
/// - timeout: The max time to wait for a value to use. `0`seconds means to wait indefinitely.
41
+ /// - Returns: The popped value and the key of its source list, otherwise `nil`.
40
42
public static func blpop(
41
43
from keys: [ RedisKey ] ,
42
44
timeout: TimeAmount = . seconds( 0 )
@@ -52,6 +54,7 @@ extension RedisCommand {
52
54
/// - Parameters:
53
55
/// - keys: The list of keys to pop from.
54
56
/// - timeout: The max time to wait for a value to use. `0`seconds means to wait indefinitely.
57
+ /// - Returns: The popped value and the key of its source list, otherwise `nil`.
55
58
public static func blpop(
56
59
from keys: RedisKey ... ,
57
60
timeout: TimeAmount = . seconds( 0 )
@@ -65,6 +68,7 @@ extension RedisCommand {
65
68
/// - Parameters:
66
69
/// - key: The key of the list to pop from.
67
70
/// - timeout: The max time to wait for a value to use. `0`seconds means to wait indefinitely.
71
+ /// - Returns: The value popped from the list, otherwise `nil`.
68
72
public static func brpop( from key: RedisKey , timeout: TimeAmount = . seconds( 0 ) ) -> RedisCommand < RESPValue ? > {
69
73
return . _bpop( keyword: " BRPOP " , [ key] , timeout, { $0? . 1 } )
70
74
}
@@ -77,6 +81,7 @@ extension RedisCommand {
77
81
/// - Parameters:
78
82
/// - key: The key of the list to pop from.
79
83
/// - timeout: The max time to wait for a value to use. `0`seconds means to wait indefinitely.
84
+ /// - Returns: The popped value and the key of its source list, otherwise `nil`.
80
85
public static func brpop( from keys: [ RedisKey ] , timeout: TimeAmount = . seconds( 0 ) ) -> RedisCommand < ( RedisKey , RESPValue ) ? > {
81
86
return . _bpop( keyword: " BRPOP " , keys, timeout, { $0 } )
82
87
}
@@ -89,6 +94,7 @@ extension RedisCommand {
89
94
/// - Parameters:
90
95
/// - key: The key of the list to pop from.
91
96
/// - timeout: The max time to wait for a value to use. `0`seconds means to wait indefinitely.
97
+ /// - Returns: The popped value and the key of its source list, otherwise `nil`.
92
98
public static func brpop(
93
99
from keys: RedisKey ... ,
94
100
timeout: TimeAmount = . seconds( 0 )
@@ -103,23 +109,26 @@ extension RedisCommand {
103
109
/// - source: The key of the list to pop from.
104
110
/// - dest: The key of the list to push to.
105
111
/// - timeout: The max time to wait for a value to use. `0` seconds means to wait indefinitely.
112
+ /// - Returns: The value removed from the `source`, otherwise `nil`.
106
113
public static func brpoplpush(
107
114
from source: RedisKey ,
108
115
to dest: RedisKey ,
109
116
timeout: TimeAmount = . seconds( 0 )
110
117
) -> RedisCommand < RESPValue ? > {
118
+ assert ( timeout >= . seconds( 0 ) , " anything smaller than a second will be treated as 0 seconds " )
111
119
let args : [ RESPValue ] = [
112
120
. init( from: source) ,
113
121
. init( from: dest) ,
114
122
. init( from: timeout. seconds)
115
123
]
116
- return . init( keyword: " BRPOPLPUSH " , arguments: args)
124
+ return . init( keyword: " BRPOPLPUSH " , arguments: args, mapValueToResult : { try ? $0 . map ( ) } )
117
125
}
118
126
119
127
/// [LINDEX](https://redis.io/commands/lindex)
120
128
/// - Parameters:
121
129
/// - index: The 0-based index of the element to get.
122
130
/// - key: The key of the list.
131
+ /// - Returns: The value stored at the index, otherwise `nil`.
123
132
public static func lindex( _ index: Int , from key: RedisKey ) -> RedisCommand < RESPValue ? > {
124
133
let args : [ RESPValue ] = [
125
134
. init( from: key) ,
@@ -161,6 +170,7 @@ extension RedisCommand {
161
170
162
171
/// [LPOP](https://redis.io/commands/lpop)
163
172
/// - Parameter key: The key of the list to pop from.
173
+ /// - Returns: The value popped from the list, otherwise `nil`.
164
174
public static func lpop( from key: RedisKey ) -> RedisCommand < RESPValue ? > {
165
175
let args = [ RESPValue ( from: key) ]
166
176
return . init( keyword: " LPOP " , arguments: args) { try ? $0. map ( ) }
@@ -472,6 +482,7 @@ extension RedisCommand {
472
482
473
483
/// [RPOP](https://redis.io/commands/rpop)
474
484
/// - Parameter key: The key of the list to pop from.
485
+ /// - Returns: The value popped from the list, otherwise `nil`.
475
486
public static func rpop( from key: RedisKey ) -> RedisCommand < RESPValue ? > {
476
487
let args = [ RESPValue ( from: key) ]
477
488
return . init( keyword: " RPOP " , arguments: args) { try ? $0. map ( ) }
@@ -481,12 +492,13 @@ extension RedisCommand {
481
492
/// - Parameters:
482
493
/// - source: The key of the list to pop from.
483
494
/// - dest: The key of the list to push to.
495
+ /// - Returns: The value removed from the `source`, otherwise `nil`.
484
496
public static func rpoplpush( from source: RedisKey , to dest: RedisKey ) -> RedisCommand < RESPValue ? > {
485
497
let args : [ RESPValue ] = [
486
498
. init( from: source) ,
487
499
. init( from: dest)
488
500
]
489
- return . init( keyword: " RPOPLPUSH " , arguments: args)
501
+ return . init( keyword: " RPOPLPUSH " , arguments: args, mapValueToResult : { try ? $0 . map ( ) } )
490
502
}
491
503
492
504
/// [RPUSH](https://redis.io/commands/rpush)
@@ -537,6 +549,8 @@ extension RedisCommand {
537
549
_ timeout: TimeAmount ,
538
550
_ transform: @escaping ( ( RedisKey , RESPValue ) ? ) throws -> ResultType ?
539
551
) -> RedisCommand < ResultType ? > {
552
+ assert ( timeout >= . seconds( 0 ) , " anything smaller than a second will be treated as 0 seconds " )
553
+
540
554
var args = keys. map ( RESPValue . init ( from: ) )
541
555
args. append ( . init( bulk: timeout. seconds) )
542
556
0 commit comments