BillBie

导航

python-redis 模糊匹配 scan del

转载自:https://zhuanlan.zhihu.com/p/534129213
begin_pos = 0    # 最开始游标从0开始
datalists = []
size = my_conn.dbsize()
new_pos = size
while new_pos:
    new_pos, datalist = my_conn.scan(begin_pos, '*%s*'% key, 100000)
    if len(datalist) > 0:
      datalists += datalist
      my_conn.delete(*datalist)
    begin_pos = new_pos

if len(datalists):
  return "ok", datalists
else:
  return "no key"

 

 

posted on 2023-03-06 15:46  BillBie  阅读(102)  评论(0编辑  收藏  举报