Redis Python - how to delete all keys according to a specific pattern In python, without python iterating

后端 未结 9 659
暗喜
暗喜 2020-12-25 10:42

I\'m writing a django management command to handle some of our redis caching. Basically, I need to choose all keys, that confirm to a certain pattern (for example: \"prefix:

9条回答
  •  太阳男子
    2020-12-25 11:20

    You can use a specific pattern to match all keys and delete them:

    import redis
    client = redis.Redis(host='192.168.1.106', port=6379,
                    password='pass', decode_responses=True)
    for key in client.keys('prefix:*'):
        client.delete(key)
    

提交回复
热议问题