Home > Database > Redis > body text

How to clear all data in Redis

WBOY
Release: 2023-06-03 14:25:19
forward
3791 people have browsed it

Summary of steps to clear all data in Redis

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
Copy after login

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
Copy after login

4. In the cmd command window, Enter the command to clear all Redis data:

flushall
Copy after login

Redis data clearing strategy

Redis clearing expiration policy

redis sets the expiration name of the key setnx. When the key expires, the key will be automatically cleared.

How to clear all data in Redis

Deletion strategy

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!