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

后端 未结 9 660
暗喜
暗喜 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:01

    Use SCAN iterators: https://pypi.python.org/pypi/redis

    for key in r.scan_iter("prefix:*"):
        r.delete(key)
    

提交回复
热议问题