• redis


    一、配置

     <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">  
            <property name="connectionFactory" ref="jedisConnectionFactory"></property>  
            <property name="keySerializer">  
                <bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/>  
            </property>  
               <property name="valueSerializer">  
                <bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/>  
            </property>  
        </bean>

    方式一:

    二、插入

    /**
         * 将检验报告存入redis
         * @param response
         * @param key
         */
        private void setRedis(ResponseResult<LisReponse> response,String key,String patientType){
            String redisKey = key;
            String mapKey = key + "-" + patientType + "-"+ (new Date().getTime());
            BoundHashOperations<String, String, Object> boundHashOperations = redisTemplate.boundHashOps(redisKey);  
            Map<String, Object> data = new HashMap<String, Object>(); 
            
            List<LisReponse> list = response.getItems();
            //根据检验日期倒序
            Collections.sort(list,new Comparator<LisReponse>() {
    
                @Override
                public int compare(LisReponse o1, LisReponse o2) {
                    return DateUtil.parseDate(o2.getCheck_time(), "yyyy/MM/dd HH:mm:ss").compareTo(DateUtil.parseDate(o1.getCheck_time(), "yyyy/MM/dd HH:mm:ss"));
                }
                
                
            });
            
            data.put(mapKey, list);
            boundHashOperations.putAll(data);  
        }

    三、获取

        /**
         * 从redis获取结果
         * @param key
         * @return
         */
        private Map<String ,Object> getResultFromRedis(String key){
             BoundHashOperations<String, String, Object> boundHashOperations = redisTemplate.boundHashOps(key);  
             Map<String, Object> data = boundHashOperations.entries();  
             return data;
        }
  • 相关阅读:
    redhat yum ISO 本地源
    md5sum的使用
    查看进程内存使用情况
    常见User-Agent大全
    aggregate和annotate使用
    Django logging配置
    Django 开发调试工具:Django-debug-toolbar
    浏览器的同源策略及跨域解决方案
    Python contenttypes组件
    Dajngo admin
  • 原文地址:https://www.cnblogs.com/binbang/p/5512387.html
Copyright © 2020-2023  润新知