File tree Expand file tree Collapse file tree 3 files changed +42
-14
lines changed Expand file tree Collapse file tree 3 files changed +42
-14
lines changed Original file line number Diff line number Diff line change @@ -1172,23 +1172,29 @@ def rpushx(key, value)
1172
1172
end
1173
1173
end
1174
1174
1175
- # Remove and get the first element in a list.
1175
+ # Remove and get the first elements in a list.
1176
1176
#
1177
1177
# @param [String] key
1178
- # @return [String]
1179
- def lpop ( key )
1178
+ # @param [Integer] count number of elements to remove
1179
+ # @return [String, Array<String>] the values of the first elements
1180
+ def lpop ( key , count = nil )
1180
1181
synchronize do |client |
1181
- client . call ( [ :lpop , key ] )
1182
+ command = [ :lpop , key ]
1183
+ command << count if count
1184
+ client . call ( command )
1182
1185
end
1183
1186
end
1184
1187
1185
- # Remove and get the last element in a list.
1188
+ # Remove and get the last elements in a list.
1186
1189
#
1187
1190
# @param [String] key
1188
- # @return [String]
1189
- def rpop ( key )
1191
+ # @param [Integer] count number of elements to remove
1192
+ # @return [String, Array<String>] the values of the last elements
1193
+ def rpop ( key , count = nil )
1190
1194
synchronize do |client |
1191
- client . call ( [ :rpop , key ] )
1195
+ command = [ :rpop , key ]
1196
+ command << count if count
1197
+ client . call ( command )
1192
1198
end
1193
1199
end
1194
1200
Original file line number Diff line number Diff line change @@ -413,14 +413,14 @@ def rpushx(key, value)
413
413
node_for ( key ) . rpushx ( key , value )
414
414
end
415
415
416
- # Remove and get the first element in a list.
417
- def lpop ( key )
418
- node_for ( key ) . lpop ( key )
416
+ # Remove and get the first elements in a list.
417
+ def lpop ( key , count = nil )
418
+ node_for ( key ) . lpop ( key , count )
419
419
end
420
420
421
- # Remove and get the last element in a list.
422
- def rpop ( key )
423
- node_for ( key ) . rpop ( key )
421
+ # Remove and get the last elements in a list.
422
+ def rpop ( key , count = nil )
423
+ node_for ( key ) . rpop ( key , count )
424
424
end
425
425
426
426
# Remove the last element in a list, append it to another list and return
Original file line number Diff line number Diff line change @@ -119,6 +119,17 @@ def test_lpop
119
119
assert_equal 1 , r . llen ( "foo" )
120
120
end
121
121
122
+ def test_lpop_count
123
+ target_version ( "6.2" ) do
124
+ r . rpush "foo" , "s1"
125
+ r . rpush "foo" , "s2"
126
+
127
+ assert_equal 2 , r . llen ( "foo" )
128
+ assert_equal [ "s1" , "s2" ] , r . lpop ( "foo" , 2 )
129
+ assert_equal 0 , r . llen ( "foo" )
130
+ end
131
+ end
132
+
122
133
def test_rpop
123
134
r . rpush "foo" , "s1"
124
135
r . rpush "foo" , "s2"
@@ -128,6 +139,17 @@ def test_rpop
128
139
assert_equal 1 , r . llen ( "foo" )
129
140
end
130
141
142
+ def test_rpop_count
143
+ target_version ( "6.2" ) do
144
+ r . rpush "foo" , "s1"
145
+ r . rpush "foo" , "s2"
146
+
147
+ assert_equal 2 , r . llen ( "foo" )
148
+ assert_equal [ "s2" , "s1" ] , r . rpop ( "foo" , 2 )
149
+ assert_equal 0 , r . llen ( "foo" )
150
+ end
151
+ end
152
+
131
153
def test_linsert
132
154
r . rpush "foo" , "s1"
133
155
r . rpush "foo" , "s3"
You can’t perform that action at this time.
0 commit comments