Redis批量查詢刪除KEYS


   對騰訊雲的Redis集群不支持很多指令(config get * 、flushdb、flushall、等相關指令)

redis指令限制:https://www.qcloud.com/document/product/239/4073

  沒有辦法,也需想出辦法。。.

刪除單個:del key

刪除多個:redis-cli -h ip -a pass(密碼)  keys 關鍵字 | xargs redis-cli -h ip -a pass(密碼) del         #Linux下的管道符批量操作


#在redis的客戶端連接處登陸刪除

./redis-cli -h 10.111.0.xx  -a xx   keys '*str_ account*' | xargs ./redis-cli -h 10.111.0.xx  -a xx  del

#環境變量直接使用 ln -s  /tmp/redis/src/redis-cli  /usr/bin/

redis-cli -h 10.111.0.xx -a xx  keys '*wxsmrzResult*' | xargs redis-cli -h 10.111.0.xx  -a xx  del   

 

#在沒有,指令限制的情況下,可以使用Redis的flushdb和flushall命令

刪除當前數據庫中的所有Key flushdb

刪除所有數據庫中的key       flushall

要訪問 Redis 中特定的數據庫

指定數據序號為0,即默認數據庫 redis-cli -n 0 keys "*" | xargs redis-cli -n 0 del


注:keys 指令可以進行模糊匹配,但如果 Key 含空格,就匹配不到了

  • h?llo matches hello, hallo and hxllo           #? 匹配任意單個字符
  • h*llo matches hllo and heeeello               #* 匹配任意字符
  • h[ae]llo matches hello and hallo, but not hillo  # 或者
  • h[^e]llo matches hallo, hbllo, ... but not hello   #排除
  • h[a-b]llo matches hallo and hbllo             #

Use \ to escape special characters if you want to match them verbatim.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM