I have application.properties and application-dev.properties.
In my application.properties (single node instance)
spring.redis.host=127.0.0.1
spring.redis.port=6379
And in my application-dev.properties (since i have cluster set up in dev env)
spring.redis.cluster.nodes=10.212.41.20:6379, 10.292.40.291:6379
Now since spring.redis.host is not present in dev profile property file it is overriding from application.property and hence spring.redis.cluster.nodes is not taken into consideration.
How can i tell springboot to not override spring.redis.host when i am starting in dev profile
2
Answers
I would suggest to go with Redisson client (I do not know what client you use) and use something like this https://www.baeldung.com/redis-redisson
Essentially you create different config files per profile and can choose from many different type of topologies :
I’ve used it before and it’s really clean as each environment is independent from the other (and in the application properties file you only define which file is the one for this env).
I hope it helped , although my suggestion is not what you exactly asked I wanted to share such an approach as it’s clean in my opinion 🙂
Have a nice day 🙂
IIRC
spring.redis.cluster.*
takes priority overspring.redis.host
. I also don’t recommend switching over to Redisson as it’s yet another dependency (also requires paid version to have any meaningful use).Your question is a bit hard to understand though, so if you want
dev
to have the cluster then you simply add the cluster configuration and Spring would use clustered mode first at least that’s the case with Lettuce (which is the default)The code in
LettuceConnectionConfiguration
isSo it prioritizes a sentinel configuration then cluster then single depending on the presence of the configuration elemeents.
As such your dev profile should be working in cluster already.