RedisKEY deletion and expiration time setting

There is an instruction DEL to delete a single key in Redis, but it seems that there is no instruction to delete keys in batches, but we can use the xargs instruction of Linux to complete this action

redis-cli keys "*" | xargs redis-cli del
//If redis-cli is not set as a system variable, you need to specify the full path of redis-cli
//如:/opt/redis/redis-cli keys "*" | xargs /opt/redis/redis-cli del


If you want to specify the Redis database access password, use the following command

redis-cli -a password keys "*" | xargs redis-cli -a password del


If you want to access a specific database in Redis, use the following command
//The following command specifies that the data serial number is 0, which is the default database
redis-cli -n 0 keys "*" | xargs redis-cli -n 0 del


To delete all keys, you can use the flushdb and flushall commands of Redis

// delete all keys in the current database
flushdb
// delete all keys in the database
flushall


Expiration time, if it has been set, then update the expiration time
expire key seconds


View remaining time
ttl key

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326712457&siteId=291194637