Jedis连接Redis出现connect timed out

JAVA测试代码:

public static void main(String[] args) {

		// 创建Jedis对象,传递两个参数:第一个host为redis服务器的名称,第二个为redis服务器的端口号
		Jedis jedis = new Jedis("192.168.19.101", 6379);
		jedis.auth("123456");
		// 进行设值操作
		jedis.set("username", "李四");
		// 从redis中取值
		String username = jedis.get("username");
		System.out.println("username:" + username);
	}

JAVA测试代码出现的问题:

Exception in thread "main" redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: connect timed out
	at redis.clients.jedis.Connection.connect(Connection.java:154)
	at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:83)
	at redis.clients.jedis.Connection.sendCommand(Connection.java:93)
	at redis.clients.jedis.Connection.sendCommand(Connection.java:88)
	at redis.clients.jedis.BinaryClient.auth(BinaryClient.java:539)
	at redis.clients.jedis.BinaryJedis.auth(BinaryJedis.java:2000)
	at test.main(test.java:20)
Caused by: java.net.SocketTimeoutException: connect timed out
	at java.net.TwoStacksPlainSocketImpl.socketConnect(Native Method)
	at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
	at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
	at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
	at java.net.PlainSocketImpl.connect(Unknown Source)
	at java.net.SocksSocketImpl.connect(Unknown Source)
	at java.net.Socket.connect(Unknown Source)
	at redis.clients.jedis.Connection.connect(Connection.java:148)
	... 6 more

解决方法:
在Linux中关闭防火墙:service iptables stop

你可能感兴趣的:(Jedis连接Redis出现connect timed out)