org.springframework.data.redis.RedisConnectionFailureException: неизвестный ответ: a - PullRequest
0 голосов
/ 20 января 2019

Ошибка:

org.springframework.data.redis.RedisConnectionFailureException: Unknown reply: a; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Unknown reply: a
        at org.springframework.data.redis.connection.jedis.JedisExceptionConverter.convert(JedisExceptionConverter.java:67)
        at org.springframework.data.redis.connection.jedis.JedisExceptionConverter.convert(JedisExceptionConverter.java:41)
        at org.springframework.data.redis.PassThroughExceptionTranslationStrategy.translate(PassThroughExceptionTranslationStrategy.java:44)
        at org.springframework.data.redis.FallbackExceptionTranslationStrategy.translate(FallbackExceptionTranslationStrategy.java:42)
        at org.springframework.data.redis.connection.jedis.JedisConnection.convertJedisAccessException(JedisConnection.java:181)
        at org.springframework.data.redis.connection.jedis.JedisHashCommands.convertJedisAccessException(JedisHashCommands.java:433)
        at org.springframework.data.redis.connection.jedis.JedisHashCommands.hGetAll(JedisHashCommands.java:196)
        at org.springframework.data.redis.connection.DefaultedRedisConnection.hGetAll(DefaultedRedisConnection.java:862)
        at org.springframework.data.redis.core.DefaultHashOperations.lambda$entries$12(DefaultHashOperations.java:231)
        at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:224)
        at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:184)
        at org.springframework.data.redis.core.AbstractOperations.execute(AbstractOperations.java:95)
        at org.springframework.data.redis.core.DefaultHashOperations.entries(DefaultHashOperations.java:231)
        at com.nec.edgedisplay.common.doatier.redis.services.impl.DemographicRedisServiceImpl.findAll(DemographicRedisServiceImpl.java:88)
        at com.nec.edgedisplay.common.doatier.redis.services.impl.DemographicRedisServiceImpl$$FastClassBySpringCGLIB$$5cda2f2d.invoke(<generated>)
        at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
        at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:746)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
        at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
        at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688)
        at com.nec.edgedisplay.common.doatier.redis.services.impl.DemographicRedisServiceImpl$$EnhancerBySpringCGLIB$$25b48e11.findAll(<generated>)
        at com.nec.edgedisplay.common.biztier.services.impl.DemographicServiceImpl.sendDataToEventHub(DemographicServiceImpl.java:67)
        at com.nec.edgedisplay.da.scheduler.EventHubScheduler.scheduleDemographicCacheTransferToEventHub(EventHubScheduler.java:60)
        at sun.reflect.GeneratedMethodAccessor71.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65)
        at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
    Caused by: redis.clients.jedis.exceptions.JedisConnectionException: Unknown reply: a
        at redis.clients.jedis.Protocol.process(Protocol.java:164)
        at redis.clients.jedis.Protocol.read(Protocol.java:215)
        at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:340)
        at redis.clients.jedis.Connection.getBinaryMultiBulkReply(Connection.java:276)
        at redis.clients.jedis.BinaryJedis.hgetAll(BinaryJedis.java:1028)
        at org.springframework.data.redis.connection.jedis.JedisHashCommands.hGetAll(JedisHashCommands.java:194)
        ... 29 common frames omitted

Ниже мой код:

    @Configuration
    public class RedisConnector {

        private static final Logger LOGGER = LoggerFactory.getLogger(RedisConnector.class);

        /** The host name. */
        @Value("${spring.redis.host}")
        private String hostName;

        /** The port. */
        @Value("${spring.redis.port}")
        private int port;

        /**
         * Jedis connection factory.
         *
         * @return the jedis connection factory
         */
        @Bean
        JedisConnectionFactory jedisConnectionFactory() {

            JedisConnectionFactory jedisConnectionFactory = null;

            try {
                RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration(hostName,
                        port);
                jedisConnectionFactory = new JedisConnectionFactory(redisStandaloneConfiguration);
                jedisConnectionFactory.getPoolConfig().setMaxTotal(128);
                jedisConnectionFactory.getPoolConfig().setMaxIdle(128);
            } catch (RedisConnectionFailureException e) {
                LOGGER.error("Connection break with redis " + e.getMessage());
            }

            return jedisConnectionFactory;
        }

        /**
         * Redis template.
         *
         * @return the redis template
         */
        @Bean
        public RedisTemplate<String, Object> redisTemplate() {
            final RedisTemplate<String, Object> template = new RedisTemplate<String, Object>();
            template.setConnectionFactory(jedisConnectionFactory());
            template.setValueSerializer(new GenericToStringSerializer<Object>(Object.class));
            template.setEnableTransactionSupport(true);
            return template;
        }

    }
    -------------------------------------------------------------------------
    @Repository
    public class CrowdCountRedisServiceImpl implements ICrowdCountRedisService {

        private static final Logger LOGGER = LoggerFactory.getLogger(CrowdCountRedisServiceImpl.class);

        /** The Constant KEY. */
        private static final String KEY = CrowdCount.class.getName();

        /** The redis template. */
        private RedisTemplate<String, Object> redisTemplate;

        /** The hash operations. */
        private HashOperations<String, Long, CrowdCount> hashOperations;



        /**
         * Instantiates a new crowd count redis service impl.
         *
         * @param redisTemplate the redis template
         */
        @Autowired
        public CrowdCountRedisServiceImpl(RedisTemplate<String, Object> redisTemplate) {
            this.redisTemplate = redisTemplate;
        }

        /**
         * Inits the rest template.
         */
        @PostConstruct
        private void init(){
            hashOperations = redisTemplate.opsForHash();
        }


        @Override
        public void save(CrowdCount crowdCount) {
            LOGGER.info("Inside save method of redis for crowd count");
            if(crowdCount != null){
                hashOperations.put(KEY, crowdCount.getDataStoreId(), crowdCount);
                LOGGER.info("CrowdCount object saved in redis is --------- >"+crowdCount.toString());
            }
            else{
                LOGGER.error("CrowdCount object is null");
            }
        }


        @Override
        public CrowdCount find(Long id) {
            if(id != null){
                return hashOperations.get(KEY, id);
            }else{
                LOGGER.error("Id is missing");
                return null;
            }

        }

        /* (non-Javadoc)
         * @see 
         */
        @Override
        public Map<Long, CrowdCount> findAll() {
            return hashOperations.entries(KEY);
        }


        @Override
        public void update(CrowdCount crowdCount) {
            if(crowdCount != null){
                hashOperations.put(KEY, crowdCount.getDataStoreId(), crowdCount);
            }else{
                LOGGER.error("Object to be updated can not be null");
            }

        }

        @Override
        public void deleteAll() {
            hashOperations.delete(KEY); 

        }

        /* (non-Javadoc)
         * @see 
         */
        @Override
        public void deleteById(Long id) {
            if(id != null){
                hashOperations.delete(KEY, id); 
            }else{
                LOGGER.error("Id can not be null");
            }


        }

    }

Так же, как и в вышеупомянутом сервисе, у меня есть несколько сервисов, которые часто взаимодействуют с redis, но после запуска в течение нескольких дней я получаю вышеуказанное исключение, поэтому, чтобы решить проблему, мне нужно очистить кэш redis и перезапустить jar, что стоило мне данные теряются каждый раз. Конфигурация: java 8, Redistemplate с пружинной загрузкой и Jedis 2.9.0

...