Dani Medina
Dani Medina

Reputation: 909

How do I to flush redis db from python redis?

Is there a way I can flush my redis db using redis?

I'm looking for something like redis.flushdb() or redis.flushall()

Upvotes: 48

Views: 39286

Answers (3)

Muhammad Faizan Fareed
Muhammad Faizan Fareed

Reputation: 3758

You can try also.

r.execute_command('FLUSHALL ASYNC') # delete keys in background

FLUSHALL ASYNC (Redis 4.0.0 or greater)

Redis is now able to delete keys in the background in a different thread without blocking the server. An ASYNC option was added to FLUSHALL and FLUSHDB in order to let the entire dataset or a single database to be freed asynchronously.

r.flushdb() # Delete all keys of currently selected database instance.
r.flushall() # Delete all keys of entire database.  

Further reading : Redis FLUSHALL ASYNC

Upvotes: 6

GuangshengZuo
GuangshengZuo

Reputation: 4687

Yes, flushdb() and flushall() both exist.

check out this page, you will find them.

Upvotes: 23

Aleksandr Borisov
Aleksandr Borisov

Reputation: 2212

Redis-py actually has this functionality:

import redis
r = redis.Redis()
r.flushdb()

Upvotes: 80

Related Questions