Skip to content

Latest commit

 

History

History
45 lines (32 loc) · 1.51 KB

File metadata and controls

45 lines (32 loc) · 1.51 KB

Simple Redis Session Manager for sparkjava

License badge Maven Central

Simple session manager for spark. It retrieves all session attributes from Redis on every request, and save them back to Redis if session attributes were changed during request processing.

Getting started

Add to your pom.xml:

<dependency>
    <groupId>com.github.jeckep</groupId>
    <artifactId>sparkjava-redis-session-manager</artifactId>
    <version>0.3.0</version>
</dependency>

Add to your main app class:

public static void main(String[] args) {
   final JedisPool pool = new JedisPool(new JedisPoolConfig(), "redis");
   final PSF psf = new PSF(new RedisSimplePersister(new JedisThreadSafeConnector(pool)));
   
   //before all before-filters                 
   before("*", psf.getBeforeFilter());
   
   //after all after-filters
   after("*", psf.getAfterFilter());
}

Customisation

If you don't want to use jedis as redis client, create you own class implementing RedisConnector instead of JedisConnector.

Disclaimer

Think before use this in production. You can use it but on your own risk.