redis-string

    @Autowired
    protected StringRedisTemplate redisTemplate;

    public List<ContactsCustomAttribute> queryList(String userId, Integer type) {
        String key = STAGE_LIST_KEY_STAGE + userId + "_" + type;
        String attribute = redisTemplate.opsForValue().get(key);
        if (StringUtil.isNotBlank(attribute)) {
            List<ContactsCustomAttribute> contactsCustomAttributes = JsonUtil.fromJsonString(attribute, new TypeReference<List<ContactsCustomAttribute>>() {
            });
            return contactsCustomAttributes;
        }
        List<ContactsCustomAttribute> contactsCustomAttributes = contactsCustomAttributeDao.queryList(userId, type);
        redisTemplate.opsForValue().set(key, JsonUtil.toJsonString(contactsCustomAttributes), EXPIRATION_TIME, TimeUnit.MINUTES);
        return contactsCustomAttributes;
    }

 

posted @ 2018-06-26 16:40  wanhua.wu  阅读(172)  评论(0编辑  收藏  举报