zoukankan      html  css  js  c++  java
  • 关于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
    

      重点是:用命令行客户端就能正常连接。PS: 同一个电脑。

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

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

    百度一下,有的说需要将超时时常设置长一点,但是我设置成100000也没用。还是会报错。错误这里没有贴。

    换成windows系统,便可正常执行。看来跟mac本身有关呀。

    折腾了几天。

    真是醉了。

    终于,找到了原因:

    我的电脑开了代理。导致网络不行。

    吐了一口老血,涨了一点教训。

    不过找到原因了,很开心。

  • 相关阅读:
    布局(layout)文件图形界面不能显示:An error has occurred. See error log for more details. java.lang.NullPointe
    Mac下无法推出硬盘
    Excel导入导出数据库(MVC)
    json导入数据库
    XML导入数据库
    Excel表格导入数据库
    Lambda高级查询
    Linq高级查询
    多线程
    反射
  • 原文地址:https://www.cnblogs.com/ld-swust/p/6002482.html
Copyright © 2011-2022 走看看