今天准备写第一个jedis程序,刚刚写完测试程序就难产了.然后接下来去找度娘搜了一下午,包括啥该配置文件,防火墙之类的.结果是阿里云服务器需要自己配置开放的端口号.
首先来给错误信息
redis.clients.jedis.exceptions.JedisConnectionException: Failed connecting to host xxxxxxx:6379
at redis.clients.jedis.Connection.connect(Connection.java:204)
at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:100)
at redis.clients.jedis.Connection.sendCommand(Connection.java:125)
at redis.clients.jedis.Connection.sendCommand(Connection.java:120)
at redis.clients.jedis.BinaryClient.ping(BinaryClient.java:113)
at redis.clients.jedis.BinaryJedis.ping(BinaryJedis.java:186)
at site.xietao.jedis.MyRedis.test(MyRedis.java:39)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
....
Caused by: java.net.SocketTimeoutException: connect timed out
这是代码
@Test
public void test(){
Jedis redis = new Jedishost(host,port,timeout);
System.out.println(redis.ping());
}
解决办法:去阿里云控制台添加如下图所示的信息:
然后再次运行程序: