RedissonConfig.java 1.08 KB
package com.viontech.fanxing.commons.config;

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.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.FileInputStream;
import java.io.IOException;

/**
 * .
 *
 * @author 谢明辉
 * @date 2021/7/5
 */

@Configuration
public class RedissonConfig {

    @Bean
    public RedissonConnectionFactory redissonConnectionFactory(RedissonClient redisson) {
        return new RedissonConnectionFactory(redisson);
    }

    @Bean(destroyMethod = "shutdown")
    public RedissonClient redisson(@Value("${vion.redisson.path}") String path) throws IOException {
        try (FileInputStream inputStream = new FileInputStream(path)) {
            Config config = Config.fromYAML(inputStream);
            config.setLockWatchdogTimeout(12000);
            return Redisson.create(config);
        }
    }

}