'There is a ClassCastException when reading data from reids

There is a ClassCastException when reading data from reids, but the actual quantity type is correct, and this happens for a period of time. After restarting the service, the problem is solved, but it appears again in some days!
``` @Configuration
    public class RedisConfig {
        /**
         * FastJson序列化
         *
         * @param factory
         * @return
         * @author Hes
         */
        @Bean
        public RedisTemplate fastJsonRedisTemplate(RedisConnectionFactory factory) throws Exception {
            RedisTemplate redisTemplate = new RedisTemplate();
            redisTemplate.setConnectionFactory(factory);
            FastJsonSerializer serializer = new FastJsonSerializer<Object>(Object.class);
            redisTemplate.setValueSerializer(serializer);
            redisTemplate.setKeySerializer(new StringRedisSerializer());
            redisTemplate.afterPropertiesSet();
            return redisTemplate;
        }
    
        /**
         * fst序列化
         *
         * @param factory
         * @return
         * @author Hes
         */
        @Bean
        public RedisTemplate<String, Object> fstRedisTemplate(RedisConnectionFactory factory) {
            RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
            redisTemplate.setConnectionFactory(factory);
            FSTSerializer<Object> serializer = new FSTSerializer<>();
            redisTemplate.setDefaultSerializer(serializer);
            redisTemplate.setKeySerializer(RedisSerializer.string());
            redisTemplate.afterPropertiesSet();
            return redisTemplate;
        }
    }



public static List<DataMap> search(String orgNo) {
        List<DataMap> datas = RedisKit.getMapValue(CACHE_AREA, orgNo);
        return datas;
    }

   public static <T> T getMapValue(String cacheKey, String valueKey) {
        T t = null;
        if (StrUtil.isNotBlank(cacheKey) && redisTemplate != null) {
            t = (T) redisTemplate.opsForHash().get(cacheKey, valueKey);
        }
        return t;
    }
```

** 2022-02-23 09:01:08.405 [http-nio-22000-exec-6] ERROR com.hnmqet.framework.exception.ExceptionCatch - catch exception:java.lang.ClassCastException: java.lang.String cannot be cast to java.util.List at com.hnmqet.framework.cache.AreaCache.search(AreaCache.java:17) at com.hnmqet.jail.base.service.area.impl.AreaMainServiceImpl.listAreaMain(AreaMainServiceImpl.java:83) at com.hnmqet.jail.base.service.area.impl.AreaMainServiceImpl.listAreaGroup(AreaMainServiceImpl.java:161) at com.hnmqet.jail.base.service.area.impl.AreaMainServiceImpl$$FastClassBySpringCGLIB$$6f19d178.invoke()**



Solution 1:[1]

Did you exactly find which "orgNo" cause this exception? If so, you should check the value in your hash map for related "orgNo" key. You can do it from CLI using this command by the way: https://redis.io/commands/hget/

I guess some test data was not written into Redis as expected.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alper Derya