1. 程式人生 > 其它 >連線redis時報錯"ERR config is disabled command"的解決方法

連線redis時報錯"ERR config is disabled command"的解決方法

專案從線上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

直接在騰訊雲控制檯裡面找到引數配置,把你需要修改的配置新增上去即可。

最後,就我本人而言,我很不喜歡騰訊雲這種經過定製的雲服務。
其程式碼和私改的部分沒有公開,例項也是對外封閉的,增加了運維的難度和不透明度;
程式碼沒經過審查,存在不安全和藏私貨的風險。