In redis, there is no command to delete keys directly according to regular expressions, only the Del key1 command
However, redis has a command to obtain keys through regular expressions: keys “regular expressions”
You can delete keys in batches with the help of xargs command, and pass the found key value to del as a parameter
redis-cli keys “xxxx*” | xargs del
Full command
redis-cli -h 192.169.1.71 -p 7001 -a 123456 keys xxxx* | xargs -r -t -n1 redis-cli -h 192.169.1.71 -p 7001 -a 123456 del
[note]
The xargs command needs to be followed by the parameter – R, otherwise when the number of keys is 0, an error will be reported err wrong number of arguments for ‘del’ command
The parameter – N1 should be added after the xargs command. Otherwise, when the number of cluster keys is greater than 1, an error may be reported: crosslot keys in request don’t hash to the same slot
It is OK not to add – T. adding – t will output the content deleted each time. If not, the deleted content will not be output, but the number of keys deleted each time will still be output
Similar Posts:
- Gitlab 403 Forbidden error [How to Solve]
- Error reported in the celery log of the project: redis.exceptions.connectionerror failed to connect with redis
- CentOS8 Install redis-6.0.6 make test:“ You need tcl 8.5 or newer in order to run the Redis test“
- Filebeat output redis i/o timeout [How to Solve]
- [Solved] #Creating Server TCP listening socket *:6379: bind: Address already in use
- This account is currently not available [How to Solve]
- [Solved] Redis Connect Error: ERR Client sent AUTH, but no password is set
- [Solved] Redis Cluster: (error) CLUSTERDOWN The cluster is down
- [Solved] Redis MISCONF ERROR: Redis is configured to save RDB snapshots
- Redis service failed to start, prompt: redis server: command not found