1. Open the cmd command window and switch to the bin folder in the Redis installation directory
2. In the cmd command window, enter the connection Redis command:
redis-cli.exe -h 127.0.0.1 -p 6389
If Redis is configured with password mode, after the connection is successful, you first need to enter the correct password; if it is not configured, you can skip this step
auth abc123
4. In the cmd command window, Enter the command to clear all Redis data:
flushall
redis sets the expiration name of the key setnx. When the key expires, the key will be automatically cleared.
1. Regular deletion
Trigger deletion events: Insufficient memory, key expiration time expires Period
The deletion strategy includes: regular deletion, lazy deletion
Periodic deletion: refers to the fact that by default, redis randomly extracts some keys with expiration time set every 100ms and checks whether they have expired. If Delete when expired
Lazy deletion: When obtaining a key, redis will check whether the key has expired if the expiration time is set? If it expires, it will be deleted at this time and nothing will be returned to you.
2 Memory elimination mechanism
1. allkeys-lru: When the memory is insufficient to accommodate newly written data, in the key space, remove the least recently used key (this is the most commonly used)
2. allkeys-random: When the memory is not enough to accommodate newly written data, a key is randomly removed from the key space. This is generally not used. Why should it be random? It must be to kill the least recently used key
3. volatile-lru: When the memory is not enough to accommodate the newly written data, move it in the key space with the expiration time set. Except for the least recently used key (this is generally not suitable)
4. Volatile-random: When the memory is not enough to accommodate newly written data, randomly remove a key from the key space with an expiration time set. key
5. volatile-ttl: When the memory is not enough to accommodate the newly written data, in the key space with an expiration time set, keys with an earlier expiration time will be removed first
The above is the detailed content of How to clear all data in Redis. For more information, please follow other related articles on the PHP Chinese website!