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

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

    cache.delete(*keys) solution of Dirk works fine, but make sure keys isn't empty to avoid a redis.exceptions.ResponseError: wrong number of arguments for 'del' command.

    If you are sure that you will always get a result: cache.delete(*cache.keys('prefix:*') )

提交回复
热议问题