概述
本文基于spring boot 2.0.7,讲解如何配置多数据源redis,采用lettuce做为redis客户端,并附上示例代码。
redis配置
配置文件
skyarthur:
redis1:
host: 127.0.0.1
port: 6378
lettuce:
pool:
min-idle: 5
max-idle: 10
max-active: 8
max-wait: 1ms
shutdown-timeout: 100ms
redis2:
host: 127.0.0.1
port: 6379
lettuce:
pool:
min-idle: 5
max-idle: 10
max-active: 8
max-wait: 1ms
shutdown-timeout: 100ms
共配置2个redis数据源,并采用 lettuce pool 做为redis客户端
配置类
package com.skyarthur.springboot.config;
import io.lettuce.core.resource.ClientResources;
import io.lettuce.core.resource.DefaultClientResources;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.RedisPassword;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.connection.