How do I delete everything in Redis?

2019-01-09 20:35发布

I want to delete all keys. I want everything wiped out and give me a blank database.

Is there a way to do this in Redis client?

标签: redis
20条回答
祖国的老花朵
2楼-- · 2019-01-09 21:13

Its better if you can have RDM (Redis Desktop Manager). You can connect to your redis server by creating a new connection in RDM.

Once its connected you can check the live data, also you can play around with any redis command.

Opening a cli in RDM.

1) Right click on the connection you will see a console option, just click on it a new console window will open at the bottom of RDM.

Coming back to your question FLUSHALL is the command, you can simply type FLUSHALL in the redis cli.

Moreover if you want to know about any redis command and its proper usage, go to link below. https://redis.io/commands.

查看更多
Melony?
3楼-- · 2019-01-09 21:14
ら.Afraid
4楼-- · 2019-01-09 21:15

This method worked for me - delete everything of current connected Database on your Jedis cluster.

public static void resetRedis() {
    jedisCluster = RedisManager.getJedis(); // your JedisCluster instance

    for (JedisPool pool : jedisCluster.getClusterNodes().values()) {

        try (Jedis jedis = pool.getResource()) {
            jedis.flushAll();
        }
        catch (Exception ex){
            System.out.println(ex.getMessage());
        }
    }

}
查看更多
够拽才男人
5楼-- · 2019-01-09 21:18

FLUSHALL Remove all keys from all databases

FLUSHDB Remove all keys from the current database

SCRIPT FLUSH Remove all the scripts from the script cache.

查看更多
Bombasti
6楼-- · 2019-01-09 21:18

After you start the Redis-server using:service redis-server start --port 8000 or redis-server.

Use redis-cli -p 8000 to connect to the server as a client in a different terminal.

You can use either

  1. FLUSHDB - Delete all the keys of the currently selected DB. This command never fails. The time-complexity for this operation is O(N), N being the number of keys in the database.
  2. FLUSHALL - Delete all the keys of all the existing databases, not just the currently selected one. This command never fails. The time-complexity for this operation is O(N), N being the number of keys in all existing databases.

Check the documentation for ASYNC option for both.

If you are using Redis through its python interface, use these two functions for the same functionality:

def flushall(self):
    "Delete all keys in all databases on the current host"
    return self.execute_command('FLUSHALL')

and

def flushdb(self):
    "Delete all keys in the current database"
    return self.execute_command('FLUSHDB')
查看更多
forever°为你锁心
7楼-- · 2019-01-09 21:18

Your questions seems to be about deleting entire keys in a database. In this case you should try:

  1. Connect to redis. You can use the command redis-cli (if running on port 6379), else you will have to specify the port number also.
  2. Select your database (command select {Index})
  3. Execute the command flushdb

If you want to flush keys in all databases, then you should try flushall.

查看更多
登录 后发表回答