Hongyu Jiang
Hongyu Jiang

Reputation: 41

Can I let spring-session used a standalone redis?

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

Answers (1)

Rob Winch
Rob Winch

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:

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

Related Questions