Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make redis-server flushes all data when it restarts?

I am studying redis.

I got local redis-server(localhost) and access with terminal in same device. Since I heard that redis is memory-database, I expect all data gone when I shutdown the server.

However, When I command "shudown"/"exit" in redis-cli and restart, data still alive. I think there is an option to control this, but I can not find.

Would you let me know where to find and what has to be changed?

like image 882
Juneyoung Oh Avatar asked Apr 17 '14 01:04

Juneyoung Oh


People also ask

How do I flush all in Redis?

There are two major commands to delete the keys present in Redis: FLUSHDB and FLUSHALL. We can use the Redis CLI to execute these commands. The FLUSHDB command deletes the keys in a database. And the FLUSHALL command deletes all keys in all databases.

Does Redis lose data on restart?

If a Redis server that only stores data in RAM is restarted, all data is lost. To prevent such data loss, there needs to be some mechanism for persisting the data to disk; Redis provides two of them: snapshotting and anappend-only file, or AOF.

How do I make Redis persistent?

Within Redis, there are two different ways of persisting data to disk. One is a method called snapshotting that takes the data as it exists at one moment in time and writes it to disk. The other method is called AOF, or append—only file, and it works by copying incoming write commands to disk as they happen.

How do I flush Redis Windows cache?

The easiest way to clear Redis cache is to use the redis-cli command. Databases in Redis are stored individually. Using the redis-cli command allows you to either clear the keys from all databases, or from a single specified database only.


1 Answers

Look in the redis.conf file that you are using:

#   It is also possible to remove all the previously configured save
#   points by adding a save directive with a single empty string argument
#   like in the following example:
#
#   save ""

Stop redis-server, configure it as stated above, throw away the .rdb file, and start redis-server.

From now on, on every restart, redis-server will start with no data. Plus, no automatic snapshotting will happen at all.

Note: I presume here that you have not configured AOF. If that's the case, the solution is similar to the method mentioned above.

Hope this helps, TW

like image 168
Tw Bert Avatar answered Sep 28 '22 04:09

Tw Bert