linux清空redis命令,使用Linux管道批量删除Redis的key
------------------------------------------------------
Redis并沒有提供批量刪除記錄的方法,這有時候很不方便,特別是重新初始化數據的時候。一般有兩種做法:
如果業務場景明確,可以通過DBID進行區分,Redis默認的DBID是0,默認的配置文件是有16個DB,可以在應用中通過select方法指定數據庫的ID進行存取。然后通過FlushDB命令能清空某個ID的數據庫,達到重新初始化的目的。
如果某個ID的數據庫已經有很多類型的記錄了,無法整個庫清空,那么就需要批量的刪除key值,這時可以采用Linux管道,比如我要刪除DBID為1的test開頭的key值:
[root@banping redis]# /banping/redis/src/redis-cli -n 1 keys
“test*” | xargs /banping/redis/src/redis-cli -n 1 del
(integer) 5095
把keys的輸出作為del的輸入,這樣就批量刪除了。
附redis-cli 命令:
redis-cli 2.4.2
Usage: redis-cli [OPTIONS] [cmd [arg [arg ...]]]
-h Server hostname (default: 127.0.0.1)
-p Server port (default: 6379)
-s Server socket (overrides hostname and port)
-a Password to use when connecting to the server
-r Execute specified command N times
-i When -r is used, waits seconds per command.
It is possible to specify sub-second times like -i 0.1.
-n Database number
-x Read last argument from STDIN
-d Multi-bulk delimiter in for raw formatting (default: \n)
–raw Use raw formatting for replies (default when STDOUT is not a
tty)
–latency Enter a special mode continuously sampling latency.
–help Output this help and exit
–version Output version and exit
總結
以上是生活随笔為你收集整理的linux清空redis命令,使用Linux管道批量删除Redis的key的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 天眼查询个人
- 下一篇: linux循环脚本while循环,She