【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 ...
随机推荐
- Sublime Text 2之Emmet插件安装及使用
1.安装Emmet How To Install?Reffer to this link:http://www.ituring.com.cn/article/47310 2.使用Emmet--Abbr ...
- 渗透常用SQL注入语句合集
1.判断有无注入点; and 1=1 and 1=2 2.猜表一般的表的名称无非是admin adminuser user pass password 等..and 0<>(select ...
- cocos2d-x 开发中使用的一些工具
这些工具平常也用到,不过没有像这样整理出来,这是我在网上看到的.就记录一下. 位图字体工具Bitmap Font Tools BMFont (Windows)FonteditorGlyph Desig ...
- 两周撸一个掘金微信小程序
利益相关 无 声明 这并不是掘金官方小程序(貌似没有搜到掘金 APP 对应的官方小程序),完全为第三者开发者开发,仅用于学习交流,禁止用于其他用途.若要使用官方正版,可访问掘金 官方网站,或下载掘金官 ...
- 关于Web2.0概念的一篇小短文
Web2.0程序设计的第一篇作业,写了就顺手放上来吧. 在互联网泡沫破裂数年后,Tim O'Reilly与John Battelle总结了互联网产业复兴过程中出现的一系列现象,在2004年举办的第一届 ...
- oracle创建计划任务
特别提示: oracle是执行完任务,才按照interval去计算下次执行时间!!! 为精确每个5分钟执行一个任务,必须自己计算时间. 如:trunc_minute(sysdate)+/ create ...
- 阿里云ecs 服务器配置
阿里云ecs 7.0+安装mysql 5.6 http://jingyan.baidu.com/article/454316ab67bd02f7a7c03af4.html 安装jdk yum -y i ...
- 【转】django 与 vue 的完美结合 实现前后端的分离开发之后在整合
https://blog.csdn.net/guan__ye/article/details/80451318 最近接到一个任务,就是用django后端,前段用vue,做一个普通的简单系统,我就是 ...
- ubuntu下让进程在后台运行
(1)输入命令: nohup 你的shell命令 & (2)回车,使终端回到shell命令行: (3)使用第二第三条,完全屏蔽掉信号 用disown -h jobspec来使某个作业忽略HUP ...
- 113. 路径总和 II
给定一个二叉树和一个目标和,找到所有从根节点到叶子节点路径总和等于给定目标和的路径. 说明: 叶子节点是指没有子节点的节点. 示例:给定如下二叉树,以及目标和 sum = 22, 5 / \ 4 8 ...