搭建公共的Redis服务和公共的Redis调用模块(Feign)
所有的缓存请求统一调用redis微服务,抽取调用redis服务器Feign模块
搭建微服务
统一由redis微服务去访问redis缓存. 由jedis操作redis
导入的包
<dependencies>
<!--web环境,必备,不解释-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--swagger2,接口手册-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
</dependency>
<!--eureka客户端,Feign调用这个微服务的接口,所有要注册到注册中心-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<!--config客户端,配置了配置中心-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-client</artifactId>
</dependency>
<!--Jedis的工具类(RedisUtil)和其他一些依赖,其中导入jedis的包-->
<dependency>
<groupId>com.marui</groupId>
<artifactId>hrm-basic-utils</artifactId>
</dependency>
</dependencies>
jedis 工具类
package com.marui.hrm.util;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
import java.io.IOException;
import java.util.Properties;
/**
* 获取连接池对象
*/
public enum RedisUtils {
INSTANCE;
static JedisPool jedisPool = null;
static {
//1 创建连接池配置对象
JedisPoolConfig config = new JedisPoolConfig();
//2 进行配置-四个配置
config.setMaxIdle(1);//最小连接数
config.setMaxTotal(11);//最大连接数
config.setMaxWaitMillis(10 * 1000L);//最长等待时间
config.setTestOnBorrow(true);//测试连接时是否畅通
//3 通过配置对象创建连接池对象
Properties properties = null;
try {
properties = new