FLUSHALL [ASYNC | SYNC]
@keyspace,
@write,
@slow,
@dangerous,
Delete all the keys of all the existing databases, not just the currently selected one. This command never fails.
By default, FLUSHALL will synchronously flush all the databases.
Starting with Redis 6.2, setting the lazyfree-lazy-user-flush configuration directive to "yes" changes the default flush mode to asynchronous.
It is possible to use one of the following modifiers to dictate the flushing mode explicitly:
ASYNC: flushes the databases asynchronouslySYNC: flushes the databases synchronouslyFLUSHALL SYNCimport redis
r = redis.Redis(decode_responses=True)
res1 = r.flushall(asynchronous=False)
print(res1) # >>> True
res2 = r.keys()
print(res2) # >>> []
res3 = r.info()
print(res3)
# >>> {'redis_version': '7.4.0', 'redis_git_sha1': 'c9d29f6a',...}
import { createClient } from 'redis';
const client = createClient();
await client.connect().catch(console.error);
const res1 = await client.flushAll('SYNC'); // or ASYNC
console.log(res1); // OK
const res2 = await client.keys('*');
console.log(res2); // []
const res3 = await client.info();
console.log(res3)
// # Server
// redis_version:7.4.0
// redis_git_sha1:c9d29f6a
// redis_git_dirty:0
// redis_build_id:4c367a16e3f9616
// redis_mode:standalone
// ...
await client.close();
importjava.util.Set;importredis.clients.jedis.Jedis;importredis.clients.jedis.UnifiedJedis;import staticorg.junit.jupiter.api.Assertions.assertEquals;publicclass CmdsServerMgmtExample{publicvoidrun(){UnifiedJedisjedis=newUnifiedJedis("redis://localhost:6379");StringflushAllResult1=jedis.flushAll();System.out.println(flushAllResult1);// >>> OKSet<String>flushAllResult2=jedis.keys("*");System.out.println(flushAllResult2);// >>> []// Note: you must use the `Jedis` class to access the `info`// command rather than `UnifiedJedis`.Jedisjedis2=newJedis("redis://localhost:6379");StringinfoResult=jedis2.info();// Check the first 8 characters of the result (the full `info` string// is much longer than this).System.out.println(infoResult.substring(0,8));// >>> # Serverjedis2.close();jedis.close();}}package example_commands_test
import (
"context"
"fmt"
"github.com/redis/go-redis/v9"
)
func ExampleClient_cmd_flushall() {
ctx := context.Background()
rdb := redis.NewClient(&redis.Options{
Addr: "localhost:6379",
Password: "", // no password docs
DB: 0, // use default DB
})
flushAllResult1, err := rdb.FlushAll(ctx).Result()
if err != nil {
panic(err)
}
fmt.Println(flushAllResult1) // >>> OK
flushAllResult2, err := rdb.Keys(ctx, "*").Result()
if err != nil {
panic(err)
}
fmt.Println(flushAllResult2) // >>> []
}
func ExampleClient_cmd_info() {
ctx := context.Background()
rdb := redis.NewClient(&redis.Options{
Addr: "localhost:6379",
Password: "", // no password docs
DB: 0, // use default DB
})
infoResult, err := rdb.Info(ctx).Result()
if err != nil {
panic(err)
}
// Check the first 8 characters (the full info string contains
// much more text than this).
fmt.Println(infoResult[:8]) // >>> # Server
}
FLUSHALL command only deletes keys that were present at the time the command was invoked. Keys created during an asynchronous flush will be unaffected.FLUSHDB), this command clears the RDB persistence file, aborts any snapshot that is in progress, and, if the save config is enabled, saves an empty RDB file.>= 6.2.0: Default flush behavior now configurable by the lazyfree-lazy-user-flush configuration directive.| Redis Enterprise |
Redis Cloud |
Notes |
|---|---|---|
| ✅ Standard ❌ Active-Active* |
✅ Standard ❌ Active-Active |
*Can use the Active-Active flush API request. |
OK.
ASYNC flushing mode modifier.SYNC flushing mode modifier.