club.zhcs.redission.cache.config.RedissonSpringCacheAutoConfiguration Maven / Gradle / Ivy
package club.zhcs.redission.cache.config;
import org.redisson.api.RedissonClient;
import org.redisson.codec.JsonJacksonCodec;
import org.redisson.codec.SerializationCodec;
import org.redisson.spring.cache.RedissonSpringCacheManager;
import org.redisson.spring.starter.RedissonAutoConfigurationCustomizer;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cache.CacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import club.zhcs.redission.cache.config.RedissonSpringCacheConfigurationProperties.SerializationMode;
/**
* @author wkipy
*
*/
@Configuration
@ConditionalOnExpression("${redission.cache.enabled:true}")
@EnableConfigurationProperties(RedissonSpringCacheConfigurationProperties.class)
public class RedissonSpringCacheAutoConfiguration {
@Bean
public RedissonAutoConfigurationCustomizer customizer(RedissonSpringCacheConfigurationProperties config) {
return configuration -> configuration.setCodec(config.getSerializationMode() == SerializationMode.JSON ? new JsonJacksonCodec() : new SerializationCodec());
}
@Bean
public CacheManager cacheManager(RedissonClient redissonClient, RedissonSpringCacheConfigurationProperties config) {
return new RedissonSpringCacheManager(redissonClient, config.getConfig());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy