database 如何清空redis数据库?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5756067/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 08:10:25  来源:igfitidea点击:

How to empty a redis database?

databasenosqlredis

提问by Luc

I've been playing with redis (and add some fun with it) during the last fews days and I'd like to know if there is a way to empty the db (remove the sets, the existing key....) easily.
During my tests, I created several sets with a lot of members, even created sets that I do not remember the name (how can I list those guys though ?).
Any idea about how to get rid of all of them ?

在过去的几天里,我一直在玩 redis(并增加一些乐趣),我想知道是否有办法轻松清空数据库(删除集合、现有密钥......) .
在我的测试中,我创建了几个包含很多成员的集合,甚至创建了一些我不记得名字的集合(但是我怎么能列出这些人?)。
关于如何摆脱所有这些的任何想法?

回答by plaes

You have two options:

您有两个选择:

  • FLUSHDB- clears currently active database
  • FLUSHALL- clears all the existing databases
  • FLUSHDB- 清除当前活动的数据库
  • FLUSHALL- 清除所有现有数据库

回答by Dexter

Be careful here.

这里要小心。

FlushDB deletes all keys in the current database while FlushALL deletes all keys in all databases on the current host.

FlushDB 删除当前数据库中的所有键,而 FlushALL 删除当前主机上所有数据库中的所有键。

回答by Hieu Le

With redis-cli:

redis-cli

FLUSHDB       - Removes data from your connection's CURRENT database.
FLUSHALL      - Removes data from ALL databases.

Redis Docs: FLUSHDB, FLUSHALL

Redis 文档: FLUSHDBFLUSHALL

回答by Marc

tldr: flushdbclears one database and flushallclears all databases

tldr:flushdb清除一个数据库并flushall清除所有数据库

Clear CURRENT

清除电流

Delete default or currently selected database (usually `0) with

删除默认或当前选择的数据库(通常为`0)

redis-cli flushdb

Clear SPECIFIC

清除特定

Delete specific redis database with (e.g. 8as my target database):

删除特定的 redis 数据库(例如8作为我的目标数据库):

redis-cli -n 8 flushdb 

Clear ALL

清除所有

Delete all redis databases with

删除所有redis数据库

redis-cli flushall

回答by Denys

There are right answers but I just want to add one more option (requires downtime):

有正确的答案,但我只想再添加一个选项(需要停机):

  1. Stop Redis.
  2. Delete RDB file (find location in redis.conf).
  3. Start Redis.
  1. 停止Redis。
  2. 删除 RDB 文件(在 redis.conf 中查找位置)。
  3. 启动Redis。

回答by behzad babaei

open your Redis cli and There two possible option that you could use:

打开您的 Redis cli,您可以使用两种可能的选项:

FLUSHDB - Delete all the keys of the currently selected DB. FLUSHALL - Delete all the keys of all the existing databases, not just the currently selected one.

FLUSHDB - 删除当前选定数据库的所有键。FLUSHALL - 删除所有现有数据库的所有键,而不仅仅是当前选择的键。