Reputation: 31885
I am using jedis in my Java program.Its version is 2.9.0.
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.0</version>
<type>jar</type>
</dependency>
To avoid taking too much time query result by command keys(*)
, I store keys in a set, and when need all keys, query them from set using:
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;
}
There's about 8 million keys in set, and it throws Below timeout exception:
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]
Here's my JedisPool Configuration:
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;
}
I have set timeout to 10 hours but the error occurs in 1 hour. I have read Jedis from github but didn't find samples for my case. Can anyone help? Thanks!
Upvotes: 3
Views: 9093
Reputation: 6267
JedisPool
takes timeout as milliseconds. So your given timeout is actually 36 seconds, not 10 hours.
On a further note, instead of running SMEMBERS
on a set of 8 million members, you should consider using SSCAN
with smaller batch size.
Upvotes: 6