Commit fbe30872 authored by renandong's avatar renandong 🇨🇳

1,修改redis手动注入工厂

parent ac90a5e3
...@@ -49,8 +49,14 @@ ...@@ -49,8 +49,14 @@
<version>${lombok.version}</version> <version>${lombok.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.data</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId> <artifactId>spring-data-redis</artifactId>
<version>2.4.3</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>3.3.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
......
...@@ -3,9 +3,16 @@ package com.weface.config; ...@@ -3,9 +3,16 @@ package com.weface.config;
import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor; import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.RedisSentinelConfiguration;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer; import org.springframework.data.redis.serializer.StringRedisSerializer;
...@@ -16,6 +23,36 @@ import org.springframework.data.redis.serializer.StringRedisSerializer; ...@@ -16,6 +23,36 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
@Configuration @Configuration
public class RedisConfig { public class RedisConfig {
private static Logger logger = LoggerFactory.getLogger(RedisConfig.class);
@Autowired
RedisProperties redisProperties;
@Bean
public JedisConnectionFactory factory() {
RedisStandaloneConfiguration connectionConf = new RedisStandaloneConfiguration();
connectionConf.setHostName(redisProperties.getHostname());
connectionConf.setDatabase(redisProperties.getDatabase());
connectionConf.setPort(redisProperties.getPort());
JedisConnectionFactory factory = new JedisConnectionFactory(connectionConf);
factory.getPoolConfig().setMaxTotal(redisProperties.getMaxTotal());
factory.getPoolConfig().setMaxIdle(redisProperties.getMaxIdle());
factory.getPoolConfig().setMinIdle(redisProperties.getMinIdle());
return factory;
}
public RedisConnectionFactory lettuceConnectionFactory() {
RedisSentinelConfiguration sentinelConfig = new RedisSentinelConfiguration()
.master("mymaster")
.sentinel("127.0.0.1", 26379)
.sentinel("127.0.0.1", 26380);
return new LettuceConnectionFactory(sentinelConfig);
}
@Bean @Bean
@SuppressWarnings("all") @SuppressWarnings("all")
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) { public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {
...@@ -39,4 +76,5 @@ public class RedisConfig { ...@@ -39,4 +76,5 @@ public class RedisConfig {
return template; return template;
} }
} }
package com.weface.config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@ConfigurationProperties(prefix = "gexiang.redis")
@Component
public class RedisProperties {
/**
* redis hostname
*/
private String hostname;
/**
* redis database
*/
private int database;
/**
* redis port
*/
private int port;
/**
* redis max channel
*/
private int maxTotal;
/**
* redis max wait channel
*/
private int maxIdle;
/**
* redis min wait channel
*/
private int minIdle;
public String getHostname() {
return hostname;
}
public void setHostname(String hostname) {
this.hostname = hostname;
}
public int getDatabase() {
return database;
}
public void setDatabase(int database) {
this.database = database;
}
public int getPort() {
return port;
}
public void setPort(int port) {
this.port = port;
}
public int getMaxTotal() {
return maxTotal;
}
public void setMaxTotal(int maxTotal) {
this.maxTotal = maxTotal;
}
public int getMaxIdle() {
return maxIdle;
}
public void setMaxIdle(int maxIdle) {
this.maxIdle = maxIdle;
}
public int getMinIdle() {
return minIdle;
}
public void setMinIdle(int minIdle) {
this.minIdle = minIdle;
}
}
...@@ -55,7 +55,7 @@ public class UserTagsTask { ...@@ -55,7 +55,7 @@ public class UserTagsTask {
/** /**
* 更新用户标签 * 更新用户标签
*/ */
@Scheduled(cron = "0 18 10 * * ? ") @Scheduled(cron = "0 20 11 * * ?")
public void updateUserTags() { public void updateUserTags() {
try { try {
//获取每次处理的id起始值 //获取每次处理的id起始值
......
...@@ -27,14 +27,6 @@ spring: ...@@ -27,14 +27,6 @@ spring:
enabled: true enabled: true
mvc: mvc:
throw-exception-if-no-handler-found: true throw-exception-if-no-handler-found: true
redis:
host: 172.21.6.6
database: 0
port: 6379
maxTotal: 1000
maxIdle: 50
minIdle: 10
timeout: 1s
getui: getui:
apps: { apps: {
...@@ -64,5 +56,13 @@ mybatis-plus: ...@@ -64,5 +56,13 @@ mybatis-plus:
jdbc-type-for-null: 'null' jdbc-type-for-null: 'null'
gexiang: gexiang:
redis:
# hostname: 172.21.6.6
hostname: 127.0.0.1
database: 0
port: 6379
maxTotal: 1000
maxIdle: 50
minIdle: 10
user_tag_id: 251696 user_tag_id: 251696
push_max_size: 10000 push_max_size: 10000
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment