forked from Fascinated/Bat
oops
This commit is contained in:
parent
455c3f0bf1
commit
52e5d50782
@ -1,50 +0,0 @@
|
|||||||
package cc.fascinated.bat.config;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
|
|
||||||
import org.springframework.data.redis.connection.jedis.JedisClientConfiguration;
|
|
||||||
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
|
||||||
|
|
||||||
import java.time.Duration;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Fascinated (fascinated7)
|
|
||||||
*/
|
|
||||||
@Configuration
|
|
||||||
public class RedisCacheConfig {
|
|
||||||
@Value(value="${spring.redis.host}")
|
|
||||||
private String host;
|
|
||||||
|
|
||||||
@Value(value="${spring.redis.port}")
|
|
||||||
private String port;
|
|
||||||
|
|
||||||
@Value(value="${spring.redis.timeout}")
|
|
||||||
private String timeout;
|
|
||||||
|
|
||||||
@Value(value="${spring.redis.database}")
|
|
||||||
private String database;
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
JedisConnectionFactory jedisConnectionFactory() {
|
|
||||||
RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration();
|
|
||||||
redisStandaloneConfiguration.setHostName(host);
|
|
||||||
redisStandaloneConfiguration.setPort(Integer.parseInt(port));
|
|
||||||
redisStandaloneConfiguration.setDatabase(Integer.parseInt(database));
|
|
||||||
|
|
||||||
JedisClientConfiguration.JedisClientConfigurationBuilder jedisClientConfiguration = JedisClientConfiguration.builder();
|
|
||||||
jedisClientConfiguration.connectTimeout(Duration.ofSeconds(Integer.parseInt(timeout)));// connection timeout
|
|
||||||
|
|
||||||
return new JedisConnectionFactory(redisStandaloneConfiguration,
|
|
||||||
jedisClientConfiguration.build());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public RedisTemplate<String, Object> redisTemplate() {
|
|
||||||
RedisTemplate<String, Object> template = new RedisTemplate<>();
|
|
||||||
template.setConnectionFactory(jedisConnectionFactory());
|
|
||||||
return template;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user