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

最新文章

  1. NodeJS写个爬虫,把文章放到kindle中阅读
  2. 一个Java递归删除目录的方法
  3. 大话JSON之Gson解析JSON
  4. eclipse的历史版本及下载
  5. Markdown中的缩进
  6. php 批量生成html、txt文件
  7. 解决Bootstrap 附加导航(Affix)的问题和使用时若干注意事项
  8. Platform Invoke
  9. apache2.2 + tomcat6 整合以及集群配置整理
  10. RHEL Server 6.3下MySQL5.5.25a源码安装
  11. RedHat7下PostGIS源码安装
  12. PHP生成图片验证码、点击切换实例
  13. Web前端 web的学习之路2
  14. 详解Transformer模型(Atention is all you need)
  15. JS实现抽奖(方形)
  16. 读书笔记(chapter17)
  17. Maya中输出nuke脚本的方法
  18. Mac svn使用学习-3-客户端调用服务端简单例子
  19. Spring3的表达式语言
  20. iOS开发之解决CocoaPods中“.h”头文件找不到的问题,简单粗暴的方法

热门文章

  1. Sql Server中order by对varchar类型排序结果不对
  2. Java学习笔记:2022年1月13日(其一)
  3. 从0到1手把手实现vite
  4. 高并发环境下3种方式优化Tomcat性能
  5. 初始rust
  6. Object类的toString方法-Object类的equas方法
  7. 基于APIView写接口
  8. XMind 2022 Win/macOS 使用教程
  9. VS 管理控制台提示ScriptHalted
  10. git操作出现 error: The following untracked working tree files would be overwritten by ...