@@ -128,11 +128,12 @@ type Client struct {
128
128
// maybeOpenNewConnections sends on the chan (one send per needed connection)
129
129
// It is closed during client.Quit(). The close tells the connectionOpener
130
130
// goroutine to exit.
131
- openerCh chan struct {}
132
- maxLifetime time.Duration // maximum amount of time a connection may be reused
133
- maxOpen int // maximum amount of connection num. maxOpen <= 0 means unlimited. default is 1.
134
- cleanerCh chan struct {}
135
- closed bool
131
+ openerCh chan struct {}
132
+ maxLifetime time.Duration // maximum amount of time a connection may be reused
133
+ maxOpen int // maximum amount of connection num. maxOpen <= 0 means unlimited. default is 1.
134
+ cleanerCh chan struct {}
135
+ closed bool
136
+ flushAllEnabled bool
136
137
}
137
138
138
139
// connRequest represents one request for a new connection
@@ -216,6 +217,7 @@ func New(servers []string, noreply bool, prefix string, hashFunc int, failover b
216
217
client .disableLock = disableLock
217
218
client .hashFunc = hashFunc
218
219
client .failover = failover
220
+ client .flushAllEnabled = false
219
221
220
222
client .openerCh = make (chan struct {}, connectionRequestQueueSize )
221
223
client .connRequests = make (map [uint64 ]chan connRequest )
@@ -1393,12 +1395,7 @@ func (client *Client) Stats() (map[string](map[string]string), error) {
1393
1395
1394
1396
// Enable/Disable the flush_all feature
1395
1397
func (client * Client ) ToggleFlushAllFeature (enabled bool ) {
1396
- client .lk .Lock ()
1397
- for i := 0 ; i < len (client .freeConns ); i ++ {
1398
- cn := client .freeConns [i ]
1399
- C .client_toggle_flush_all_feature (cn ._imp , C .bool (enabled ))
1400
- }
1401
- client .lk .Unlock ()
1398
+ client .flushAllEnabled = enabled
1402
1399
}
1403
1400
1404
1401
// FlushAll will flush all memcached servers
@@ -1410,6 +1407,9 @@ func (client *Client) FlushAll() ([]string, error) {
1410
1407
flushedHosts := []string {}
1411
1408
1412
1409
cn , err := client .conn (context .Background ())
1410
+ C .client_toggle_flush_all_feature (
1411
+ cn ._imp , C .bool (client .flushAllEnabled ),
1412
+ )
1413
1413
if err != nil {
1414
1414
return flushedHosts , err
1415
1415
}
@@ -1431,6 +1431,11 @@ func (client *Client) FlushAll() ([]string, error) {
1431
1431
}
1432
1432
1433
1433
if errCode != C .RET_OK {
1434
+ if errCode == C .RET_PROGRAMMING_ERR {
1435
+ return flushedHosts , errors .New (
1436
+ "client.ToggleFlushAllFeature(true) to enable flush_all" ,
1437
+ )
1438
+ }
1434
1439
return flushedHosts , networkError (errorMessage (errCode ))
1435
1440
}
1436
1441
0 commit comments