【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 ...
随机推荐
- 【转载】python-协程
转载自:廖雪峰的官方网站 协程,又称微线程,纤程.英文名Coroutine. 协程的概念很早就提出来了,但直到最近几年才在某些语言(如Lua)中得到广泛应用. 子程序,或者称为函数,在所有语言中都是层 ...
- ueditor 编辑器上传到服务器后图片上传不能正常使用
网站集成ueditor编辑器后在本地能正常使用,上传到服务器上后,图片上传功能提示:后端配置项没有正常加载,上传插件不能正常使用.且单个图片上传图标是灰色的不能点击. 相信遇到这个问题的同学是很多的吧 ...
- [MySQL] specified key was too long max key length is 767bytes
https://blog.csdn.net/u012099869/article/details/53815084/
- Download failed : Oracle JDK 7 is NOT installed,解决oracle jdk7的问题
先了解下概念: jdk(java development kit),就是java的开发工具集,顾名思义就是做开发用的,其中包括javac,也就是java compiler等.jre(java runt ...
- vuejs学习——vue+vuex+vue-router项目搭建(一)
前言 快年底了却有新公司邀请了我,所以打算把上家公司的学到一下技术做一些总结和分享. 现在vuejs都2.0了,我相信也有很多朋友和我一样实际项目还是选择vue1.0的或者给新手一些参考,不管在选择哪 ...
- LeetCode 16. 3Sum Closest(最接近的三数之和)
LeetCode 16. 3Sum Closest(最接近的三数之和)
- HTML5 canvas绘制arcTo、translate和rotate的画法探索
arcTo(x1,y1,x2,y2,radius) ; 还要加上moveTo的点(x0,y0) ; 第一步:找到切点 过点 (x1,y1), (x0,y0)引射线与点(x1,y1),(x2,y2) ...
- 转:linux关闭防火墙iptables
ref:https://jingyan.baidu.com/article/066074d64f433ec3c21cb000.html Linux系统下面自带了防火墙iptables,iptables ...
- 洛谷P3435 [POI2006]OKR-Period of Words [KMP]
洛谷传送门,BZOJ传送门 OKR-Period of Words Description 一个串是有限个小写字符的序列,特别的,一个空序列也可以是一个串. 一个串P是串A的前缀, 当且仅当存在串B, ...
- Python类总结-继承-子类和父类,新式类和经典类
子类和父类 class Father(object): #子类在使用super调用父类时,Father后面要加object --新式类 def __init__(self): self.Fname = ...