标签:not 最大连接数 temp 设置 cep known let 文件 默认
Linux安装Redis1、准备安装包
2、解压安装包
tar zxvf redis-5.0.5.tar.gz
3、进入刚刚解压的那个文件夹,输入make命令
4、等待上述过程完成后,输入 make install命令
5、在redis/src/文件夹下 运行 ./redis-server启动Redis
6、设置Redis后台运行
7、修改完成后重新启动。
1、添加Redis相关依赖
咱们还是以之前搭建的Springboot项目为基础
<!-- Redis相关依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
2、application.properties中加入redis相关配置
参见《Spring Boot、Duboo、Zookeeper、redis的配置文件【怎么用】》
# Redis数据库索引(默认为0)
spring.redis.database=0
# Redis服务器地址
spring.redis.host=192.168.0.24
# Redis服务器连接端口
spring.redis.port=6379
# Redis服务器连接密码(默认为空)
spring.redis.password=
# 连接池最大连接数(使用负值表示没有限制)
spring.redis.pool.max-active=200
# 连接池最大阻塞等待时间(使用负值表示没有限制)
spring.redis.pool.max-wait=-1
# 连接池中的最大空闲连接
spring.redis.pool.max-idle=10
# 连接池中的最小空闲连接
spring.redis.pool.min-idle=0
# 连接超时时间(毫秒)
spring.redis.timeout=1000
3、redis配置类
package com.example.demo;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.support.collections.RedisProperties;
import java.net.UnknownHostException;
/**FrozenConnection与RedAntctionConfiguration是俺随便创建的俩个客户端
*
/
@Configuration
@ConditionalOnClass(RedisOperations.class)
@EnableConfigurationProperties(RedisProperties.class)
@Import({FrozenConnection.class, RedAntctionConfiguration.class})
public class RedisAutoConfiguration {
/**@ConditionalOnMissingBean
* 如果Spring容器中有了RedisTemplate对象了,
* 这个自动配置的RedisTemplate不会实例化。
* 因此我们可以直接自己写个配置类,配置RedisTemplate。
*/
@Bean
@ConditionalOnMissingBean(name = "redisTemplate")
public RedisTemplate<Object, Object> redisTemplate(
RedisConnectionFactory redisConnectionFactory) throws UnknownHostException {
RedisTemplate<Object, Object> template = new RedisTemplate<>();
template.setConnectionFactory(redisConnectionFactory);
return template;
}
@Bean
@ConditionalOnMissingBean
public StringRedisTemplate stringRedisTemplate(
RedisConnectionFactory redisConnectionFactory) throws UnknownHostException {
StringRedisTemplate template = new StringRedisTemplate();
template.setConnectionFactory(redisConnectionFactory);
return template;
}
}
package com.example.demo;
import io.lettuce.core.RedisClient;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Configuration;
/**
* SpringBoot默认使用的是lettuce
*/
@Configuration
@ConditionalOnClass(RedisClient.class)
public class FrozenConnection extends RedisAutoConfiguration{
}
package com.example.demo;
import org.apache.commons.pool.impl.GenericObjectPool;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.jedis.JedisConnection;
@Configuration
@ConditionalOnClass({ GenericObjectPool.class, JedisConnection.class, RedisProperties.Jedis.class })
public class RedAntctionConfiguration extends RedisAutoConfiguration{
}
标签:not 最大连接数 temp 设置 cep known let 文件 默认
原文地址:https://blog.51cto.com/13479739/2493634