Reputation: 41
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?
Upvotes: 0
Views: 1729
Reputation: 21720
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:
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:
For example:
@Bean
public JedisConnectionFactory connectionFactory() {
JedisConnectionFactory connection = new JedisConnectionFactory();
connection.setPort(6379);
connection.setHostName("example.com");
connection.setPassword("secret");
return connection;
}
Upvotes: 2