我正在使用johm缓存和检索redis数据库中的一些数据。但是,当我想像使用johm.getall(mt.class)那样拉取对象数据时;例如,我得到一个异常

   redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: Read timed out
        at redis.clients.jedis.Protocol.process(Protocol.java:85)
        at redis.clients.jedis.Protocol.read(Protocol.java:137)
        at redis.clients.jedis.Connection.getIntegerReply(Connection.java:191)
        at redis.clients.jedis.Jedis.exists(Jedis.java:83)
        at redis.clients.johm.Nest.exists(Nest.java:117)
        at redis.clients.johm.JOhm.get(JOhm.java:55)
        at redis.clients.johm.JOhm.getAll(JOhm.java:393)
        at com.smsgh.smpp.Components.Database.MTProc.getAll(MTProc.java:67)
..................................................
        Caused by: java.net.SocketTimeoutException: Read timed out
        at java.net.SocketInputStream.socketRead0(Native Method)
        at java.net.SocketInputStream.read(Unknown Source)
        at java.net.SocketInputStream.read(Unknown Source)
        at java.net.SocketInputStream.read(Unknown Source)
        at redis.clients.util.RedisInputStream.fill(RedisInputStream.java:109)
        at redis.clients.util.RedisInputStream.readByte(RedisInputStream.java:45)
        at redis.clients.jedis.Protocol.process(Protocol.java:70)
        ... 31 more

这是我的johm设置
public class Redis {

    @SuppressWarnings("unused")
    private static Logger logger = LoggerFactory.getLogger(Redis.class);
    private static Redis redis = new Redis();
    protected JedisPool jedisPool;

    /**
     *
     */
    private Redis() {
        jedisPool = new JedisPool(new Config(), "localhost", 6379);
        JOhm.setPool(jedisPool);
        // purgeRedis();
    }

    protected void purgeRedis() {
        Jedis jedis = jedisPool.getResource();
        jedis.flushAll();
        jedisPool.returnResource(jedis);
    }

    public synchronized static Redis getInstance() {
        if (redis == null)
            redis = new Redis();
        return redis;
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        throw new CloneNotSupportedException("Clone is not allowed.");
    }

}

这就是检索功能:
public Set<MT> getAll(){
    return JOhm.getAll(MT.class);
}

我的redis开始运行了
有人能帮我吗?

最佳答案

这是一个连接问题。
请检查您正在尝试连接到正确的地址,并且您的所有连接配置都正确。

关于java - 杰迪斯和约翰异常(exception),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19595247/

10-15 09:13