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

后端 未结 9 661
暗喜
暗喜 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 10:57

    From the Documentation

    delete(*names)
        Delete one or more keys specified by names
    

    This just wants an argument per key to delete and then it will tell you how many of them were found and deleted.

    In the case of your code above I believe you can just do:

        redis.delete(*x)
    

    But I will admit I am new to python and I just do:

        deleted_count = redis.delete('key1', 'key2')
    

提交回复
热议问题