上篇整合了DB层,现在开始整合缓存层,使用redis。

  springboot驱动注解,使用spring注入JedisPool便可封装自己的redis工具类。

package hello.configuration;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource; import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig; @Configuration
@PropertySource(value = "classpath:/redis.properties")
@EnableCaching
public class RedisCacheConfiguration extends CachingConfigurerSupport {
@Value("${spring.redis.host}")
private String host; @Value("${spring.redis.port}")
private int port; @Value("${spring.redis.timeout}")
private int timeout; @Value("${spring.redis.pool.max-idle}")
private int maxIdle; @Value("${spring.redis.pool.max-wait}")
private long maxWaitMillis; @Bean
public JedisPool redisPoolFactory() {
System.out.println("JedisPool注入成功!!");
System.out.println("redis地址:" + host + ":" + port);
JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
jedisPoolConfig.setMaxIdle(maxIdle);
jedisPoolConfig.setMaxWaitMillis(maxWaitMillis);
JedisPool jedisPool = new JedisPool(jedisPoolConfig, host, port);
return jedisPool;
}
}

  redis.properties配置文件,为了清晰区分资源文件。

spring.redis.database=0
spring.redis.host=localhost
spring.redis.port=6379
spring.redis.pool.max-active=8
spring.redis.pool.max-idle=8
spring.redis.pool.max-wait=-1
spring.redis.pool.min-idle=0
spring.redis.timeout=0

springboot+redis的更多相关文章

  1. 补习系列(14)-springboot redis 整合-数据读写

    目录 一.简介 二.SpringBoot Redis 读写 A. 引入 spring-data-redis B. 序列化 C. 读写样例 三.方法级缓存 四.连接池 小结 一.简介 在 补习系列(A3 ...

  2. SpringBoot+Redis整合

    SpringBoot+Redis整合 1.在pom.xml添加Redis依赖 <!--整合Redis--> <dependency> <groupId>org.sp ...

  3. springboot +redis配置

    springboot +redis配置 pom依赖 <dependency> <groupId>org.springframework.boot</groupId> ...

  4. 【springboot】【redis】springboot+redis实现发布订阅功能,实现redis的消息队列的功能

    springboot+redis实现发布订阅功能,实现redis的消息队列的功能 参考:https://www.cnblogs.com/cx987514451/p/9529611.html 思考一个问 ...

  5. spring boot 学习(十四)SpringBoot+Redis+SpringSession缓存之实战

    SpringBoot + Redis +SpringSession 缓存之实战 前言 前几天,从师兄那儿了解到EhCache是进程内的缓存框架,虽然它已经提供了集群环境下的缓存同步策略,这种同步仍然需 ...

  6. SpringBoot + Redis:基本配置及使用

    注:本篇博客SpringBoot版本为2.1.5.RELEASE,SpringBoot1.0版本有些配置不适用 一.SpringBoot 配置Redis 1.1 pom 引入spring-boot-s ...

  7. 基于SpringBoot+Redis的Session共享与单点登录

    title: 基于SpringBoot+Redis的Session共享与单点登录 date: 2019-07-23 02:55:52 categories: 架构 author: mrzhou tag ...

  8. springboot + redis + 注解 + 拦截器 实现接口幂等性校验

    一.概念 幂等性, 通俗的说就是一个接口, 多次发起同一个请求, 必须保证操作只能执行一次 比如: 订单接口, 不能多次创建订单 支付接口, 重复支付同一笔订单只能扣一次钱 支付宝回调接口, 可能会多 ...

  9. Springboot + redis + 注解 + 拦截器来实现接口幂等性校验

    Springboot + redis + 注解 + 拦截器来实现接口幂等性校验   1. SpringBoot 整合篇 2. 手写一套迷你版HTTP服务器 3. 记住:永远不要在MySQL中使用UTF ...

  10. springboot+redis做事件过期通知业务

    springboot+redis做事件过期通知 博主也是初次体验,不足之处多多指教 我的业务场景 系统管理员要给维护员分配巡查路口设施的工作,由于路口比较多,管理员不知道哪些路口已经被分配了,况且过了 ...

随机推荐

  1. js操作数组的一些小技巧

    1.从数组中随机获取成员 var items = [12, 548 , 'a' , 2 , 5478 , 'foo' , 8852, , 'Doe' , 2145 , 119]; var  rando ...

  2. python用二进制读取文件

    python二进制读取文件 很多时候,都需要用到二进制读取文件.毕竟很多信息不是以文本的形式存储.例如:图片,音乐等等.这些东西都是有规则的二进制文件. 在python中,二进制读取采用rb的方式. ...

  3. centOS 虚拟机设置固定IP:图形化设置

    右键单击图形化标志,Edit Connection 设置一下就可以了.

  4. CentOS7 开机调整亮度

    默认亮度是100,受不了,所与就自己想了个办法,依赖其它的自启动服务使我的设置生效. /usr/lib/systemd/scripts/nfs-utils_env.sh这是一个开机自启动服务要用到的脚 ...

  5. java utils

    1.获取resouces中文件的绝对路径 String filePath = XXX.class.getClassLoader().getResource("/configs/interfa ...

  6. OUC校园导游

    大二专业课太多,都没有好好的在博客上面做笔记,以备后面用的时候可以查找看一下,下面是写的不是完全正确的与图相关的代码~~希望指正~~ /* Name: Copyright: Author:Hxm Da ...

  7. MyEclipse 10, 2013, 2014 破解、注册码

    MyEclipse 试用期限一般是三十天,过了三十天后 MyEclipse 会提示用户注册而不能正常使用,这里分享一下破解过程,仅供学习和参考. MyEclipse 10, 2013, 2014 破解 ...

  8. C#反射机制 Type类型

    using System;using System.Collections.Generic;using System.Linq;using System.Reflection;using System ...

  9. Xcode免证书调试

    不用开发者账号,不用证书,不用创建APPID,不用绑定设备,不用生成配置文件,只需一个AppleID和密码(就是APPStore应用商店的ID和密码即可并不是开发者ID和密码)即可.即可完成真机调试, ...

  10. .NET NPOI导出Excel详解

    NPOI,顾名思义,就是POI的.NET版本.那POI又是什么呢?POI是一套用Java写成的库,能够帮助开发者在没有安装微软Office的情况下读写Office的文件. 支持的文件格式包括xls, ...