ClassPathXmlApplicationContext appCtx = new ClassPathXmlApplicationContext("spring-redis.xml");
final RedisTemplate<String, Object> redisTemplate = appCtx.getBean("redisTemplate",RedisTemplate.class);
//添加一个 key
ValueOperations<String, Object> value = redisTemplate.opsForValue();
value.set("lp", "hello word");
//获取 这个 key 的值
System.out.println(value.get("lp"));
//添加 一个 hash集合
HashOperations<String, Object, Object> hash = redisTemplate.opsForHash();
Map<String,Object> map = new HashMap<String,Object>();
map.put("name", "lp");
map.put("age", "26");
hash.putAll("lpMap", map);
//获取 map
System.out.println(hash.entries("lpMap"));
//添加 一个 list 列表
ListOperations<String, Object> list = redisTemplate.opsForList();
list.rightPush("lpList", "lp");
list.rightPush("lpList", "26");
//输出 list
System.out.println(list.range("lpList", 0, 1));
//添加 一个 set 集合
SetOperations<String, Object> set = redisTemplate.opsForSet();
set.add("lpSet", "lp");
set.add("lpSet", "26");
set.add("lpSet", "178cm");
//输出 set 集合
System.out.println(set.members("lpSet"));
//添加有序的 set 集合
ZSetOperations<String, Object> zset = redisTemplate.opsForZSet();
zset.add("lpZset", "lp", 0);
zset.add("lpZset", "26", 1);
zset.add("lpZset", "178cm", 2);
//输出有序 set 集合
System.out.println(zset.rangeByScore("lpZset", 0, 2));

redisTemplate 方法的更多相关文章

  1. Redis(二) 数据类型操作指令以及对应的RedisTemplate方法

    1.Redis key值操作以及RedisTemplate对应的API 本文默认使用RedisTemplate,关于RedisTemplate和StringRedisTemplate的区别如下 Red ...

  2. Spring RedisTemplate操作-xml配置(1)

    网上没能找到全的spring redistemplate操作例子,故特意化了点时间做了接口调用练习,基本包含了所有redistemplate方法. 该操作例子是个系列,该片为spring xml配置, ...

  3. springboot中RedisTemplate的使用

    springboot中RedisTemplate的使用 参考 了解 Redis 并在 Spring Boot 项目中使用 Redis--以IBM为学习模板 springboot之使用redistemp ...

  4. Spring Boot缓存应用实践

    缓存是最直接有效提升系统性能的手段之一.个人认为用好用对缓存是优秀程序员的必备基本素质. 本文结合实际开发经验,从简单概念原理和代码入手,一步一步搭建一个简单的二级缓存系统. 一.通用缓存接口 1.缓 ...

  5. 补习系列(13)-springboot redis 与发布订阅

    目录 一.订阅发布 常见应用 二.Redis 与订阅发布 三.SpringBoot 与订阅发布 A. 消息模型 B. 序列化 C. 发布消息 D. 接收消息 小结 一.订阅发布 订阅发布是一种常见的设 ...

  6. redis缓存中间件基础

    前序: 默认使用SimpleCacheConfiguration 组件ConcurrentMapCacheManager==ConcurrentMapCache将数据保存在ConcurrentMap& ...

  7. Spring StringRedisTemplate 配置

    1 先看pom.xml <dependency> <groupId>org.apache.commons</groupId> <artifactId>c ...

  8. 贼厉害,手撸的 SpringBoot 缓存系统,性能杠杠的!

    一.通用缓存接口 二.本地缓存 三.分布式缓存 四.缓存"及时"过期问题 五.二级缓存 缓存是最直接有效提升系统性能的手段之一.个人认为用好用对缓存是优秀程序员的必备基本素质. 本 ...

  9. javaSE27天复习总结

    JAVA学习总结    2 第一天    2 1:计算机概述(了解)    2 (1)计算机    2 (2)计算机硬件    2 (3)计算机软件    2 (4)软件开发(理解)    2 (5) ...

随机推荐

  1. C# 处理 JSON 常用的帮助类

    C#请求接口的方法,具体代码: 首先需要添加引用和第三方的组件,具体如下: 引用命名空间: using System.IO; using Newtonsoft.Json.Linq; using Sys ...

  2. 【QT】QML的Mouse事件(MouseArea)详解

    https://blog.csdn.net/ieearth/article/details/42082837

  3. iOS TableView常见问题

    Q:表视图只需要部分单元格,怎样删除下方多余的空白单元格? A:viewDidLoad中添加 self.tableView.tableFooterView=[[UIView alloc] init]; ...

  4. APUE学习笔记——10.可靠信号与不可靠信号

    首先说明:现在大部分Unix系系统如Linux都已经实现可靠信号. 1~31信号与SIGRTMIN-SIGRTMAX之间并不是可靠信号与不可靠信号的区别,在大多数系统下他们都是可靠信号. 只不过: 1 ...

  5. Spring警告: Could not load driverClass com.mysql.jdbc.Driver(待解决)

    在一个Spring项目中,新建了一个外部属性文件db.properties,在xml文件中利用${}来引用db.properties文件里面的属性. beans-properties.xml: < ...

  6. PostgreSQL统计信息挖掘

    PG提供了丰富的统计信息,但是没有将这些统计信息使用的简单查询搞成存储过程,需要我们自己根据需要灵活的去挖掘,最近做了数据库监控,用了一些简单的东西,于是想往深了挖一下. 首先看看系统表和视图,他们都 ...

  7. oracle 查询XML操作、操作系统文件

    --1.随机数 select dbms_random.value from dual; select mod(dbms_random.random, 10) from dual; --0-9随机数 s ...

  8. IOS开发 警告 All interface orientations must be supported unless the app requires full screen.

    在IOS开发中遇到警告  All interface orientations must be supported unless the app requires full screen. 只要勾上R ...

  9. Java中高级面试题整理

    一.基础知识: 1)集合类:List和Set比较,各自的子类比较(ArrayList,Vector,LinkedList:HashSet,TreeSet): 2)HashMap的底层实现,之后会问Co ...

  10. rabbitMQ高可用

    镜像模式 镜像模式和普通模式的区别就是,队列的数据都镜像了一份到所有的节点上.这样任何一个节点失效,不会影响整个集群的使用. 在实现上,mirror queue内部有一套选举算法,会选出一个maste ...