上代码:
/**获取a,然后获取b,然后删除c,对同一个key有多次操作,按照opsForHash()的写法
* 每次都是redisTemplate.opsForHash().xxx("key","value")写法很是啰嗦
*/
int result = (Integer) redisTemplate.opsForHash().get("hash-key","a");
result = (Integer)redisTemplate.opsForHash().get("hash-key","b");
redisTemplate.opsForHash().delete("hash-key","c");
/**
* boundHashOps()则是直接将key和boundHashOperations对象进行了绑定,
* 后续直接通过boundHashOperations对象进行相关操作即可,写法简洁,不需要
* 每次都显式的将key写出来
*/
BoundHashOperations<String, String, Object> boundHashOperations = redisTemplate.boundHashOps("hash-key");
result = (Integer) boundHashOperations.get("a");
result = (Integer) boundHashOperations.get("b");
boundHashOperations.delete("c");
//以上是个人拙见,如有不对,欢迎指正