电脑重启后,redis中的数据为什么没有被清空?

图片说明

引自官方文档:

By default Redis saves snapshots of the dataset on disk, in a binary file called dump.rdb.

要想清空数据,按如下步骤操作:
1 停止redis server , 找到redis.conf文件中如下部分:
# 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 ""
然后将 save ""行注释(#)去掉

2 删除.rdb文件

3 重启redis server

redis虽然是内存数据库,但是它有持久化功能,也就是它停止的时候会把数据写入文件,下次启动的时候会把数据从文件读取出来加载进内存。

如果你要删除数据那么就要停止程序,然后删除DB文件。

redis有rdb和aof两种持久化方式,也可以设置无持久化模式,这样就相当于纯内存存储了。