Java Connection Operation Redis Error occurred

Source: Internet
Author: User

Exception in thread "main"Redis.clients.jedis.exceptions.JedisConnectionException:java.net.ConnectException:Connection refused: Connect at Redis.clients.jedis.Connection.connect (Connection.java:207) at Redis.clients.jedis.BinaryClient.connect (Binaryclient.java:93) at Redis.clients.jedis.Connection.sendCommand (Connection.java:126) at Redis.clients.jedis.Connection.sendCommand (Connection.java:121) at redis.clients.jedis.BinaryClient.ping (Binaryclient.java:106) at redis.clients.jedis.BinaryJedis.ping (Binaryjedis.java:195) at practice. Redisjava.main (Redisjava.java:13) caused By:java.net.ConnectException:Connection refused:connect at Java.net.DualStackPlainSocketImpl.waitForConnect (Native Method) at Java.net.DualStackPlainSocketImpl.socketConnect (Dualstackplainsocketimpl.java:85) at Java.net.AbstractPlainSocketImpl.doConnect (Abstractplainsocketimpl.java:350) at Java.net.AbstractPlainSocketImpl.connectToAddress (Abstractplainsocketimpl.java:206) at Java.net.AbstractPlainSocketImpl.connect (Abstractplainsocketimpl.java:188) at Java.net.PlainSocketImpl.connect (Plainsocketimpl.java:172) at Java.net.SocksSocketImpl.connect (Sockssocketimpl.java:392) at Java.net.Socket.connect (Socket.java:589) at Redis.clients.jedis.Connection.connect (Connection.java:184)    ... 6 more

This can be caused by two reasons, the first may be the Redis 6379 port is inaccessible, please enter the command in CMD first
Telnet 127.0.0.1 6379
See if you can access the 6379 port of the Redis-server machine, if you can't access it, you need to switch off the firewall on the remote machine or add permission to
1) Log in with the root user, vi/etc/sysconfig/iptables, add so one line

2) Enter command service iptables restart Restart firewall

Alternatively, you can use the command service iptables stop to shut down the firewall directly by the root user.

After the firewall is checked, if you still have the above problem, the Redis has a place to configure, redis default is only native can access, want to remote access needs to modify the redis.conf configuration file.
Enter the redis.conf directory and use the VI command to open, find bind that row modified, Wq save exit, restart Redis-server.

bind is added to the IP that is allowed to access
Bind 127.0.0.1 means that only this machine can be accessed, you can join the IP that is allowed to access, or you can comment out the line directly so that all machines can access it.

New issues that arise after solving the above problems: DENIED Redis is running in protected mode

The error message is as follows:

Exception in thread "main" Redis.clients.jedis.exceptions.JedisDataException:DENIED Redis are running inprotectedmode becauseprotectedMode is enabled, no bind address was specified, no authentication password are requested to clients. Inch ThisMode connections is only accepted from the loopbackInterface. If you want to connect from external computers to Redis one of the following solutions:1) Just DisableprotectedMode sending the command ' CONFIG SET protected-mode No ' from the loopbackInterfaceBy connecting-to-Redis from the same host the server is running, however make sure Redis are not publicly accessible from I NternetifYou DoSo. Use CONFIG REWRITE ThisChange permanent.2) Alternatively you can just disable theprotectedMode by editing the Redis configuration file, and setting theprotectedmode option to ' no ', and then restarting the server.3) If You started the server manually just forTesting, restart it with the '--protected-mode no 'option.4) Setup A bind address or an authentication password. Note:you only need to DoOne of the above things in order forThe server to start accepting connections from the outside. At Redis.clients.jedis.Protocol.processError (Protocol.java:127) at Redis.clients.jedis.Protocol.process (Protocol.java:161) at Redis.clients.jedis.Protocol.read (Protocol.java:215) at Redis.clients.jedis.Connection.readProtocolWithCheckingBroken (Connection.java:340) at redis.clients.jedis.Connection.getStatusCodeReply (Connection.java:239) at Redis.clients.jedis.Jedis.set (Jedis.java:121) at Roy.redis.test.Test.init (Test.java:13) at Roy.redis.test.Test.main (Test.java:8)

The error message is very long, but the main thing is that Redis opens the protected mode, which is also a new feature of Redis3.2, which enables Redis to turn on protected mode to allow only native logins, and also in the configuration file redis.conf.

Here is the original yes means that the protection mode is turned on, the following can be filled with a password can also fill no for the closed, we choose to turn off the protection mode, Wq save exit and then restart Redis-server

Reproduced:

Using the Java Remote Connection Operation redis-roy_70 column-Blog channel-csdn.net
http://blog.csdn.net/roy_70/article/details/54583686

Java Connection Operation Redis Error occurred

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.