#!/bin/bash #修改成自己的ip、密码、库名以及所要匹配的字符串 db_ip=192.168.1.100 db_port=6379 password=963852741 dbnum=0 str="niubi:*" cursor=0 cnt=1000 new_cursor=0 redis-cli -h $db_ip -p $db_port -a $password -n $dbnum scan $cursor match $str count $cnt > scan_tmp_result new_cursor=`sed -n ‘1p‘ scan_tmp_result` sed -n ‘2,$p‘ scan_tmp_result > scan_result sed -n ‘1,$p‘ scan_result|xargs redis-cli -h $db_ip -p $db_port -a $password -n $dbnum del >/dev/null while [ $cursor -ne $new_cursor ] do redis-cli -h $db_ip -p $db_port -a $password -n $dbnum scan $new_cursor match $str count $cnt > scan_tmp_result new_cursor=`sed -n ‘1p‘ scan_tmp_result` sed -n ‘2,$p‘ scan_tmp_result > scan_result sed -n ‘1,$p‘ scan_result|xargs redis-cli -h $db_ip -p $db_port -a $password -n $dbnum del >/dev/null done