Search code examples
spring-sessionspring-data-redis

Can multiple Spring sessions be backed by same redis instance?


We have a couple of web applications written on Java Spring, we are using spring-data-redis and @EnableRedisHttpSession. I was wondering what are the spring session internals. Would it check redis database for duplicate session keys before creating a new session?

I looked at spring documentation and also did a google search but couldn't get a definitive answer.


Solution

  • Found the solution after going through spring session project's github issues. Answer provided by @Avnish doesn't work because in cluster configuration redis does not provide databases, there is just a single database 0 and SELECT commands are not supported.

    [email protected] solves this issue by providing session namespaces. If you are using @EnableRedisHttpSession annotation, you can add redisNamespace property to it. Or you can add the key in spring.session.redis.namespace property in your .properties or .yml file.