首页 > 代码库 > 关于Jedis连接redis出现问题

关于Jedis连接redis出现问题

 环境说明:

redis服务器系统:ubuntu  

ip 192.168.10.9

port 6379

两台电脑:一个作为专门的服务器,一个是开发环境

  

就这样的简单的代码连接redis服务器

import redis.clients.jedis.Jedis;

public class Test {
	public static void main(String[] args) {
		Jedis jedis = new Jedis("192.168.10.9");
		jedis.auth("ldd");
		jedis.set("age", "1");
	 System.out.println(jedis.get("age"));
	}
}

 但是却出现了下面的异常: 

Exception in thread "main" redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: Read timed out
	at redis.clients.jedis.Protocol.process(Protocol.java:79)
	at redis.clients.jedis.Protocol.read(Protocol.java:131)
	at redis.clients.jedis.Connection.getStatusCodeReply(Connection.java:162)
	at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:72)
	at redis.clients.jedis.Connection.sendCommand(Connection.java:79)
	at redis.clients.jedis.Connection.sendCommand(Connection.java:75)
	at redis.clients.jedis.BinaryClient.auth(BinaryClient.java:499)
	at redis.clients.jedis.Jedis.auth(Jedis.java:1963)
	at testfinal.Test.main(Test.java:8)
Caused by: java.net.SocketTimeoutException: Read timed out
	at java.net.SocketInputStream.socketRead0(Native Method)
	at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
	at java.net.SocketInputStream.read(SocketInputStream.java:170)
	at java.net.SocketInputStream.read(SocketInputStream.java:141)
	at java.net.SocketInputStream.read(SocketInputStream.java:127)
	at redis.clients.util.RedisInputStream.fill(RedisInputStream.java:109)
	at redis.clients.util.RedisInputStream.readByte(RedisInputStream.java:45)
	at redis.clients.jedis.Protocol.process(Protocol.java:64)
	... 8 more

  重点是:用客户端就能正常连接。

技术分享

真的,需要研究一下原因。

不知道有没有知道的朋友可以指点一二。

关于Jedis连接redis出现问题