Home  >  Article  >  Database  >  How does redis delete keys in batches through the command line?

How does redis delete keys in batches through the command line?

王林
王林forward
2020-12-21 09:34:043181browse

How does redis delete keys in batches through the command line?

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!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete