redisspring boot中 使用redis hash 操作
Posted Angel挤一挤
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了redisspring boot中 使用redis hash 操作相关的知识,希望对你有一定的参考价值。
示例:
@Autowired StringRedisTemplate redisTemplate; @Override public void dealRedis(Dealer dealer) { dealer = dao.findByUid(dealer.getUid()); String tid = dealer.getTenementId(); HashOperations<String, Object, Object> ofh = redisTemplate.opsForHash(); Field[] declaredFields = dealer.getClass().getDeclaredFields(); for (Field declaredField : declaredFields) { String name = declaredField.getName(); if (name.equals("id") || name.equals("tid")){ continue; }else { ofh.increment(tid,name,111); } } Map<Object, Object> entries = ofh.entries(tid); System.out.println("获取Map>>>>>>>>>>>>>>>>>>>>>>>>>>"+entries.toString()); Set<Object> keys = ofh.keys(tid); System.out.println("获取KEY的SET>>>>>>>>>>>>>>>>>>>>>"+keys.toString()); List<Object> values = ofh.values(tid); System.out.println("获取VALUES的LIST>>>>>>>>>>>>>>>>>>>>>"+values.toString()); ofh.delete(tid,keys.toArray()); System.out.println("删除成功>>>>>>>>>>>>>>>>>>>>>>>>>>"); Map<Object, Object> entries2 = ofh.entries(tid); System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>"+entries2.toString()); for (Object key : keys) { ofh.increment(tid,key,111); } Map<Object, Object> entries3 = ofh.entries(tid); System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>"+entries3.toString()); for (Object key : keys) { ofh.increment(tid,key,-11); } Map<Object, Object> entries4 = ofh.entries(tid); System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>"+entries4.toString()); ofh.delete(tid,keys.toArray()); System.out.println("删除成功>>>>>>>>>>>>>>>>>>>>>>>>>>"); for (Object key : keys) { ofh.increment(tid,key,-11); } Map<Object, Object> entries5 = ofh.entries(tid); System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>"+entries5.toString()); }
结果:
以上是关于redisspring boot中 使用redis hash 操作的主要内容,如果未能解决你的问题,请参考以下文章
redisSpring 集成注解 redis 项目配置使用---3
如何将我的 Spring Boot 应用程序连接到 Docker 上的 Redis 容器?
RedisTemplate操作Redis数据结构-字符串类型