Redis:Hash数据结构使用

// hash存

// map对象
// 一般处理
Map map = BeanUtil.beanToMap(demo);
// 特殊处理
Map map = BeanUtil.beanToMap(
    demo,
    new HashMap<>(),
    CopyOptions.create()
    .setIgnoreNullValue(true)
    .setFieldValueEditor(
        (fieldName, fieldValue) -> {
            if (fieldValue == null) {
                return null;
            } else {
                return fieldValue.toString();
            }
        })
);

// redis的hash存储
stringRedisTemplate.opsForHash().putAll(key, map);
// 设置过期时间
stringRedisTemplate.expire(key, ttl, TimeUnit.MINUTES);


// hash取

Map map = stringRedisTemplate.opsForHash().entries(key);
Demo demo = BeanUtil.fillBeanWithMap(map, new Demo(), false);

你可能感兴趣的:(Redis,redis,数据结构,哈希算法,java)