RedissonConfig.java
1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package com.brframework.commoncache.config;
import com.brframework.commoncache.core.FastJsonRedisCodec;
import com.google.common.base.Strings;
import lombok.Data;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.codec.JsonJacksonCodec;
import org.redisson.config.Config;
import org.redisson.config.TransportMode;
import org.springframework.beans.factory.annotation.Autowired;
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;
/**
* Redisson 配置
* @author xu
* @date 2019年9月4日22:56:12
*/
@Configuration
@ConfigurationProperties(value = "spring.redis")
@Data
public class RedissonConfig {
@Autowired
RedisProperties redisProperties;
@Bean
public RedissonClient redissonClient (){
String address = "redis://" + redisProperties.getHost() + ":" + redisProperties.getPort();
Config config = new Config();
config.setTransportMode(TransportMode.NIO);
config.useSingleServer()
.setDatabase(redisProperties.getDatabase())
.setAddress(address)
.setPassword(redisProperties.getPassword());
config.setCodec(new FastJsonRedisCodec());
return Redisson.create(config);
}
}