【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 ...
随机推荐
- 窗口生效函数UpdateData
Invalidate()使整个窗口客户区无效.窗口的客户区无效意味着需要重绘,例如,如果一个被其它窗口遮住的窗口变成了前台窗口,那么原来被遮住的部分就是无效的,需要重绘.这时Windows会在应用程序 ...
- mysql建立自增主键的插入,及自动插入当前时间
MYSQL里用这两个字段,几乎都是必须的. 以前都是自动建立的,现在手把手建立的时候,就要找资料来搞定了. 参考URL: http://blog.csdn.net/Weicleer/article/d ...
- tensorflow运行出现错误 : ImportError: Could not find 'cudart64_90.dll'.
安装 tensorflow-gpu 版本后,需要安装相应的 CUDA 和 cuDNN 注意版本问题:tensorflow-gpu 1.7以及之后的版本要安装 CUDA 8.0 以上的版本,tf 1.7 ...
- python中调用cmd
1. 使用os.system("cmd") 这是最简单的一种方法,特点是执行的时候程序会打出cmd在linux上执行的信息.使用前需要import os. os.system(&q ...
- Error: Exception was raised when calling event-notify Vuser function in extension parameng.dll: System Exceptions: EXCEPTION_ACCESS_VIOLATION
解决方法:在C 盘新建一个TEMP目录,把环境变量TMP,TEMP的值设置成环境变量,重启计算机
- ubuntu 依赖问题
ubuntu想装个QQ,无奈安装不但出错,还导致现在的软件依赖出了问题 正在读取软件包列表... 完成 正在分析软件包的依赖关系树 正在读取状态信息... 完成 您也许需要运行“apt --fix-b ...
- Centos7 Openldap主从配置
转载 https://blog.csdn.net/htvxjl02/article/details/80336788 Centos7 Openldap主从配置 2018年05月16日 15:09:57 ...
- POJ2955【区间DP】
题目链接[http://poj.org/problem?id=2955] 题意:[].()的匹配问题,问一个[]()串中匹配的字符数,匹配方式为[X],(X),X为一个串,问一个长度为N(N<= ...
- WebLogic Server
前几天,看了几集J2ee , 给我的感觉就是,看不懂!! 一点也不懂! 那怎么办呢? 听老师的,不管懂不懂,先看看再说.接下来,就开始了J2ee "艰苦"的历程.在J2ee中,经常 ...
- luogu P4115 Qtree4
题目链接 luogu P4115 Qtree4 题解 动态点分治,和上一题一样.同样三个堆.就是带权,用边权替换深度就好 为什么要单独写这个题解呢,因为我卡常卡了一天....据说树剖比rmq快? 在第 ...