Created
September 13, 2022 10:00
-
-
Save ppabcd/71133d181c6669a24db760ffb248635d to your computer and use it in GitHub Desktop.
Redis set keys expirations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ $# -ne 4 ] | |
then | |
echo "Usage: $0 <host> <port> <pattern> <seconds>" | |
exit 1 | |
fi | |
cursor=-1 | |
keys="" | |
ttl=0 | |
expire="$4" | |
while [ $cursor -ne 0 ]; do | |
if [ $cursor -eq -1 ] | |
then | |
cursor=0 | |
fi | |
reply=`redis-cli -h $1 -p $2 --tls SCAN $cursor MATCH $3` | |
cursor=`expr "$reply" : '\([0-9]*[0-9 ]\)'` | |
keys=`echo $reply | cut -d' ' -f2-` | |
for key in ${keys// / } ; do | |
ttl=`redis-cli -h $1 -p $2 --tls TTL $key` | |
act="" | |
if [ $ttl -eq -1 ] | |
then | |
result=`redis-cli -h $1 -p $2 --tls EXPIRE $key $expire` | |
act=" -> $expire" | |
fi | |
echo "$key: $ttl$act" | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment