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?
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());
}
}
}
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
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')
This works for me: redis-cli KEYS \* | xargs --max-procs=16 -L 100 redis-cli DEL
It list all Keys in redis, then pass using xargs to redis-cli DEL, using max 100 Keys per command, but running 16 command at time, very fast and useful when there is not FLUSHDB or FLUSHALL due to security reasons, for example when using Redis from Bitnami in Docker or Kubernetes. Also, it doesn't require any additional programming language and it just one line.
You can use FLUSHALL which will delete all keys from your every database. Where as FLUSHDB will delete all keys from our current database.
Open redis-cli and type:
FLUSHALL
Your questions seems to be about deleting entire keys in a database. In this case you should try:
redis-cli
(if running on port 6379), else you will have to specify the port number also.select {Index}
)flushdb
If you want to flush keys in all databases, then you should try flushall
.