All Downloads are FREE. Search and download functionalities are using the official Maven repository.

k.e.book.config.RedissonCfg Maven / Gradle / Ivy

package k.e.book.config;

import lombok.Data;
import lombok.NoArgsConstructor;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.codec.JsonJacksonCodec;
import org.redisson.config.Config;
import org.redisson.config.SingleServerConfig;
import org.redisson.config.TransportMode;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

@Configuration
@ConfigurationProperties(prefix = "redisson")
@Data
@NoArgsConstructor
public class RedissonCfg {
    private String address;
    private String password;
    private int database;
    private int threads;
    private int nettyThreads;
    private int connectionPoolSize;

    @Primary
    @Bean(value = "redissonClient", destroyMethod = "shutdown")
    public RedissonClient redissonClient() {
        Config config = new Config();
        config.setTransportMode(TransportMode.NIO);
        config.setThreads(threads);
        config.setNettyThreads(nettyThreads);
        config.setCodec(JsonJacksonCodec.INSTANCE);

        SingleServerConfig singleServerConfig = config.useSingleServer();
        singleServerConfig.setAddress(address);
        singleServerConfig.setDatabase(database);
        singleServerConfig.setConnectionPoolSize(connectionPoolSize);
        if (password != null && password.length() > 0) {
            singleServerConfig.setPassword(password);
        }
        return Redisson.create(config);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy