首页 > 技术文章 > 连接redis时报错"ERR config is disabled command"的解决方法

Putinium 2022-03-22 15:46 原文

项目从线上redis4.0迁移到5.0时出现了启动报错:

org.springframework.beans.factory.BeanCreationException: 
  Error creating bean with name 'enableRedisKeyspaceNotificationsInitializer' defined in class path resource [org/springframework/boot/autoconfigure/session/RedisSessionConfiguration$SpringBootRedisHttpSessionConfiguration.class]: Invocation of init method failed; 
    nested exception is org.springframework.data.redis.RedisSystemException: Error in execution; 
    nested exception is io.lettuce.core.RedisCommandExecut1onException: ERR config is disabled command
    ......

请注意,虽然同样都是 "enableRedisKeyspaceNotificationsInitializer" 这个 bean 创建失败,但报错是 " ERR config is disabled command " 而不是 " ERR unknown command CONFIG "。

一般的开源版本的 redis 5.0 是没办法 disable 一个命令的,所以在开源版本的 redis 5.0 的解决方案是直接把 CONFIG 这个命令直接 rename 成空串或者随机字符来禁用此命令。
所以,如果你的报错是 ERR unknown command CONFIG ,请检查你的 redis 配置文件,查看是不是 CONFIG 命令被 rename 了。

如果你的报错显示是 ERR config is disabled command ,那你有可能正在使用的是腾讯云公有云或者私有云版本的 redis。
按照官网的说明,想要用 config 命令,是只能用 config get,但是不能用 config set。

当前腾讯云版本的 redis config get 是只支持以下命令

maxmemory,
maxclients,
maxmemory-policy,
databases,
slowlog-log-slower-than
slowlog-max-len,
notify-keyspace-events
lua-time-limit

直接在腾讯云控制台里面找到参数配置,把你需要修改的配置添加上去即可。

最后,就我本人而言,我很不喜欢腾讯云这种经过定制的云服务。
其代码和私改的部分没有公开,实例也是对外封闭的,增加了运维的难度和不透明度;
代码没经过审查,存在不安全和藏私货的风险。

推荐阅读