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