org.springframework.data.redis.RedisConnectionFailureException Java Examples

The following examples show how to use org.springframework.data.redis.RedisConnectionFailureException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReqNoDrcAspect.java    From springboot-cloud with MIT License 6 votes vote down vote up
@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") ;
            }
        }
    }

}
 
Example #2
Source File: RedissonExceptionConverter.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Override
public DataAccessException convert(Exception source) {
    if (source instanceof RedisConnectionException) {
        return new RedisConnectionFailureException(source.getMessage(), source);
    }
    if (source instanceof RedisRedirectException) {
        RedisRedirectException ex = (RedisRedirectException) source;
        return new ClusterRedirectException(ex.getSlot(), ex.getUrl().getHost(), ex.getUrl().getPort(), source);
    }

    if (source instanceof RedisException) {
        return new InvalidDataAccessApiUsageException(source.getMessage(), source);
    }
    
    if (source instanceof DataAccessException) {
        return (DataAccessException) source;
    }
    
    if (source instanceof RedisTimeoutException) {
        return new QueryTimeoutException(source.getMessage(), source);
    }

    return null;
}
 
Example #3
Source File: RedissonExceptionConverter.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Override
public DataAccessException convert(Exception source) {
    if (source instanceof RedisConnectionException) {
        return new RedisConnectionFailureException(source.getMessage(), source);
    }

    if (source instanceof RedisException) {
        return new InvalidDataAccessApiUsageException(source.getMessage(), source);
    }
    
    if (source instanceof DataAccessException) {
        return (DataAccessException) source;
    }
    
    if (source instanceof RedisTimeoutException) {
        return new QueryTimeoutException(source.getMessage(), source);
    }

    return null;
}
 
Example #4
Source File: RedissonExceptionConverter.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Override
public DataAccessException convert(Exception source) {
    if (source instanceof RedisConnectionException) {
        return new RedisConnectionFailureException(source.getMessage(), source);
    }
    if (source instanceof RedisRedirectException) {
        RedisRedirectException ex = (RedisRedirectException) source;
        return new ClusterRedirectException(ex.getSlot(), ex.getUrl().getHost(), ex.getUrl().getPort(), source);
    }

    if (source instanceof RedisException) {
        return new InvalidDataAccessApiUsageException(source.getMessage(), source);
    }
    
    if (source instanceof DataAccessException) {
        return (DataAccessException) source;
    }
    
    if (source instanceof RedisTimeoutException) {
        return new QueryTimeoutException(source.getMessage(), source);
    }

    return null;
}
 
Example #5
Source File: RedissonExceptionConverter.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Override
public DataAccessException convert(Exception source) {
    if (source instanceof RedisConnectionException) {
        return new RedisConnectionFailureException(source.getMessage(), source);
    }
    if (source instanceof RedisRedirectException) {
        RedisRedirectException ex = (RedisRedirectException) source;
        return new ClusterRedirectException(ex.getSlot(), ex.getUrl().getHost(), ex.getUrl().getPort(), source);
    }

    if (source instanceof RedisException) {
        return new InvalidDataAccessApiUsageException(source.getMessage(), source);
    }
    
    if (source instanceof DataAccessException) {
        return (DataAccessException) source;
    }
    
    if (source instanceof RedisTimeoutException) {
        return new QueryTimeoutException(source.getMessage(), source);
    }

    return null;
}
 
Example #6
Source File: RedissonExceptionConverter.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Override
public DataAccessException convert(Exception source) {
    if (source instanceof RedisConnectionException) {
        return new RedisConnectionFailureException(source.getMessage(), source);
    }
    if (source instanceof RedisRedirectException) {
        RedisRedirectException ex = (RedisRedirectException) source;
        return new ClusterRedirectException(ex.getSlot(), ex.getUrl().getHost(), ex.getUrl().getPort(), source);
    }

    if (source instanceof RedisException) {
        return new InvalidDataAccessApiUsageException(source.getMessage(), source);
    }
    
    if (source instanceof DataAccessException) {
        return (DataAccessException) source;
    }
    
    if (source instanceof RedisTimeoutException) {
        return new QueryTimeoutException(source.getMessage(), source);
    }

    return null;
}
 
Example #7
Source File: RedissonExceptionConverter.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Override
public DataAccessException convert(Exception source) {
    if (source instanceof RedisConnectionException) {
        return new RedisConnectionFailureException(source.getMessage(), source);
    }
    if (source instanceof RedisRedirectException) {
        RedisRedirectException ex = (RedisRedirectException) source;
        return new ClusterRedirectException(ex.getSlot(), ex.getUrl().getHost(), ex.getUrl().getPort(), source);
    }

    if (source instanceof RedisException) {
        return new InvalidDataAccessApiUsageException(source.getMessage(), source);
    }
    
    if (source instanceof DataAccessException) {
        return (DataAccessException) source;
    }
    
    if (source instanceof RedisTimeoutException) {
        return new QueryTimeoutException(source.getMessage(), source);
    }

    return null;
}
 
Example #8
Source File: MqConfiguration.java    From demo-project with MIT License 6 votes vote down vote up
private Runnable loop() {
    return () -> {
        while (true) {
            AtomicInteger count = new AtomicInteger(0);
            topicMap.forEach((k, v) -> {
                try {
                    String message = mqUtil.getRedisTemplate().opsForList().rightPop(k);
                    if (message == null) {
                        count.getAndIncrement();
                    } else {
                        pushTask(v, message, k);
                    }
                } catch (RedisConnectionFailureException connException) {
                    log.error("redis无法连接,10s后重试", connException);
                    sleep(10);
                } catch (Exception e) {
                    log.error("redis消息队列异常", e);
                }
            });
            if (count.get() == topicMap.keySet().size()) {
                //当所有的队列都为空时休眠1s
                sleep(1);
            }
        }
    };
}
 
Example #9
Source File: RedissonExceptionConverter.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Override
public DataAccessException convert(Exception source) {
    if (source instanceof RedisConnectionException) {
        return new RedisConnectionFailureException(source.getMessage(), source);
    }
    if (source instanceof RedisRedirectException) {
        RedisRedirectException ex = (RedisRedirectException) source;
        return new ClusterRedirectException(ex.getSlot(), ex.getUrl().getHost(), ex.getUrl().getPort(), source);
    }

    if (source instanceof RedisException) {
        return new InvalidDataAccessApiUsageException(source.getMessage(), source);
    }
    
    if (source instanceof DataAccessException) {
        return (DataAccessException) source;
    }
    
    if (source instanceof RedisTimeoutException) {
        return new QueryTimeoutException(source.getMessage(), source);
    }

    return null;
}
 
Example #10
Source File: AggregateCounterSinkStoreConfiguration.java    From spring-cloud-stream-app-starters with Apache License 2.0 5 votes vote down vote up
@Bean
public RetryOperations retryOperations() {
	RetryTemplate retryTemplate = new RetryTemplate();
	retryTemplate.setRetryPolicy(new SimpleRetryPolicy(3,
			Collections.<Class<? extends Throwable>, Boolean>singletonMap(RedisConnectionFailureException.class, true)));
	ExponentialBackOffPolicy backOffPolicy = new ExponentialBackOffPolicy();
	backOffPolicy.setInitialInterval(1000L);
	backOffPolicy.setMaxInterval(1000L);
	backOffPolicy.setMultiplier(2);
	retryTemplate.setBackOffPolicy(backOffPolicy);
	return retryTemplate;
}
 
Example #11
Source File: RedisTemplateDriver.java    From redis-scheduler with MIT License 5 votes vote down vote up
@Override
public <T> T fetch(Function<Commands, T> block) {
    try {
        return redisTemplate.execute(new SessionCallback<T>() {
            @Override
            @SuppressWarnings("unchecked")
            public <K, V> T execute(RedisOperations<K, V> operations) throws DataAccessException {
                RedisConnectionCommands commands = new RedisConnectionCommands((RedisOperations<String, String>) operations);
                return block.apply(commands);
            }
        });
    } catch (RedisConnectionFailureException e) {
        throw new RedisConnectException(e);
    }
}
 
Example #12
Source File: EmailEmbeddedRedisConfigurationTest.java    From spring-boot-email-tools with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldEmailEmbeddedRedisConfigurationBeCreated() throws Exception {
    //Arrange
    int port = 6381;
    List<String> settings = ImmutableList.of("appendfilename email_appendonly.aof",
            "save 900 1");

    //Act
    EmailEmbeddedRedisConfiguration emailEmbeddedRedisConfiguration = new EmailEmbeddedRedisConfiguration(port, settings);

    //Assert
    assertions.assertThat(emailEmbeddedRedisConfiguration.emailEmbeddedRedis())
            .isNotNull();
    assertions.assertThat(emailEmbeddedRedisConfiguration.redisConnectionFactory())
            .isNotNull()
            .isInstanceOf(JedisConnectionFactory.class);


    //Act
    TimeUnit.SECONDS.sleep(3);
    emailEmbeddedRedisConfiguration.preDestroy();

    TimeUnit.SECONDS.sleep(1);
    //Assert
    assertions.assertThat(emailEmbeddedRedisConfiguration.emailEmbeddedRedis().isActive()).isFalse();

    exportException.expect(RedisConnectionFailureException.class);
    emailEmbeddedRedisConfiguration.redisConnectionFactory().getConnection();
}
 
Example #13
Source File: FieldValueCounterSinkStoreConfiguration.java    From spring-cloud-stream-app-starters with Apache License 2.0 5 votes vote down vote up
@Bean
public RetryOperations retryOperations() {
	RetryTemplate retryTemplate = new RetryTemplate();
	retryTemplate.setRetryPolicy(new SimpleRetryPolicy(3, Collections.<Class<? extends Throwable>, Boolean>singletonMap(RedisConnectionFailureException.class, true)));
	ExponentialBackOffPolicy backOffPolicy = new ExponentialBackOffPolicy();
	backOffPolicy.setInitialInterval(1000L);
	backOffPolicy.setMaxInterval(1000L);
	backOffPolicy.setMultiplier(2);
	retryTemplate.setBackOffPolicy(backOffPolicy);
	return retryTemplate;
}
 
Example #14
Source File: MessageConsumer.java    From redisq with MIT License 5 votes vote down vote up
protected void startDequeue() {
    String queueName = queue.getQueueName();

    threadingStrategy.start(queueName, new Runnable() {
        public void run() {
            try {
                processNextMessage();
            } catch (RedisConnectionFailureException e) {
                connectionFailureHandler.serverConnectionFailed(e);
            }
        }
    });
}
 
Example #15
Source File: DefaultConnectionFailureHandler.java    From redisq with MIT License 5 votes vote down vote up
public void serverConnectionFailed(RedisConnectionFailureException e) {
    int count = incrementFailureCounterAndGetCount();

    if (shouldLogError(count)) {
        logger.error("Could not connect to Redis after {} attempts, retrying in {}ms...", connectionFailuresCounter, millisToWaitAfterConnectionFailure,e);
        resetErrorCount();
    } else {
        logger.warn("Error connecting to Redis ({}), retrying in {}ms...", e.getMessage(), millisToWaitAfterConnectionFailure);
    }

    waitAfterConnectionFailure();
}
 
Example #16
Source File: JedisTaskService.java    From konker-platform with Apache License 2.0 5 votes vote down vote up
public void registerLastEventTimestamp(Event event) {

	    try {
            // register last timestamp
            final String eventTimestamp = Long.toString(event.getCreationTimestamp().getEpochSecond());
            redisTemplate.boundHashOps(LAST_TS_HASHNAME).put(event.getIncoming().getDeviceGuid(), eventTimestamp);
	    } catch (RedisConnectionFailureException ex) {
	        LOGGER.error("RedisConnectionFailureException: {}", ex.getMessage());
        }

	}
 
Example #17
Source File: RedisSpringDataCache.java    From jetcache with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean needLogStackTrace(Throwable e) {
    if (e instanceof RedisConnectionFailureException) {
        return false;
    }
    return true;
}
 
Example #18
Source File: DefaultConnectionFailureHandlerTest.java    From redisq with MIT License 4 votes vote down vote up
private void whenConnectionFailureTimes(int count) {
    for (int i = 0; i < count; i++) {
        defaultConnectionFailureHandler.serverConnectionFailed(new RedisConnectionFailureException("error!"));
    }
}
 
Example #19
Source File: ConnectionFailureHandler.java    From redisq with MIT License 2 votes vote down vote up
/**
 * Called when a connection failure happens. This method is called in the context of each message processing thread.
 * @param e the details on the connection failure
 */
void serverConnectionFailed(RedisConnectionFailureException e);