1.通过实现一个定时任务,来定时访问远程redis服务;
2.通过设置一定的重试次数,来访问远程redis服务;
private final int retryCount=3;//重试次数
for (int retry=0;retry<retryCount;retry++)
{
try
{
String obj = (String)redisTemplate.opsForValue().get(key);
if (timeout>0)
redisTemplate.opsForValue().set(key, obj,timeout, TimeUnit.MINUTES);
return obj;
} catch (RedisCommandTimeoutException e)
{
e.printStackTrace();
} catch (Exception e)
{
e.printStackTrace();
return null;
}
}