本文整理汇总了Java中org.springframework.data.redis.RedisConnectionFailureException类的典型用法代码示例。如果您正苦于以下问题:Java RedisConnectionFailureException类的具体用法?Java RedisConnectionFailureException怎么用?Java RedisConnectionFailureException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RedisConnectionFailureException类属于org.springframework.data.redis包,在下文中一共展示了RedisConnectionFailureException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateShopInfo
import org.springframework.data.redis.RedisConnectionFailureException; //导入依赖的package包/类
/**
* 单条修改
* 更新商店信息,先读出list,然后根据shopId进行修改
*/
public int updateShopInfo(ShopInfo shopInfo) {
List<ShopInfo> shopInfoList = new ArrayList<ShopInfo>();
shopInfoList = queryShopInfos(shopInfo);
for (int i = 0; i < shopInfoList.size(); i++) {
if (shopInfo.getShop_id() == shopInfoList.get(i).getShop_id()) {
shopInfoList.set(i, shopInfo);
}
}
try {
redisTemplate.opsForHash().put(SHOP_INFO_KEY, shopInfo.getShop_owner(), shopInfoList);
} catch (RedisConnectionFailureException e) {
return 0;
}
return 1;
}
示例2: queryShopProbeInfo
import org.springframework.data.redis.RedisConnectionFailureException; //导入依赖的package包/类
/**
* 查询店铺的探针信息
* */
public List<ProbeInfo> queryShopProbeInfo(ShopInfo shopInfo) {
List<ProbeInfo> results = new ArrayList<ProbeInfo>();
try {
Map<Object, Object> map = redisTemplate.opsForHash().entries(PROBE_INFO_KEY);
if (map.containsKey(shopInfo.getShop_owner())) {
results = (List<ProbeInfo>) map.get(shopInfo.getShop_owner());
}
for (ProbeInfo pi:results) {
if (pi.getShop_id() != shopInfo.getShop_id()) {
results.remove(pi);
}
}
} catch (RedisConnectionFailureException e) {
return null;
}
return results;
}
示例3: before
import org.springframework.data.redis.RedisConnectionFailureException; //导入依赖的package包/类
@Before("checkRepeat()")
public void before(JoinPoint joinPoint) throws Exception {
BaseRequest request = getBaseRequest(joinPoint);
if(request != null){
final String reqNo = request.getReqNo();
if(StringUtil.isEmpty(reqNo)){
throw new RuntimeException("reqNo不能为空");
}else{
try {
String tempReqNo = redisTemplate.opsForValue().get(prefixReq +reqNo);
logger.debug("tempReqNo="+tempReqNo);
if((StringUtil.isEmpty(tempReqNo))){
redisTemplate.opsForValue().set(prefixReq + reqNo, reqNo, day, TimeUnit.DAYS);
}else{
throw new RuntimeException("请求号重复,reqNo="+reqNo);
}
} catch (RedisConnectionFailureException e){
logger.error("redis操作异常",e);
throw new RuntimeException("need redisService") ;
}
}
}
}
示例4: before
import org.springframework.data.redis.RedisConnectionFailureException; //导入依赖的package包/类
@Before("checkRepeat()")
public void before(JoinPoint joinPoint) throws Exception {
BaseRequest request = getBaseRequest(joinPoint);
if(request != null){
final String reqNo = request.getReqNo();
if(StringUtil.isEmpty(reqNo)){
throw new SBCException(StatusEnum.REPEAT_REQUEST);
}else{
try {
String tempReqNo = redisTemplate.opsForValue().get(prefixReq +reqNo);
logger.debug("tempReqNo=" + tempReqNo);
if((StringUtil.isEmpty(tempReqNo))){
redisTemplate.opsForValue().set(prefixReq + reqNo, reqNo, day, TimeUnit.DAYS);
}else{
throw new SBCException("请求号重复,"+ prefixReq +"=" + reqNo);
}
} catch (RedisConnectionFailureException e){
logger.error("redis操作异常",e);
throw new SBCException("need redisService") ;
}
}
}
}
示例5: doRun
import org.springframework.data.redis.RedisConnectionFailureException; //导入依赖的package包/类
/**
* Connection failure safe run loop.
*/
protected void doRun() throws Throwable {
while (run.get()) {
try {
// Test connection to avoid marking this worker as running and fail immediately afterwards.
workerDao.ping();
setWorkerState(WorkerState.RUNNING);
eventBus.publishEvent(new WorkerStart(this));
startup();
poll();
} catch (RedisConnectionFailureException e) {
// Do not report the same connection error over and over again.
log.warn("Worker {} failed to connect to Redis. Restarting in {} ms.", getName(), RESTART_DELAY_MS);
if (!WorkerState.FAILED.equals(state.getState())) {
// No possibility to store the state in Redis...
this.state.setState(WorkerState.FAILED);
eventBus.publishEvent(new WorkerFailure(this));
}
Thread.sleep(RESTART_DELAY_MS);
}
}
}
示例6: redisIsDown
import org.springframework.data.redis.RedisConnectionFailureException; //导入依赖的package包/类
@Test
public void redisIsDown() throws Exception {
RedisConnection redisConnection = mock(RedisConnection.class);
RedisConnectionFactory redisConnectionFactory = mock(
RedisConnectionFactory.class);
given(redisConnectionFactory.getConnection()).willReturn(redisConnection);
given(redisConnection.info())
.willThrow(new RedisConnectionFailureException("Connection failed"));
RedisHealthIndicator healthIndicator = new RedisHealthIndicator(
redisConnectionFactory);
Health health = healthIndicator.health();
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
assertThat(((String) health.getDetails().get("error"))
.contains("Connection failed"));
verify(redisConnectionFactory).getConnection();
verify(redisConnection).info();
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:18,代码来源:RedisHealthIndicatorTests.java
示例7: redisIsDown
import org.springframework.data.redis.RedisConnectionFailureException; //导入依赖的package包/类
@Test
public void redisIsDown() throws Exception {
RedisConnection redisConnection = mock(RedisConnection.class);
RedisConnectionFactory redisConnectionFactory = mock(
RedisConnectionFactory.class);
given(redisConnectionFactory.getConnection()).willReturn(redisConnection);
given(redisConnection.info())
.willThrow(new RedisConnectionFailureException("Connection failed"));
RedisHealthIndicator healthIndicator = new RedisHealthIndicator(
redisConnectionFactory);
Health health = healthIndicator.health();
assertEquals(Status.DOWN, health.getStatus());
assertTrue(((String) health.getDetails().get("error"))
.contains("Connection failed"));
verify(redisConnectionFactory).getConnection();
verify(redisConnection).info();
}
示例8: attemptTriggerNextTask
import org.springframework.data.redis.RedisConnectionFailureException; //导入依赖的package包/类
private void attemptTriggerNextTask() throws InterruptedException {
try {
boolean taskTriggered = triggerNextTaskIfFound();
// if a task was triggered, we'll try again immediately. This will help to speed up the execution
// process if a few tasks were due for execution.
if (!taskTriggered) {
sleep(pollingDelayMillis);
}
resetRetriesAttemptsCount();
} catch (RedisConnectionFailureException e) {
incrementRetriesAttemptsCount();
log.warn(String.format("Connection failure during scheduler polling (attempt %s/%s)", numRetriesAttempted, maxRetriesOnConnectionFailure));
}
}
示例9: setProperty
import org.springframework.data.redis.RedisConnectionFailureException; //导入依赖的package包/类
/**
* 更新Property以mmac作为field的记录,Value 为propertyBean对象
* 由于一个店铺有多个探针,而redis是以K-V的方式,如果以shopId作为字段,
* 就会让一个shopId有且仅有一个探针mmac,如果一个店铺里面有2个及其以上的mmac,
* 就不能方便记录,所以用一个mmac对应一个店铺的方式来记录,比较方便。
* */
public int setProperty(PropertyBean propertyBean) {
try {
redisTemplate.opsForHash().put(PROPERTY_BEAN_KEY,propertyBean.getMmac(),propertyBean);
}catch (RedisConnectionFailureException e){
return 0;
}
return 1;
}
示例10: addProperty
import org.springframework.data.redis.RedisConnectionFailureException; //导入依赖的package包/类
/**
* 添加Property以mmac作为field的记录,Value 为propertyBean对象
* */
public int addProperty(PropertyBean propertyBean){
try {
//redisTemplate.opsForHash().put(PROPERTY_BEAN_KEY,propertyBean.getMmac(),propertyBean);
redisTemplate.opsForHash().put(PROPERTY_BEAN_KEY,propertyBean.getMmac(), JSON.toJSONString(propertyBean));
}catch (RedisConnectionFailureException e){
return 0;
}
return 1;
}
示例11: queryProperty
import org.springframework.data.redis.RedisConnectionFailureException; //导入依赖的package包/类
/**
* 查询field为 mmac的记录
* */
public PropertyBean queryProperty(PropertyBean propertyBean) {
PropertyBean resultPropertyBean;
try {
resultPropertyBean = (PropertyBean) redisTemplate.opsForHash().get(PROPERTY_BEAN_KEY,propertyBean.getMmac());
}catch (RedisConnectionFailureException e){
return null;
}
return resultPropertyBean;
}
示例12: queryProbeInfos
import org.springframework.data.redis.RedisConnectionFailureException; //导入依赖的package包/类
/**
* 查询用户的所有探针信息
*
* */
public List<ProbeInfo> queryProbeInfos(ProbeInfo probeInfo) {
List<ProbeInfo> results = new ArrayList<ProbeInfo>();
try {
Map<Object, Object> map = redisTemplate.opsForHash().entries(PROBE_INFO_KEY);
if (map.containsKey(probeInfo.getUser_name())) {
results = (List<ProbeInfo>) map.get(probeInfo.getUser_name());
}
} catch (RedisConnectionFailureException e) {
return null;
}
return results;
}
示例13: addProbeInfo
import org.springframework.data.redis.RedisConnectionFailureException; //导入依赖的package包/类
/**
* 给指定用户添加探针信息
*/
public int addProbeInfo(ProbeInfo probeInfo) {
List<ProbeInfo> probeInfoList = new ArrayList<ProbeInfo>();
try {
probeInfoList = queryProbeInfos(probeInfo);
probeInfoList.add(probeInfo);
redisTemplate.opsForHash().put(PROBE_INFO_KEY, probeInfo.getUser_name(), probeInfoList);
} catch (RedisConnectionFailureException e) {
return 0;
}
return 1;
}
示例14: afterPropertiesSet
import org.springframework.data.redis.RedisConnectionFailureException; //导入依赖的package包/类
@Override
public void afterPropertiesSet() {
LOGGER.info("Starting Redis policy evaluation cache.");
try {
String pingResult = this.decisionCacheRedisTemplate.getConnectionFactory().getConnection().ping();
LOGGER.info("Redis server ping: {}", pingResult);
} catch (RedisConnectionFailureException ex) {
LOGGER.error("Redis server ping failed.", ex);
}
}
示例15: ping
import org.springframework.data.redis.RedisConnectionFailureException; //导入依赖的package包/类
@Override
public void ping() {
redis.execute((RedisConnection connection) -> {
if (!"PONG".equals(connection.ping())) {
throw new RedisConnectionFailureException("Ping failed.");
}
return null;
});
}