首页

解决jedis客户端java代码报"redis.clients.jedis.exceptions.JedisDataException:DENIED Redis is running in protected mode.."问题

标签:JedisDataException,jedis连接异常,redis保护模式     发布时间:2019-04-07   

一、问题描述

关于通过jedis客户端java代码示例连接linux系统redis服务,运行后报"Exception in thread "main" redis.clients.jedis.exceptions.JedisDataException: 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."异常,详情日志如下>>

Exception in thread "main" redis.clients.jedis.exceptions.JedisDataException: 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.@b@	at redis.clients.jedis.Protocol.processError(Protocol.java:59)@b@	at redis.clients.jedis.Protocol.process(Protocol.java:66)@b@	at redis.clients.jedis.Protocol.read(Protocol.java:131)@b@	at redis.clients.jedis.Connection.getStatusCodeReply(Connection.java:162)@b@	at redis.clients.jedis.Jedis.set(Jedis.java:51)@b@	at com.xwood.redis.jedis.JedisClientTest.set(JedisClientTest.java:10)@b@	at com.xwood.redis.jedis.JedisClientTest.main(JedisClientTest.java:19)

二、解决方法

1.将redis配置文件protected-mode保护模式改为no(默认为yes),具体如下所示

...@b@#@b@# By default protected mode is enabled. You should disable it only if@b@# you are sure you want clients from other hosts to connect to Redis@b@# even if no authentication is configured, nor a specific set of interfaces@b@# are explicitly listed using the "bind" directive.@b@protected-mode yes@b@...

修改为

...@b@#@b@# By default protected mode is enabled. You should disable it only if@b@# you are sure you want clients from other hosts to connect to Redis@b@# even if no authentication is configured, nor a specific set of interfaces@b@# are explicitly listed using the "bind" directive.@b@#protected-mode yes@b@protected-mode  no@b@...

2. 重启redis,问题即可解决了