我正在使用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启动并运行 有人可以帮我吗?
答案 0 :(得分:0)
这是一个连接问题。
检查您是否正在尝试连接到正确的地址,并且所有连接配置都是正确的。