开发者社区> 问答> 正文

redis 400 请求报错 

redis It seems like server has closed the connection

redis版本:redis-3.0.3
jedis版本:2.3.0
系统:OS X Yosemite 10.10.5

Subscribe.class
JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
        jedisPoolConfig.setMaxIdle(10);
        jedisPoolConfig.setMaxWait(4000);
        jedisPoolConfig.setTestOnBorrow(true);
        JedisPool jedisPool = new JedisPool(jedisPoolConfig, "127.0.0.1", 6379);

        final Jedis jedis = jedisPool.getResource();
        System.out.println(jedis.configGet("timeout"));
        System.out.println(jedis.configGet("tcp-keepalive"));
        final JedisPubSub jedisPubSub = new JedisPubSub() {
            @Override
            public void onMessage(String channel, String message) {
                System.out.println("onMessage");
            }

            @Override
            public void onPMessage(String pattern, String channel, String message) {
                System.out.println("onPMessage");
            }

            @Override
            public void onSubscribe(String channel, int subscribedChannels) {
                System.out.println("onSubscribe");
            }

            @Override
            public void onUnsubscribe(String channel, int subscribedChannels) {
                System.out.println("onUnsubscribe");
            }

            @Override
            public void onPUnsubscribe(String pattern, int subscribedChannels) {
                System.out.println("onPUnsubscribe");
            }

            @Override
            public void onPSubscribe(String pattern, int subscribedChannels) {
                System.out.println("onPSubscribe");
            }
        };
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH����ss");
        System.out.println(dateFormat.format(new Date()));
        jedis.subscribe(jedisPubSub, "/atm/test");
Publish.class
Jedis jedis = new Jedis("127.0.0.1", 6379); jedis.publish("/atm/test", "lqiaing---hello");

2分钟后输出:

[timeout, 0]
[tcp-keepalive, 0]
2015-12-03 19:01:55
onSubscribe
Exception in thread "main" redis.clients.jedis.exceptions.JedisConnectionException: It seems like server has closed the connection.
	at redis.clients.util.RedisInputStream.readLine(RedisInputStream.java:91)
	at redis.clients.jedis.Protocol.processMultiBulkReply(Protocol.java:110)
	at redis.clients.jedis.Protocol.process(Protocol.java:63)
	at redis.clients.jedis.Protocol.read(Protocol.java:122)
	at redis.clients.jedis.Connection.getObjectMultiBulkReply(Connection.java:196)
	at redis.clients.jedis.JedisPubSub.process(JedisPubSub.java:88)
	at redis.clients.jedis.JedisPubSub.proceed(JedisPubSub.java:83)
	at redis.clients.jedis.Jedis.subscribe(Jedis.java:1974)
	at Subscribe.main(Subscribe.java:63)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)

请求帮助。

展开
收起
kun坤 2020-05-29 22:58:41 815 0
1 条回答
写回答
取消 提交回答
  • 折腾好几天了都搞不定,有大神说貌似是跟tcp_tw_reuse和tcp_tw_recycle有关,但是百度看了下,这2个东西正常是不需要改变的,大家难道就没有遇到这个问题吗? ###### jedis这玩意儿会去拿连接,不知道你设置的空闲时间是多少,如果当前系统的访问量不是非常大,想必是会超过这个空闲时间的,当超过之后应该是会回收这个连接,导致你发现再获取的时候获取不到了。所以你可以去看下你设置的那个超时时间或者空闲时间,调整为大一点或者无限大。有一个坑爹点的方案就是每次用的时候用完就干掉它,下次用的时候再取获取一个新的jedis对象  ######timeout 设置成0了哦。

    2020-05-29 22:58:48
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
ApsaraDB for Redis——与创客同行 立即下载
微博的Redis定制之路 立即下载
云数据库Redis版的开源之路 立即下载