Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring session on Redis - what is the failover when Redis is down

I am using Spring and Spring Security and want to use spring-session-data-redis with RedisHttpSessionConfiguration to enable storing session IDs on redis (so clients wont loose their sessions when webapp fails and switched over to another server).

My question, what happens when Redis server is down? Will spring be able to continue to work by storing session in memory until Redis is back up? Is there a way to configure this as so?

I am using Redis on AWS ElastiCache, and Failover can take several minutes before replacement primary node is configured on the DNS.

like image 849
Berethor Avatar asked Oct 29 '15 14:10

Berethor


People also ask

How does Redis session work?

The Redis session cache is most commonly used in a scenario where client requests are directed by a load balancing mechanism to two or more replicated WebSEAL servers. Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker.

How does Redis work with spring boot?

Redis supports data structures such as strings, hashes, lists, sets, and sorted sets with range queries. The Spring Data Redis framework makes it easy to write Spring applications that use the Redis Key-Value store by providing an abstraction to the data store.

How many sessions can Redis store?

The basic approach of serialising a JSON blob (or, better, a msgpack blob) into an expiring key is sufficient for managing sessions for all but the very largest of sites; you can handle over ten million sessions in less than 2GB of memory and Redis can handle at least 250 million root keys.


1 Answers

As far as I can see, you will need to provide an implementation of CacheErrorHandler ( javadoc).

You can do this by providing a Configuration instance, that implements CachingConfigurer, and overrides the errorHandler() method.

For example:

@Configuration
@Ena1bleCaching
public class MyApp extends SpringBootServletInitializer  implements CachingConfigurer {

  @Override
  public CacheErrorHandler errorHandler() {

    return MyAppCacheErrorHandler();
  }

}

Exactly HOW you will then provide uninterrupted service is not clear to me - without duplicating the current sessions in your failover cache, it seems impossible.

If you are using ElasticCache, is it not possible to have AWS handle a replicated setup for you, so that if one node goes doen, the other can take over?

like image 69
demaniak Avatar answered Sep 24 '22 03:09

demaniak