|
@@ -1,58 +0,0 @@
|
|
|
-package com.chelvc.framework.redis.config;
|
|
|
-
|
|
|
-import lombok.RequiredArgsConstructor;
|
|
|
-import org.redisson.Redisson;
|
|
|
-import org.redisson.api.RedissonClient;
|
|
|
-import org.redisson.config.Config;
|
|
|
-import org.redisson.spring.data.connection.RedissonConnectionFactory;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.beans.factory.annotation.Configurable;
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
-import org.springframework.context.annotation.Bean;
|
|
|
-import org.springframework.context.annotation.Primary;
|
|
|
-
|
|
|
-/**
|
|
|
- * Redisson配置
|
|
|
- *
|
|
|
- * @author igl
|
|
|
- * @date 2023/05/28 18:06
|
|
|
- */
|
|
|
-@Configurable
|
|
|
-@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
|
|
-public class RedissonConfig {
|
|
|
-
|
|
|
- private static final String REDIS_CONNECTION_TEMPLATE = "redis://%s:%d";
|
|
|
-
|
|
|
- @Value("${spring.redis.host:127.0.0.1}")
|
|
|
- private String host;
|
|
|
-
|
|
|
- @Value("${spring.redis.port:60379}")
|
|
|
- private Integer port;
|
|
|
-
|
|
|
- @Value("${spring.redis.password:igl611}")
|
|
|
- private String password;
|
|
|
-
|
|
|
- @Value("${spring.redis.database:0}")
|
|
|
- private Integer database;
|
|
|
-
|
|
|
- @Bean
|
|
|
- @Primary
|
|
|
- public RedissonConnectionFactory redisConnectionFactory() {
|
|
|
- return new RedissonConnectionFactory(createConfig());
|
|
|
- }
|
|
|
-
|
|
|
- @Bean
|
|
|
- public RedissonClient redissonClient() {
|
|
|
- return Redisson.create(createConfig());
|
|
|
- }
|
|
|
-
|
|
|
- private Config createConfig() {
|
|
|
- Config config = new Config();
|
|
|
- String address = String.format(REDIS_CONNECTION_TEMPLATE, host, port);
|
|
|
- config.useSingleServer()
|
|
|
- .setAddress(address)
|
|
|
- .setPassword(password)
|
|
|
- .setDatabase(database);
|
|
|
- return config;
|
|
|
- }
|
|
|
-}
|