Getting JedisConnectionException in one particular operation, need help

158 views
Skip to first unread message

Chanchal Mishra

unread,
Apr 19, 2020, 7:18:26 AM4/19/20
to Jedis

I am trying to delete keys of a specific pattern from redis server but while executing it, it shows:

redis.clients.jedis.exceptions.JedisConnectionException: Unexpected end of stream.
    at redis.clients.util.RedisInputStream.ensureFill(RedisInputStream.java:199)
    at redis.clients.util.RedisInputStream.readByte(RedisInputStream.java:40)
    at redis.clients.jedis.Protocol.process(Protocol.java:153)
    at redis.clients.jedis.Protocol.read(Protocol.java:218)
    at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:341)
    at redis.clients.jedis.Connection.getBinaryMultiBulkReply(Connection.java:277)
    at redis.clients.jedis.Jedis.keys(Jedis.java:284)

For your reference, my server timeout value is 0 and jedis version which I have been using is 2.10.2. Following is the code snippet which I am trying to execute:

try {
    Set<String> keys = jedis.keys(pattern);
    jedis.del(keys.toArray(new String[keys.size()]));
} catch(Exception e) {
    log.error("Failed to delete key entry for pattern {0}", pattern);
    throw e;
}

here pattern is the string we are trying to delete.


The code is running fine in local, no issues with any jedis function.

  1. When running on remote server, other functions are getting executed correctly except this delete keys method. Precisely while executing jedis.keys()
Any idea how to resolve this issue?


Chanchal Mishra

unread,
Apr 19, 2020, 7:18:26 AM4/19/20
to Jedis

Any suggestion to resolve the error?


Allan Wax

unread,
Apr 20, 2020, 12:36:08 PM4/20/20
to Jedis
keys is an 'evil' function that stops the server while hunting for keys.  It will take as long as it takes and if you have a lot of keys, could takes minutes.  Switch to using SCAN instead.  It allows you to get keys in blocks of a certain size.
Reply all
Reply to author
Forward
0 new messages