File tree Expand file tree Collapse file tree 2 files changed +56
-4
lines changed Expand file tree Collapse file tree 2 files changed +56
-4
lines changed Original file line number Diff line number Diff line change @@ -226,19 +226,31 @@ def debug(*args)
226
226
227
227
# Remove all keys from all databases.
228
228
#
229
+ # @param [Hash] options
230
+ # - `:async => Boolean`: async flush (default: false)
229
231
# @return [String] `OK`
230
- def flushall
232
+ def flushall ( options = nil )
231
233
synchronize do |client |
232
- client . call ( [ :flushall ] )
234
+ if options && options [ :async ]
235
+ client . call ( [ :flushall , :async ] )
236
+ else
237
+ client . call ( [ :flushall ] )
238
+ end
233
239
end
234
240
end
235
241
236
242
# Remove all keys from the current database.
237
243
#
244
+ # @param [Hash] options
245
+ # - `:async => Boolean`: async flush (default: false)
238
246
# @return [String] `OK`
239
- def flushdb
247
+ def flushdb ( options = nil )
240
248
synchronize do |client |
241
- client . call ( [ :flushdb ] )
249
+ if options && options [ :async ]
250
+ client . call ( [ :flushdb , :async ] )
251
+ else
252
+ client . call ( [ :flushdb ] )
253
+ end
242
254
end
243
255
end
244
256
Original file line number Diff line number Diff line change @@ -81,6 +81,7 @@ def test_dbsize
81
81
end
82
82
83
83
def test_flushdb
84
+ # Test defaults
84
85
r . set ( "foo" , "s1" )
85
86
r . set ( "bar" , "s2" )
86
87
@@ -89,12 +90,51 @@ def test_flushdb
89
90
r . flushdb
90
91
91
92
assert_equal 0 , r . dbsize
93
+
94
+ # Test sync
95
+ r . set ( "foo" , "s1" )
96
+ r . set ( "bar" , "s2" )
97
+
98
+ assert_equal 2 , r . dbsize
99
+
100
+ r . flushdb ( :async => false )
101
+
102
+ assert_equal 0 , r . dbsize
103
+
104
+ # Test async
105
+ target_version "3.9.101" do
106
+ r . set ( "foo" , "s1" )
107
+ r . set ( "bar" , "s2" )
108
+
109
+ assert_equal 2 , r . dbsize
110
+
111
+ r . flushdb ( :async => true )
112
+
113
+ assert_equal 0 , r . dbsize
114
+
115
+ redis_mock ( :flushdb => lambda { |args | "+FLUSHDB #{ args . upcase } " } ) do |redis |
116
+ assert_equal "FLUSHDB ASYNC" , redis . flushdb ( :async => true )
117
+ end
118
+ end
92
119
end
93
120
94
121
def test_flushall
122
+ # Test defaults
95
123
redis_mock ( :flushall => lambda { "+FLUSHALL" } ) do |redis |
96
124
assert_equal "FLUSHALL" , redis . flushall
97
125
end
126
+
127
+ # Test sync
128
+ redis_mock ( :flushall => lambda { "+FLUSHALL" } ) do |redis |
129
+ assert_equal "FLUSHALL" , redis . flushall ( :async => false )
130
+ end
131
+
132
+ # Test async
133
+ target_version "3.9.101" do
134
+ redis_mock ( :flushall => lambda { |args | "+FLUSHALL #{ args . upcase } " } ) do |redis |
135
+ assert_equal "FLUSHALL ASYNC" , redis . flushall ( :async => true )
136
+ end
137
+ end
98
138
end
99
139
100
140
def test_migrate
You can’t perform that action at this time.
0 commit comments