FLUSHALL
FLUSHALL [ASYNC | SYNC]
- Available since:
- Redis Open Source 1.0.0
- Time complexity:
- O(N) where N is the total number of keys in all databases
- ACL categories:
-
@keyspace,@write,@slow,@dangerous, - Compatibility:
- Redis Software and Redis Cloud compatibility
Note:
This command's behavior varies in clustered Redis environments. See the multi-key operations page for more information.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.
Full delete: Delete all keys from all databases using FLUSHALL (dangerous operation, supports ASYNC/SYNC modes, clears RDB file)
FLUSHALL SYNCres1 = r.flushall(asynchronous=False)
print(res1) # >>> True
res2 = r.keys()
print(res2) # >>> []
import 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',...}
const res1 = await client.flushAll('SYNC'); // or ASYNC
console.log(res1); // OK
const res2 = await client.keys('*');
console.log(res2); // []
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();
String flushAllResult1 = jedis.flushAll();
System.out.println(flushAllResult1); // >>> OK
Set<String> flushAllResult2 = jedis.keys("*");
System.out.println(flushAllResult2); // >>> []
import java.util.Set;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.RedisClient;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class CmdsServerMgmtExample {
public void run() {
RedisClient jedis = RedisClient.create("redis://localhost:6379");
String flushAllResult1 = jedis.flushAll();
System.out.println(flushAllResult1); // >>> OK
Set<String> flushAllResult2 = jedis.keys("*");
System.out.println(flushAllResult2); // >>> []
// Note: you must use the `Jedis` class to access the `info`
// command rather than `RedisClient`.
Jedis jedis2 = new Jedis("redis://localhost:6379");
String infoResult = 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)); // >>> # Server
jedis2.close();
jedis.close();
}
}
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) // >>> []
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
}
Optional arguments
ASYNC | SYNC
Flush asynchronously (ASYNC) or synchronously (SYNC). The default is set by the lazyfree-lazy-user-flush configuration directive.
Details
- An asynchronous
FLUSHALLcommand only deletes keys that were present at the time the command was invoked. Keys created during an asynchronous flush will be unaffected. - This command does not delete functions.
- Other than emptying all databases (similar to
FLUSHDB), this command clears the RDB persistence file, aborts any snapshot that is in progress, and, if thesaveconfig is enabled, saves an empty RDB file.
Redis Software and Redis Cloud compatibility
| Redis Software |
Redis Cloud |
Notes |
|---|---|---|
| ✅ Standard |
✅ Standard |
*Can use the Active-Active flush API request. |
Return information
Simple string reply:
OK.
History
- Starting with Redis version 4.0.0: Added the
ASYNCflushing mode modifier. - Starting with Redis version 6.2.0: Added the
SYNCflushing mode modifier. The default flush behavior is now configurable using the lazyfree-lazy-user-flush configuration directive.