Java代码连接远程Redis服务器,报如下错误
Exception in thread "main" redis.clients.jedis.exceptions.JedisConnectionException: java.net.UnknownHostException: 192.168.43.108 Exception in thread "main" redis.clients.jedis.exceptions.JedisConnectionException: java.net.UnknownHostException: 192.168.43.108 at redis.clients.jedis.Connection.connect(Connection.java:134) at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:69) at redis.clients.jedis.Connection.sendCommand(Connection.java:79) at redis.clients.jedis.Connection.sendCommand(Connection.java:75) at redis.clients.jedis.Jedis.get(Jedis.java:66) at com.adtec.redisdemo.RedisDemo.main(RedisDemo.java:17) Caused by: java.net.UnknownHostException: 192.168.43.108 at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184) 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:129) ... 5 more
源码:
public static void main(String[] args) { Jedis jedis = new Jedis(" 192.168.43.108",6379); String name = jedis.get("testMessage"); System.out.println(name); }
然后就排错排了一下午!!!
最后发现是ip前边多了个空格!!
万恶的空格!!!!
Linux端查看ip:
ifconfig
或
ip add
本地测试是否能连接远程服务器某端口:
打开cmd
telnet 192.168.43.108 6379