How do I to flush redis db from python redis?

前端 未结 3 1485
深忆病人
深忆病人 2021-01-01 09:26

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

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

相关标签:
3条回答
  • 2021-01-01 10:01

    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

    0 讨论(0)
  • 2021-01-01 10:05

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

    check out this page, you will find them.

    0 讨论(0)
  • 2021-01-01 10:07

    Redis-py actually has this functionality:

    import redis
    r = redis.Redis()
    r.flushdb()
    
    0 讨论(0)
提交回复
热议问题