The available methods are:
(Learning video sharing: Programming video)
1. Use cli
FLUSHDB clears a database, FLUSHALL clears the entire redis data.
2. Use shell
redis-cli keys "*" | while read LINE ; do TTL=`redis-cli ttl $LINE`; if [ $TTL -eq -1 ]; then echo "Del $LINE"; RES=`redis-cli del $LINE`; fi; done;
Delete those that expire after 3600 seconds
redis-cli keys "*" | while read LINE ; do TTL=`redis-cli ttl $LINE`; if [ $TTL -ge 3600 ]; then echo "Del $LINE"; RES=`redis-cli del $LINE`; fi; done;
Delete those with certain prefixes
redis-cli KEYS "126.com*" | xargs redis-cli DEL
Related recommendations:redis database Tutorial
The above is the detailed content of How does redis delete keys in batches through the command line?. For more information, please follow other related articles on the PHP Chinese website!