redis clear cache

How does redis clear the cache

If your project uses redis, although the expiration time is set, sometimes you need to clear the cache in time to read the data in the database when you modify the bug, so this article explains how to clear the redis cache.

Text
1. First enter the redis installation directory, enter the src directory, and find redis-cli

insert image description here
2. First use the account password to enter the redis server

./redis-cli -h 127.0.0.1 -p 6379 -a 1234

After entering, the following interface ip:port> will appear, and you can operate it
insert image description here

flushdb ——> Clear all keys in the current database flushall ——> Clear
the data of the entire Redis server (delete all keys in all databases).
Important, whether it can be cleared must be determined clearly, otherwise don't clear it easily.

The next thing to talk about is the installation-free version of redis, which is the version of my computer.
insert image description here
First, when we clear the cache, we need to make sure that redis-server.exe is running , otherwise the cache cannot be cleared, and then we double-click Run redis-cli.exe
insert image description here
: Then enter this interface:
insert image description here
we can use the command to clear the cache, because of the needs of our project, because there is only one project in the server deployed by our project, so I often use the command flushall To clear the cache, enter this and press Enter. Generally, you will see the following situation:
insert image description here
the problem is not big, let’s just enter the auth "password" , and the "password" is the password you configured yourself when using redis. After typing, press Enter, you can see the word OK, then enter the command flushall
insert image description here
again , after pressing Enter, you will find that if you see OK, it means that the cache has been cleared successfully

insert image description here

At this point, the cache is cleared, and there is no need to restart redis. However, it is worth noting that whether the cached data of your server is important and whether it can be cleared, you must be sure to clear the cache before executing the command to clear the cache. If you are not sure whether it is possible To clear it, it is best to confirm it before clearing it, otherwise don't clear it easily.

Let's talk about the role of the command:

flushall: Clear the data of the entire redis server (delete all keys in all databases).
flushdb: Clear all keys in the current database.
insert image description here

Guess you like

Origin blog.csdn.net/weixin_45182619/article/details/127571850