spring RedisTemplate用法
1.maven依赖
<!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-redis -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>1.6.2.RELEASE</version>
</dependency> <!-- https://mvnrepository.com/artifact/redis.clients/jedis -->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.7.2</version>
</dependency> <dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
<version>2.2</version>
</dependency>
2.spring的xml配置
<bean id="jedisFactory" class="work.cache.redis.JedisPoolConnectionFactory"
destroy-method="close">
<constructor-arg ref="jedisPoolConfig" />
<constructor-arg value="127.0.0.1" />
<constructor-arg value="6379" />
</bean> <bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<property name="hostName" value="127.0.0.1" />
<property name="port" value="6379"/>
<property name="poolConfig" ref="jedisPoolConfig" />
<property name="usePool" value="true"/>
</bean> <bean id="springRedisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="jedisConnectionFactory" />
<property name="keySerializer">
<bean class="org.springframework.data.redis.serializer.StringRedisSerializer" />
</property>
<property name="valueSerializer">
<bean class="org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer" />
</property>
<property name="hashKeySerializer">
<bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
</property>
<property name="hashValueSerializer">
<bean class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer"/>
</property>
</bean>
2.2 将bean传到业务类中
3 使用redisTemplate
springRedisTemplate.opsForValue().set(String.valueOf(report.getId()) +InstructionUtil.IsuSuffixRedisKey.ISU_HEART_BEAT.getKey(),1,80,TimeUnit.SECONDS);
RedisTemplate依赖:import org.springframework.data.redis.core.RedisTemplate;
参考地址:https://blog.csdn.net/liang_love_java/article/details/50497281
spring RedisTemplate用法的更多相关文章
- Java Spring AOP用法
Java Spring AOP用法 Spring AOP Java web 环境搭建 Java web 项目搭建 Java Spring IOC用法 spring提供了两个核心功能,一个是IoC(控制 ...
- Java Spring IOC用法
Java Spring IOC用法 Spring IoC 在前两篇文章中,我们讲了java web环境搭建 和 java web项目搭建,现在看下spring ioc在java中的运用,开发工具为In ...
- Spring JdbcTemplate用法整理
Spring JdbcTemplate用法整理: xml: <?xml version="1.0" encoding="UTF-8"?> <b ...
- Spring RedisTemplate操作-xml配置(1)
网上没能找到全的spring redistemplate操作例子,故特意化了点时间做了接口调用练习,基本包含了所有redistemplate方法. 该操作例子是个系列,该片为spring xml配置, ...
- spring RestTemplate用法详解
spring RestTemplate用法详解 spring 3.2.3 框架参考有说明 21.9 Accessing RESTful services on the Client
- spring redistemplate中setHashValueSerializer的设置
笔者曾经对redis键值使用了不同类型的序列化方法 用过默认值.JdkSerializationRedisSerializer.StringRedisSerializer还用改以下自定类型的序列化工具 ...
- RedisTemplate 用法
Redis 数据结构简介 Redis 可以存储键与5种不同数据结构类型之间的映射,这5种数据结构类型分别为String(字符串).List(列表).Set(集合).Hash(散列)和 Zset(有 ...
- Spring Aspect 用法略讲
『配置Aspect』 若要启用AspectJ风格的注解则必须额外的导入AspectJ的jar包,此外还需要在spring的配置文件中进行配置,配置方式有两种; 一.在配置文件的Schema中进行配置 ...
- spring RedisTemplate的使用(一)--xml配置或JavaConfig配置
1.xml配置 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns:xsi="h ...
- Spring RedisTemplate操作-事务操作(9)
@Autowired @Qualifier("redisTemplate") private RedisTemplate<String, String> stringr ...
随机推荐
- [python] 基于matplotlib实现圆环图的绘制
圆环图本质上是一个中间切出一块区域的饼状图.可以使用python和matplotlib库来实现.本文主要介绍基于matplotlib实现圆环图.本文所有代码见:Python-Study-Notes # ...
- HBase详解(04) - HBase Java API使用
HBase详解(04) - HBase Java API使用 环境准备 新建Maven项目,在pom.xml中添加依赖 <dependency> <groupId>org.ap ...
- 初探富文本之OT协同算法
初探富文本之OT协同算法 OT的英文全称是Operational Transformation,是一种处理协同编辑的算法.当前OT算法用的比较多的地方就是富文本编辑器领域了,常用于作为实现文档协同的底 ...
- Vue+elementui前后端分离,单个图片文件上传和上传时出现的跨域问题的解决方案
在后端解决跨域问题: 我是通过配置文件来解决跨域问题的 @Configurationpublic class CorsConfig {//解决前后端分离的跨域问题! /** * cors suppor ...
- C++Vector源码解析(侯捷STL)
vector是动态空间,随着元素的加入,它的内部机制会自行扩充空间以容纳新的元素.vector的实现技术,关键在于对大小的控制以及重新配置时的数据移动效率. 一.vector的数据结构 vector采 ...
- 发布并部署NCF站点的那些事
简介 开工第一天,祝大家2023年钱兔无量,技术兔飞猛进 为更加方便大家一站式打通所有使用NCF的环节,在新年开工的第一天给大家带来如何发布最新版本的站点 无论你的网站在开发环境做的多么的炫酷,实用, ...
- Function接口-默认方法:andThen
Function接口 java.util.function.Function<T,R〉接口用来根据一个类型的数据得到另一个类型的数据,前者称为前置条件,后者称为后置条件. 抽象方法:apply ...
- (数据科学学习手札149)用matplotlib轻松绘制漂亮的表格
本文示例代码已上传至我的Github仓库https://github.com/CNFeffery/DataScienceStudyNotes 1 简介 大家好我是费老师,matplotlib作为数据可 ...
- 【随笔记】全志平台 gpio-leds 驱动应用
硬件信息 内核版本:Linux 4.9 硬件原理: GPIO 通过一颗 MOS 管(2N7002ET1G),接到 LED 负极,LED 正极接电源. GPIO 通过拉高导通 MOS ,将 LED 接地 ...
- MRS_开发编译与设置相关问题汇总
解决问题如下: MRS开发编译时,如何修改工程优化等级 MRS进行工程编译时,如何配置FLASH.RAM显示占比 打印浮点类型 配置LD文件在工程中显示 使用sprintf打印 当重复多次调用相同函数 ...