文章目录

  • 小结
  • 问题
  • 解决
  • 参考


小结

Redis的调试指令返回权限不允许的错误(ERR DEBUG command not allowed),进行了解决。

问题

redis-cli -p 6379 DEBUG sleep 30指令返回ERR DEBUG command not allowed,如下:

john@XYZ:~$ redis-cli -p 6379 DEBUG sleep 30
(error) ERR DEBUG command not allowed. If the enable-debug-command option is set to "local", you can ru server.

解决

参考How to fix Redis Error “ERR DEBUG command not allowed.”还是无法解决。

开始误以为文件配置有问题/etc/redis/redis.conf,修改enable-debug-commandyes.

john@XYZ:~$ sudo vim /etc/redis/redis.conf
enable-debug-command yes

注意在WSL的Ubuntu中systemctl指令是不起作用的,可以使用sudo service redis-server restart指令进行重启。

进行了以上配置,还是会有同样的ERR DEBUG command not allowed错误。
细究原因是Redis-server启动方式不对,我使用了sudo redis-server --port 6379指令启动Redis,导致了enable-debug-command yes的配置没有生效,正确的启动方式是sudo service redis-server restart

最后的测试结果如下:

john@XYZ:~$ redis-cli -p 6379 DEBUG sleep 30
OK
john@XYZ:~$ redis-cli
127.0.0.1:6379> DEBUG POPULATE 10 Test
OK
127.0.0.1:6379> keys Test*
 1) "Test:8"
 2) "Test:7"
 3) "Test:2"
 4) "Test:9"
 5) "Test:1"
 6) "Test:5"
 7) "Test:0"
 8) "Test:6"
 9) "Test:4"
10) "Test:3"
127.0.0.1:6379> exit

参考

How to fix Redis Error “ERR DEBUG command not allowed.”How to Install Redis on Ubuntu + Configuration and Common Redis Commands