【问题标题】:FLUSHALL and FLUSHDB commands on redis return "unk command"redis 上的 FLUSHALL 和 FLUSHDB 命令返回“unk 命令”
【发布时间】:2022-03-25 23:48:50
【问题描述】:

要刷新 redis,需要使用FLUSHALL 命令。

使用 Redis 2.6.16,当我在使用 redis-cli 时尝试了 FLUSHALLFLUSHDB 命令时,我收到了 unknown command 错误。其他命令工作正常。

a) FLUSH* 命令出了什么问题?

b) 是否可以关闭 Redis,然后删除 rdb 文件? (我相信)

更新:

不,我们从未解决过这个问题。

(唯一已知的解决方案是使用上面的步骤'b')

【问题讨论】:

  • 你的假设(b)是正确的。关于(a);你的命令有什么问题:很奇怪,我不知道。你做了makemake test 吗?你的构建一定有问题。
  • 是的,一年前我在初始安装时完成了整个 make/make 测试。这是一个在所有其他方面都可以正常工作的生产实例。
  • 这里有同样的问题;你解决了吗?
  • 同样的问题,有人有解决办法吗?

标签: redis


【解决方案1】:

可能是您的 Redis 配置重命名了一些命令,以防止您的数据库被意外删除。

在您的 redis.conf 中查找以下行:

rename-command FLUSHDB ""
rename-command FLUSHALL ""

【讨论】:

  • 请注意:这是服务器设置,不是客户端;)
  • 这是 Bitnami Redis kubernetes helm 图表中的默认设置,其他任何使用它的人都会遇到这个惊喜。通过修改master/slave.disableCommands 值撤消。
【解决方案2】:

Redis official Helm chart 默认禁用FLUSHDBFLUSHALL 命令。在这种情况下,它没有在容器内的任何redis.conf 中指定,因此您需要在 Redis YAML 中指定它:

master:
  disableCommands: []

【讨论】:

  • 请注意,它在values.yaml 文件中指定 - 用于主服务器和从服务器
  • 最后我们没有启用命令,而是在Bitnami提供的Redis容器的shell中执行了如下命令:echo 'KEYS *' | redis-cli * | sed 's/^/DEL /' | redis-cli
【解决方案3】:

我正在使用 Helm 并且不想重新安装它,因此我通过修改 Helm 生成的 configmap 以包含该配置来解决此问题。

CONFIGMAP=<<value of common.names.fullname>>-configuration
kubectl edit cm $CONFIGMAP

您应该会看到如下内容:

  master.conf: |-
    dir /data
    # User-supplied master configuration:
    rename-command FLUSHDB ""
    rename-command FLUSHALL ""
    # End of master configuration
  redis.conf: |-
    # User-supplied common configuration:
    # Enable AOF https://redis.io/topics/persistence#append-only-file
    appendonly yes
    # Disable RDB persistence, AOF persistence already enabled.
    save ""
    # End of common configuration
  replica.conf: |-
    dir /data
    slave-read-only yes
    # User-supplied replica configuration:
    rename-command FLUSHDB ""
    rename-command FLUSHALL ""
    # End of replica configuration

删除以rename-command 开头的行,使其看起来更像这样:

  master.conf: |-
    dir /data
    # User-supplied master configuration:
    # End of master configuration
  redis.conf: |-
    # User-supplied common configuration:
    # Enable AOF https://redis.io/topics/persistence#append-only-file
    appendonly yes
    # Disable RDB persistence, AOF persistence already enabled.
    save ""
    # End of common configuration
  replica.conf: |-
    dir /data
    slave-read-only yes
    # User-supplied replica configuration:
    # End of replica configuration

重启 redis pod

kubectl delete pods $(kubectl get pods | grep redis | awk {'print $1'})

现在执行到主 pod 并刷新所有

kubectl exec redis-master-0 -- redis-cli FLUSHALL
OK

请注意,如果您想再次使用 FLUSHALL 或 FLUSHDB,则在重新安装 Helm 版本时必须再次执行此操作。

更新:虽然这可行,但当您重新安装 helm release 时,pod 将进入 crashloopbackoff,因为它们会在历史记录中看到您运行的命令不存在,因此您必须再次执行此操作让 pod 运行。在这种情况下,可能最好使用@camilo-sampedro 的答案。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-25
    • 1970-01-01
    • 2019-09-06
    • 2015-02-15
    • 2013-02-19
    • 2023-03-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多