Quantcast
Channel: Active questions tagged redis+java - Stack Overflow
Viewing all articles
Browse latest Browse all 2204

Could not setup redis using application.yaml

$
0
0

I am trying to setup redis cluster caching with spring boot version 2.7.14

I can manually configure redis via beans. For example following way I can easily configure:

@Slf4j@Configurationpublic class CacheConfiguration implements CachingConfigurer {    @Bean    public RedisConnectionFactory redisConnectionFactory() {        RedisClusterConfiguration clusterConfig = new RedisClusterConfiguration(                Collections.singletonList("{IP}:{PORT}") // hidden for security purpose        );        LettuceClientConfiguration clientConfig = LettuceClientConfiguration.builder()                .readFrom(ReadFrom.REPLICA_PREFERRED)                .build();        return new LettuceConnectionFactory(clusterConfig, clientConfig);    }    @Bean    public RedisCacheManager cacheManager() {        return RedisCacheManager.builder(this.redisConnectionFactory())                .cacheDefaults(cacheConfiguration())                .build();    }    @Bean    public RedisCacheConfiguration cacheConfiguration() {        return RedisCacheConfiguration.defaultCacheConfig()                .disableCachingNullValues()                .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(new GenericJackson2JsonRedisSerializer()));    }    public CacheErrorHandler errorHandler() {        return new CacheErrorHandler() {            @Override            public void handleCacheGetError(RuntimeException exception, Cache cache, Object key) {                log.error("Failure getting from cache: {}", cache.getName(), exception);            }            @Override            public void handleCachePutError(RuntimeException exception, Cache cache, Object key, Object value) {                log.info("Failure putting into cache: {}", cache.getName(), exception);            }            @Override            public void handleCacheEvictError(RuntimeException exception, Cache cache, Object key) {                log.info("Failure evicting from cache: {}", cache.getName(), exception);            }            @Override            public void handleCacheClearError(RuntimeException exception, Cache cache) {                log.info("Failure clearing cache: {}", cache.getName(), exception);            }        };    }}

However, whenever I try to configure it using JUST the properties yaml file, I encounter problems:

spring:  main:    allow-circular-references: true  cache:    type: redis  data:    redis:      lettuce:        pool:          enabled: true      database: 0      cluster:        nodes: IP:PORT        maxRedirects: 2

What am I missing here?I looked up on spring docs but no help there:https://docs.spring.io/spring-boot/docs/2.7.14/reference/html/application-properties.html#appendix.application-properties

Note that my redis setup is cluster. Not a standalone one. I am not using sentinel or anything like that either.

What goes wrong here?


Viewing all articles
Browse latest Browse all 2204

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>