先编写shell文件,名称为“expireAll.sh”,并设置为可执行文件,用于接收参数并设置过期时间,内容如下:
# 给指定缓存设置1分钟过期 ,-n是指定库.注意密码这最好单引号,否则容易出现无法识别。
redis-cli -h 127.0.0.1 -p 6379 -a '123456' -n "2" expire $1 60
使用shell 管道命令执行,这里将test_开头的key全部设置过期时间
redis-cli -h " 127.0.0.1" -p 6379 -a '123456' -n "2" keys "test_.*" | xargs -I {} ./exipreAll.sh {}