拿走不謝,根據自己需求改動
#!/bin/sh
# 功能:查詢某個redis數據庫的 沒有設置過期時間的key
# 執行姿勢:sh redis-query.sh 22 這是查詢22庫中,存在沒有設置過期時間的key
n=$@
redis-cli -h 'ip地址' -p 6379 -a '密碼' -n $n keys "*" > keys.txt
more keys.txt | grep -v ^$ | while read mykey
do
result=`redis-cli -h 'ip地址' -p 6379 -a '密碼' -n $n -c ttl $mykey`
if [ $result -eq -1 ]
then
echo $mykey
fi
done