有没有办法在集群上刷新所有密钥,以便从数据库中删除主从的所有键 [英] Is there a way to flushall on a cluster so all keys from master and slaves are deleted from the db

查看:56
本文介绍了有没有办法在集群上刷新所有密钥,以便从数据库中删除主从的所有键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从文档看来,flushall 是如何工作的,但实际上它不是那样工作的.当我使用命令 flushall 时,它只会刷新 cli 分配给的数据库实例中的键.

From the documentation this seems how flushall would work but in practice it is not working that way. When I use the command flushall it only flushes the keys from the db instance the cli is assigned to.

Redis 刷新文档

删除所有现有数据库的所有键,而不仅仅是当前选择的键.这个命令永远不会失败.

Delete all the keys of all the existing databases, not just the currently selected one. This command never fails.

此操作的时间复杂度为 O(N),N 是所有现有数据库中的键数.

The time-complexity for this operation is O(N), N being the number of keys in all existing databases.

例如,如果我的集群 redis-cli 已经启动并且我搜索一个键,并且节点 cli 从 7000 更改为 7002,对应于哈希所在的键,即服务器 7002,然后执行刷新所有操作,它将删除每个服务器的密钥.

For example if my cluster redis-cli has started and I search for a key and the node cli changes from 7000 to 7002 corresponding with the key that the hash is located i.e. server 7002 and then do a flush all it will delete the key per that server.

但是,其他键仍然存在.

However, the other keys remain.

有没有办法flushall,意思是删除所有master和slave的所有key?

Is there a way to flushall meaning delete all keys across all masters and slaves?

推荐答案

是的.您可以将 cli 的 --cluster 开关与 call 命令一起使用 - 它会在集群的每个主节点上执行提供的命令(并将复制,如 FLUSHALL 是一个写命令,给它们各自的从属).

Yes. You can use the cli's --cluster switch with the call command - it will execute the provided command on each of the cluster's master nodes (and will replicate, as FLUSHALL is a write command, to their respective slaves).

应该这样做:

$ redis-cli --cluster call <one-of-the-nodes-address>:<its-port> FLUSHALL

这篇关于有没有办法在集群上刷新所有密钥,以便从数据库中删除主从的所有键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆