刪除redis所有KEY

來源:互聯網
上載者:User
大量刪除Key

Redis 中有刪除單個 Key 的指令 DEL,但好像沒有大量刪除 Key 的指令,不過我們可以藉助 Linux 的 xargs 指令來完成這個動作

1 2 3 redis-cli -h ip -p port keys "*"| xargs redis-cli -h ip -p port del //如果redis-cli沒有設定成系統變數,需要指定redis-cli的完整路徑 //如:/opt/redis/redis-cli keys "*" | xargs /opt/redis/redis-cli del

如果要指定 Redis 資料庫訪問密碼,使用下面的命令

1 redis-cli -h ip -p port -a password keys "*"| xargs redis-cli -h ip -p port -a password del

如果要訪問 Redis 中特定的資料庫,使用下面的命令

1 2 //下面的命令指定資料序號為0,即預設資料庫 redis-cli -h ip -p port -n 0 keys "*"| xargs redis-cli -h ip -p port -n 0 del
刪除所有Key

刪除所有Key,可以使用Redis的flushdb和flushall命令

1 2 3 4 //刪除當前資料庫中的所有Key flushdb //刪除所有資料庫中的key flushall

註:keys 指令可以進行模糊比對,但如果 Key 含空格,就匹配不到了,暫時還沒發現好的解決辦法。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.