配置Jedis超时 [英] Configure Jedis timeout

查看:36
本文介绍了配置Jedis超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在完成 .hgetall()时遇到问题,这是我尝试过的事情:

I'm having problems completing an .hgetall(), here's what I've tried:

Jedis jedis = new Jedis(REDIS_MASTER_NODE);
jedis.connect();
jedis.configSet("timeout", "30");

Map<String, String> alreadyStored = jedis.hgetAll(redisTargetHash);

这就是我得到的:

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.getBinaryMultiBulkReply(Connection.java:199)
    at redis.clients.jedis.Jedis.hgetAll(Jedis.java:851)

这解决了这个问题:

Jedis jedis = new Jedis(REDIS_MASTER_NODE, 6379, 1800);

推荐答案

如果要设置Jedis连接 timeout ,则应使用为此专门设计的构造函数来实现:

If what you want to do is set Jedis connection timeout, you should do it using the special constructor made for that:

public Jedis(final String host, final int port, final int timeout)

您正在做的是在 jedis 的redis设置中设置超时.进行 CONFIG SET timeout 60 (配置超时60),意味着redis将在 60 秒后关闭空闲的客户端连接.这就是为什么您在Jedis中遇到例外的原因.

What you are doing is setting the timeout on redis settings from jedis. Doing CONFIG SET timeout 60, means that redis will close idle client connections after 60 seconds. That's why you get the exception in Jedis.

这篇关于配置Jedis超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆