I have built up a redis server, I want to know whether I can make spring-session use the existed redis server instead of embed its redis-server?
Asked
Active
Viewed 1,694 times
1 Answers
2
Yes Spring Session can and should use an existing Redis Server. This is the primary way to deploy to production. I have provided a few examples below:
Spring Boot
Taking the Spring Boot Sample and converting it to use an external Redis Server can be done by:
- Removing the @EmbeddedRedisServer annotation
Configuring the Redis Server Location For example, you might provide the following properties in your application.properties:
spring.redis.host=example.com spring.redis.password=secret spring.redis.port=6379
Other Samples
The other samples are quite similar to use an external Redis instance. For example, to change the httpsession sample to use an external Redis:
- Remove @EnableEmbeddedRedis
- Update your RedisConnectionFactory Bean definition to point to your Redis server
For example:
@Bean
public JedisConnectionFactory connectionFactory() {
JedisConnectionFactory connection = new JedisConnectionFactory();
connection.setPort(6379);
connection.setHostName("example.com");
connection.setPassword("secret");
return connection;
}

Rob Winch
- 21,440
- 2
- 59
- 76