How do I delete everything in Redis?

前端 未结 22 1064
无人共我
无人共我 2020-11-28 17:18

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?

22条回答
  •  南笙
    南笙 (楼主)
    2020-11-28 17:36

    you can use following approach in python

    def redis_clear_cache(self):
    
        try:
            redis_keys = self.redis_client.keys('*')
        except Exception as e:
            # print('redis_client.keys() raised exception => ' + str(e))
            return 1
    
        try:
            if len(redis_keys) != 0:
                self.redis_client.delete(*redis_keys)
        except Exception as e:
            # print('redis_client.delete() raised exception => ' + str(e))
            return 1
    
        # print("cleared cache")
        return 0
    

提交回复
热议问题