Redis hash是一个string类型的field和value的映射表,hash特别适合用于存储对象
Redis中每个hash可以存储2^32-1键值对(40多亿)
内容:正如JavaSE集合体系中的Map一样,只不过它是Map中嵌套了Map!
hset hsetnx hget hgetall hmset hmget hdel hlen hkeys
一个大Key,一个小key
命令行
API查询
@Test
public void method5(){
log.info("--开始哈希Hash测试");
final String key = "SpringBootRedis:Hash:Key:V2";
redisTemplate.delete(key);
HashOperations<String, String, String> hashOperations = redisTemplate.opsForHash();
hashOperations.put(key, "10010", "zhangsan");
hashOperations.put(key, "10011", "lisi");
hashOperations.put(key, "10012", "wangwu");
Map<String, String> dataMap = Maps.newHashMap();
dataMap.put("10013","zhaoliu");
hashOperations.putAll(key, dataMap);
log.info("--哈希hash-获取列表所有元素:{}", hashOperations.entries(key));
log.info("--哈希hash-获取10012的元素:{}", hashOperations.get(key, "10012"));
log.info("--哈希hash-获取所有元素的field列表:{}", hashOperations.keys(key));
log.info("--哈希hash-获取所有元素的value列表:{}",hashOperations.values(key));
log.info("--哈希hash-10013成员是否存在:{}", hashOperations.hasKey(key, "10013"));
log.info("--哈希hash-10014成员是否存在:{}",hashOperations.hasKey(key, "10014"));
log.info("--哈希hash-删除元素10010 10011:{}",hashOperations.delete(key, "10010", "10011"));
log.info("--哈希hash-获取列表所有元素:{}", hashOperations.entries(key));
log.info("--哈希hash-获取列表元素个数:{}", hashOperations.size(key));
}