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用法的更多相关文章

  1. Java Spring AOP用法

    Java Spring AOP用法 Spring AOP Java web 环境搭建 Java web 项目搭建 Java Spring IOC用法 spring提供了两个核心功能,一个是IoC(控制 ...

  2. Java Spring IOC用法

    Java Spring IOC用法 Spring IoC 在前两篇文章中,我们讲了java web环境搭建 和 java web项目搭建,现在看下spring ioc在java中的运用,开发工具为In ...

  3. Spring JdbcTemplate用法整理

    Spring JdbcTemplate用法整理: xml: <?xml version="1.0" encoding="UTF-8"?> <b ...

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

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

  5. spring RestTemplate用法详解

    spring RestTemplate用法详解 spring 3.2.3 框架参考有说明 21.9 Accessing RESTful services on the Client

  6. spring redistemplate中setHashValueSerializer的设置

    笔者曾经对redis键值使用了不同类型的序列化方法 用过默认值.JdkSerializationRedisSerializer.StringRedisSerializer还用改以下自定类型的序列化工具 ...

  7. RedisTemplate 用法

      Redis 数据结构简介 Redis 可以存储键与5种不同数据结构类型之间的映射,这5种数据结构类型分别为String(字符串).List(列表).Set(集合).Hash(散列)和 Zset(有 ...

  8. Spring Aspect 用法略讲

    『配置Aspect』 若要启用AspectJ风格的注解则必须额外的导入AspectJ的jar包,此外还需要在spring的配置文件中进行配置,配置方式有两种; 一.在配置文件的Schema中进行配置 ...

  9. spring RedisTemplate的使用(一)--xml配置或JavaConfig配置

    1.xml配置 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns:xsi="h ...

  10. Spring RedisTemplate操作-事务操作(9)

    @Autowired @Qualifier("redisTemplate") private RedisTemplate<String, String> stringr ...

随机推荐

  1. [机器学习] Yellowbrick使用笔记8-模型选择可视化

    Yellowbrick可视化工具旨在指导模型选择过程.一般来说,模型选择是一个搜索问题,定义如下:给定N个由数值属性描述的实例和(可选)一个估计目标,找到一个由特征.算法和最适合数据的超参数组成的三元 ...

  2. 1_使用swiper数组对象循环图片遇到的问题

    今天在练习微信小程序的swiper组件时,想用列表循环出图片,发现图片一直没出来,控制台也没有报错,后来仔细一看,原来是语法格式写错了. 以下是我列表循环踩过的坑: 一:微信小程序的列表循环和vue的 ...

  3. 说一下三种jar包在Linux的启动方式

    最近在linux上发布了一个SpringBoot项目,研究了一下jar包在Linux上的集中启动方式,特在此分享一下. 这里默认要启动的jar包为demo-0.0.1-SNAPSHOT.jar 第一种 ...

  4. 迁移学习(MixMatch)《MixMatch: A Holistic Approach to Semi-Supervised Learning》

    论文信息 论文标题:MixMatch: A Holistic Approach to Semi-Supervised Learning论文作者:David Berthelot, Nicholas Ca ...

  5. Hexo博客搭建记录

    Hexo博客搭建记录 参考视频:手把手教你从0开始搭建自己的个人博客 |无坑版视频教程 以下命令操作建议使用管理员权限完成 1. nodejs & hexo 安装 1.首先下载node.js, ...

  6. UVA12412 A Typical Homework (a.k.a Shi Xiong Bang Bang Mang) 代码

    #include <bits/stdc++.h> #define int long long #define judge(a,func) case a:func();break; usin ...

  7. dp 优化

    dp 优化 \(\text{By DaiRuiChen007}\) I. [ARC085D] - NRE \(\text{Link}\) 思路分析 将最终的第 \(i\) 对 \(a_i\) 和 \( ...

  8. Ubuntu 安装 dlib 库时的疑难杂症

    解决方法 安装 C/C++环境 sudo apt install gcc sudo apt install g++ 激活 conda 环境 source activate OpenCV pip ins ...

  9. pycharm设置python头文件模版

    钢铁知识库,一个学习python爬虫.数据分析的知识库.人生苦短,快用python. 使用pycharm创建python文件时候,有时候需要自动生成想要的文件头,如何生成呢? 只需要以下几步: 在fi ...

  10. 跟着廖雪峰学python 003

    ​ ​编辑 列表和元组 list 是一种有序.可变的数据类型,可添加删除其中的元素. len()函数:可以获取列表元素的个数 classmates = ['Micheal' , 'Bob' , 'Ja ...