FLUSHALL

Syntax
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,

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 asynchronously
  • SYNC: flushes the databases synchronously
FLUSHALL SYNC
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',...}

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();
import java.util.Set;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.UnifiedJedis;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class CmdsServerMgmtExample {
    public void run() {
        UnifiedJedis jedis = new UnifiedJedis("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 `UnifiedJedis`.
        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();
    }
}
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

}

Notes

  • An asynchronous FLUSHALL command 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 the save config is enabled, saves an empty RDB file.

Behavior change history

  • >= 6.2.0: Default flush behavior now configurable by the lazyfree-lazy-user-flush configuration directive.

Return information

History

  • Starting with Redis version 4.0.0: Added the ASYNC flushing mode modifier.
  • Starting with Redis version 6.2.0: Added the SYNC flushing mode modifier.
RATE THIS PAGE
Back to top ↑