File tree Expand file tree Collapse file tree 3 files changed +25
-0
lines changed Expand file tree Collapse file tree 3 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -1110,6 +1110,18 @@ def getset(key, value)
1110
1110
end
1111
1111
end
1112
1112
1113
+ # Get the value of key and delete the key. This command is similar to GET,
1114
+ # except for the fact that it also deletes the key on success.
1115
+ #
1116
+ # @param [String] key
1117
+ # @return [String] the old value stored in the key, or `nil` if the key
1118
+ # did not exist
1119
+ def getdel ( key )
1120
+ synchronize do |client |
1121
+ client . call ( [ :getdel , key ] )
1122
+ end
1123
+ end
1124
+
1113
1125
# Get the length of the value stored in a key.
1114
1126
#
1115
1127
# @param [String] key
Original file line number Diff line number Diff line change @@ -316,6 +316,11 @@ def get(key)
316
316
node_for ( key ) . get ( key )
317
317
end
318
318
319
+ # Get the value of a key and delete it.
320
+ def getdel ( key )
321
+ node_for ( key ) . getdel ( key )
322
+ end
323
+
319
324
# Get the values of all the given keys as an Array.
320
325
def mget ( *keys )
321
326
mapped_mget ( *keys ) . values_at ( *keys )
Original file line number Diff line number Diff line change @@ -115,6 +115,14 @@ def test_psetex_with_non_string_value
115
115
end
116
116
end
117
117
118
+ def test_getdel
119
+ target_version "6.2" do
120
+ assert r . set ( "foo" , "bar" )
121
+ assert_equal "bar" , r . getdel ( "foo" )
122
+ assert_equal nil , r . get ( "foo" )
123
+ end
124
+ end
125
+
118
126
def test_getset
119
127
r . set ( "foo" , "bar" )
120
128
You can’t perform that action at this time.
0 commit comments