Redis get key error

时间:2022-07-25
本文章向大家介绍Redis get key error,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
背景

程序中一直用的key,突然不可以用,于是登录到redis集群上,手动get了一下,发现如下错误

错误
 (error) DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to 'no', and then restarting the server. 3) If you started the server manually just for testing, restart it with the '--protected-mode no' option. 4) Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.

现在redis 处于拒绝模式,绑定地址也没有指定,在这种模式下,只接受回环地址接口的接口。

解决方案

其实,这里面提示了4种方法: 1、Just disable protected mode sending the command ‘CONFIG SET protected-mode no’ from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent.

直接通过回环接口命令设置为非保护模式,但是这种模式,需要保证外部的网络不能访问你。

2、 Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to ‘no’, and then restarting the server. 可以,编辑redis配置文件,配置和第一点一样。

3、If you started the server manually just for testing, restart it with the ‘–protected-mode no’ option. 如果你只是测试,那么可以重启的时候一次性使用非保护模式

4、Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside. 设置一个绑定的地址,或者认证的密码。注意,只用做上面的一个就够了。

因为我这边是开发环境,就直接采用第二种方式了。