Coder Social home page Coder Social logo

"Unknown reply" exception. about jedis HOT 8 CLOSED

redis avatar redis commented on July 23, 2024
"Unknown reply" exception.

from jedis.

Comments (8)

xetorthio avatar xetorthio commented on July 23, 2024

This usually happens when you share Jedis instances among different threads.
Please make sure you are not doing that. If you need to do that, use JedisPool.

from jedis.

viulian avatar viulian commented on July 23, 2024

Thanks for the reply, I do use the pool.
For each service method invocation:

public void savePost(Post post) {
    Jedis conn = getPool().getResource();
    try {
    ....
    } finally {
        if (conn != null) {
            getPool().returnResource(conn);
        }
    }
}

The getPool method:

private JedisPool getPool() {
    if (pool == null) {
        pool = new JedisPool(server, port);
        pool.init();
    }

    return pool;
}

I'm not using Spring for services, but a JSF bean with Application scope.
I am using hot deploy in Tomcat (from Netbeans IDE) and at around the moment of the exception there were some redeploys before / after, since I was changing behavior of the request beans.

But the pool behavior is there from the beginning, I read about it in the wiki and applied it :)

from jedis.

xetorthio avatar xetorthio commented on July 23, 2024

Great! Can you write a small test that reproduces this? Maybe a connection is not used for some time and redis is closing it? I have the feeling it might be that. But a tests that reproduces this would be great!

from jedis.

johanhaleby avatar johanhaleby commented on July 23, 2024

I also experience a similar error (Jedis 1.3.1) but it doesn't seem to be deterministic so it's hard to write tests that demonstrates it. I get: "redis.clients.jedis.JedisException: Unknown reply: P" and "redis.clients.jedis.JedisException: Unknown reply: ^@".
E.g.
redis.clients.jedis.JedisException: Unknown reply: P
at redis.clients.jedis.Protocol.process(Protocol.java:65)
at redis.clients.jedis.Protocol.read(Protocol.java:116)
at redis.clients.jedis.Connection.getIntegerReply(Connection.java:131)
at redis.clients.jedis.Jedis.hexists(Jedis.java:787)

I'm also using the JedisPool to get a Jedis instance before each invocation.

from jedis.

xetorthio avatar xetorthio commented on July 23, 2024

This happens because Redis by default closes idle connections after 300 seconds and the pool is not checking connections in the ready queue.
You should use Jedis 1.5.0 RC2 which uses the apache pool instead and you can tell that pool to test on borrow, which will ensure that the connection is up and running.

from jedis.

johanhaleby avatar johanhaleby commented on July 23, 2024

Thanks for your reply. Would you recommend using 1.5.0 RC2 in a business critical system or would you rather advice me to wait until the final 1.5.0 release?

from jedis.

xetorthio avatar xetorthio commented on July 23, 2024

It is in maven central already.
Final 1.5.0 will be released Friday. There won't be many changes. Lots of the big changes were pushed to 1.6.0, so I would say you can go ahead and use it. Or you can wait until Friday for the final 1.5.0. :)

from jedis.

xetorthio avatar xetorthio commented on July 23, 2024

This issue has been handled before using testOnBorrow
So I'm closing this since there is a solution. You'll find information on this in:
https://github.com/xetorthio/jedis/wiki
under "Using Jedis in a multithreaded environment"

from jedis.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.