JedisConnectionException Read Time Out



我在Java程序中使用jedis。其版本为2.9.0

         <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
            <version>2.9.0</version>
            <type>jar</type>
        </dependency>

为了避免通过命令keys(*)查询结果花费太多时间,我将键存储在一个集合中,当需要所有键时,使用以下命令从集合中查询它们:

public Set<String> getKeysFromDailySet(String day) {
    Jedis jedis = jedisPool.getResource();
    Set<String> keys = new HashSet<>();
    try {
        keys = jedis.smembers(day);
        jedis.close();
    } catch (Exception e) {
        logger.error("fail get keys from daily set {}", day);
    }
    return keys;
}

集合中大约有 800 万个密钥,它抛出以下超时异常:

  Caused by: redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: Read timed out
            at redis.clients.util.RedisInputStream.ensureFill(RedisInputStream.java:202) ~[scoring-20180118.jar:na]
            at redis.clients.util.RedisInputStream.readByte(RedisInputStream.java:40) ~[scoring-20180118.jar:na]
            at redis.clients.jedis.Protocol.process(Protocol.java:151) ~[scoring-20180118.jar:na]
            at redis.clients.jedis.Protocol.read(Protocol.java:215) ~[scoring-20180118.jar:na]
            at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:340) ~[scoring-20180118.jar:na]
            at redis.clients.jedis.Connection.getStatusCodeReply(Connection.java:239) ~[scoring-20180118.jar:na]
            at redis.clients.jedis.BinaryJedis.select(BinaryJedis.java:523) ~[scoring-20180118.jar:na]
            at redis.clients.jedis.JedisFactory.makeObject(JedisFactory.java:111) ~[scoring-20180118.jar:na]
            at org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:868) ~[scoring-20180118.jar:na]
            at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:435) ~[scoring-20180118.jar:na]
            at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:363) ~[scoring-20180118.jar:na]
            at redis.clients.util.Pool.getResource(Pool.java:49) ~[scoring-20180118.jar:na]
            ... 9 common frames omitted
    Caused by: java.net.SocketTimeoutException: Read timed out
            at java.net.SocketInputStream.socketRead0(Native Method) ~[na:1.7.0_80]
            at java.net.SocketInputStream.read(SocketInputStream.java:152) ~[na:1.7.0_80]
            at java.net.SocketInputStream.read(SocketInputStream.java:122) ~[na:1.7.0_80]
            at java.net.SocketInputStream.read(SocketInputStream.java:108) ~[na:1.7.0_80]
            at redis.clients.util.RedisInputStream.ensureFill(RedisInputStream.java:196) ~[scoring-20180118.jar:na]

这是我的绝地武池配置:

private final int HOUR_IN_SECONDS = 3600 * 10;  // 10 HOURS
private final Configuration config;
private final int INDEX;
public DatabaseConnection(String host, Configuration config) {
    this.config = config;
    this.INDEX = config.getRedisDbIndex();
    jedisPool = new JedisPool(buildJedisPoolConfiguration(), host, 6379, HOUR_IN_SECONDS, null, INDEX);
}
private JedisPoolConfig buildJedisPoolConfiguration() {
    JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
    jedisPoolConfig.setMaxTotal(this.config.getNumberOfThreads());
    return jedisPoolConfig;
}

我已将超时设置为 10 小时,但错误发生在 1 小时内。我已经从github阅读了Jedis,但没有找到我的案例样本。谁能帮忙?谢谢!

JedisPool将超时作为毫秒。因此,您给定的超时实际上是 36 秒,而不是 10 小时。

进一步说明,您应该考虑使用具有较小批大小的SSCAN,而不是在一组 800 万个成员上运行 SMEMBERS

相关内容

  • 没有找到相关文章

最新更新