【redis】spring boot中 使用redis hash 操作 --- 之 使用redis实现库存的并发有序操作
示例:
@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()); }
结果:

【redis】spring boot中 使用redis hash 操作 --- 之 使用redis实现库存的并发有序操作的更多相关文章
- 在Spring Boot中使用数据库事务
我们在前面已经分别介绍了如何在Spring Boot中使用JPA(初识在Spring Boot中使用JPA)以及如何在Spring Boot中输出REST资源(在Spring Boot中输出REST资 ...
- 【Spring Boot&&Spring Cloud系列】Spring Boot中使用NoSql数据库Redis
github地址:https://github.com/AndyFlower/Spring-Boot-Learn/tree/master/spring-boot-nosql-redis 一.加入依赖到 ...
- Spring Boot 中 Redis 的使用
Spring Boot 对常用的数据库支持外,对 Nosql 数据库也进行了封装自动化,如Redis.MongoDB等,本文主要介绍Redis的使用. Redis 介绍 Redis 是目前业界使用最广 ...
- Spring Boot中使用Redis小结
Spring Boot中除了对常用的关系型数据库提供了优秀的自动化支持之外,对于很多NoSQL数据库一样提供了自动化配置的支持,包括:Redis, MongoDB, 等. Redis简单介绍 Redi ...
- Spring Boot中使用redis的发布/订阅模式
原文:https://www.cnblogs.com/meetzy/p/7986956.html redis不仅是一个非常强大的非关系型数据库,它同时还拥有消息中间件的pub/sub功能,在sprin ...
- spring boot(三):Spring Boot中Redis的使用
spring boot对常用的数据库支持外,对nosql 数据库也进行了封装自动化. redis介绍 Redis是目前业界使用最广泛的内存数据存储.相比memcached,Redis支持更丰富的数据结 ...
- springboot(三):Spring boot中Redis的使用
spring boot对常用的数据库支持外,对nosql 数据库也进行了封装自动化. redis介绍 Redis是目前业界使用最广泛的内存数据存储.相比memcached,Redis支持更丰富的数据结 ...
- Spring Boot:Spring Boot 中 Redis 的使用
Redis 介绍 Redis 是目前业界使用最广泛的内存数据存储.相比 Memcached,Redis 支持更丰富的数据结构,例如 hashes, lists, sets 等,同时支持数据持久化.除此 ...
- (转)Spring Boot(三):Spring Boot 中 Redis 的使用
http://www.ityouknow.com/springboot/2016/03/06/spring-boot-redis.html Spring Boot 对常用的数据库支持外,对 Nosql ...
随机推荐
- 观察者模式和java委托
观察者模式与java委托 所谓观察者模式,指的某个状态信息的改变,会影响其他一系列的操作,这时就可以将这些操作抽象化,同时创建一个类统一的管理和执行这些操作.把这些抽象出来的操作称为观察者类,而管理这 ...
- Linux shell 中$() ` `,${},$[] $(()),[ ] (( )) [[ ]]作用与区别
转载自 https://blog.csdn.net/x1269778817/article/details/46535729 参考: https://stackoverflow.com/questio ...
- hdu5984
听说大佬都是看到1.693147就知道是ln(2)+1我是服气的 不过老老实实推的话就看你大一数分/高数是不是学扎实了 令 把L移到右边并两边求导可得,即 令 代入最开始的公式得到 化简可得,得解 # ...
- Lunix含Ubuntu使用总结
错误 鼠标闪烁解决 系统设置->显示—>未知显示器->关闭->应用->选择当前配置 提示sudo: unable to resolve host ,亦即无法解析主机. 原 ...
- [实战]MVC5+EF6+MySql企业网盘实战(5)——页面模板
写在前面 上篇文章更新了网盘的登录界面,以及用户头像的等比例压缩功能.今天折腾一下页面的样式,将从网上找的一个模板套用在项目中. 系列文章 [EF]vs15+ef6+mysql code first方 ...
- es6js promise在ie中报错“未定义”
解决办法,我使用https://cdn.bootcss.com/es6-promise/4.1.1/es6-promise.auto.min.js直接引入在html中,也可以安装相应的babel-po ...
- 【LOJ】#2350. 「JOI 2017/2018 决赛」月票购买
题解 首先求一个最短路图出来,最短路图就是这条边在最短路上就保留,否则就不保留,注意最短路图是一个有向图,一条边被保留的条件是 dis(S,u) + val(u,v) = dis(v,T)我们需要求两 ...
- 20169211《Linux内核原理与分析》第二周作业
<linux内核分析>实验一实验报告 <linux内核设计与实现>第1.2.18章学习总结 一.<linux内核分析>实验一实验报告 在进行实验楼操作 ...
- CTF西湖论剑
一,西湖论剑 itoa()函数有3个参数:第一个参数是要转换的数字,第二个参数是要写入转换结果的目标字符串,第三个参数是转移数字时所用 的基数.在上例中,转换基数为10.10:十进制:2:二进制... ...
- 深入浅出Spring(三) AOP详解
上次的博文深入浅出Spring(二) IoC详解中,我为大家简单介绍了一下Spring框架核心内容中的IoC,接下来我们继续讲解另一个核心AOP(Aspect Oriented Programming ...