Springboot中Redis的简单实用--template编码形式
来源:互联网 发布:php网页爬虫源码 编辑:程序博客网 时间:2024/06/08 15:22
Springboot中Redis的简单实用
再上一遍文章中已经介绍过Spring boot中redis的配置http://blog.csdn.net/yy756127197/article/details/73719588
现在介绍他的简单实用
引入bean
@Resource private RedisTemplate<Serializable, Serializable> template; @Resource private ValueOperations<Serializable, Serializable> valueOperations; @Resource private ListOperations<Serializable, Serializable> listOperations; @Resource private HashOperations<Serializable, Object, Object> hashOperations; @Resource private SetOperations<Serializable, Serializable> setOperations; @Resource private ZSetOperations<Serializable, Serializable> zSetOperations;
测试方法
public void test() { // String读写 template.delete("name"); valueOperations.set("name", "拯救世界的Programmer"); System.out.println(valueOperations.get("name")); System.out.println("---------------"); // List读写 template.delete("myList"); listOperations.rightPush("myList", "右1"); listOperations.rightPush("myList", "右2"); listOperations.leftPush("myList", "左"); List<Serializable> listCache = listOperations.range("myList", 0, -1); for (Serializable s : listCache) { System.out.println((String) s); } System.out.println("---------------"); // Set读写 template.delete("mySet"); setOperations.add("mySet", "A"); setOperations.add("mySet", "B"); setOperations.add("mySet", "C"); Set<Serializable> setCache = setOperations.members("mySet"); for (Serializable s : setCache) { System.out.println((String) s); } System.out.println("---------------"); // Set读写 template.delete("myZset"); zSetOperations.add("myZset", "A", 1); zSetOperations.add("myZset", "C",3); zSetOperations.add("myZset", "B",2); Set<Serializable> zsetCache = zSetOperations.range("myZset", 0, -1); for (Serializable s : zsetCache) { System.out.println((String) s); } System.out.println("---------------"); // Hash读写 template.delete("myHash"); hashOperations.put("myHash", "DEPARTMENT", "部门"); hashOperations.put("myHash", "COMPANY", "公司"); hashOperations.put("myHash", "ADDRESS", "深圳"); Map<Object, Object> hashCache = hashOperations.entries("myHash"); for (Map.Entry<Object, Object> entry : hashCache.entrySet()) { System.out.println(entry.getKey() + " - " + entry.getValue()); } System.out.println("---------------"); }
欢迎大家交流沟通,喜欢的请给赞哦^^
阅读全文
0 0
- Springboot中Redis的简单实用--template编码形式
- Spring boot下配置使用redis--template编码形式
- Springboot中使用redis,配置redis的key value生成策略(解决编码问题)
- SpringBoot中Redis的使用
- SpringBoot 整合 Redis 的简单案例
- python的redis,实用订阅发布简单实用代码
- springboot中通过aop的形式获取方法执行时间
- redis简单实用
- SpringBoot中使用redis
- Springboot中redis
- SpringBoot中redis
- 关于C++中template的简单用法
- Android开发中最实用的集合形式转换
- SpringBoot结合Redis简单应用
- springboot中websocket的简单应用
- SpringBoot简单的SpringBoot后端
- redis的安装及简单实用(Linux下)
- template的简单例子
- Binder学习之——Android的MediaPlayer架构介绍
- 基于 Quartz 开发企业级任务调度应用
- C# 实时监控数据库SqlDependency
- 【脚本语言系列】关于Python结构化文本文件处理Avro,你需要知道的事
- 虚拟机网络配置
- Springboot中Redis的简单实用--template编码形式
- 页面引用JS文件,在文件名后加随机数字来避免缓存问题
- 【1004】无环图
- hdu 5120 Intersection (圆相交面积模板)
- JavaPoet
- 【脚本语言系列】关于Python结构化文本文件处理Thrift,你需要知道的事
- XGBoost
- maven 工程启动找不到 Spring ContextLoaderListener 的解决办法
- Java创建线程