@Singleton public class RedisSessionStore extends Object implements Session.Store
Session.Store powered by Redis.
{
use(new Redis());
session(RedisSessionStore.class);
get("/", req -> {
req.session().set("name", "jooby");
});
}
The name attribute and value will be stored in a
Redis db.
Session are persisted as
a Redis Hash.
By default, a redis session will expire after 30 minutes. Changing the default
timeout is as simple as:
# 8 hours session.timeout = 8h # 15 seconds session.timeout = 15 # 120 minutes session.timeout = 120m # no timeout session.timeout = -1
Default redis key prefix is sessions. Sessions in redis will look like:
sessions:ID
It's possible to change the default key setting the jedis.sesssion.prefix properties
| Constructor and Description |
|---|
RedisSessionStore(redis.clients.jedis.JedisPool pool,
String prefix,
int timeout)
Creates a new
RedisSessionStore. |
RedisSessionStore(redis.clients.jedis.JedisPool pool,
String prefix,
String timeout)
Creates a new
RedisSessionStore. |
| Modifier and Type | Method and Description |
|---|---|
void |
create(Session session) |
void |
delete(String id) |
Session |
get(Session.Builder builder) |
void |
save(Session session) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgenerateIDpublic RedisSessionStore(redis.clients.jedis.JedisPool pool,
String prefix,
int timeout)
RedisSessionStore.pool - Jedis pool.prefix - Session key prefix on redis.timeout - Session timeout in seconds.@Inject
public RedisSessionStore(redis.clients.jedis.JedisPool pool,
@Named(value="jedis.session.prefix")
String prefix,
@Named(value="jedis.session.timeout")
String timeout)
RedisSessionStore.pool - Jedis pool.prefix - Session key prefix on redis.timeout - Session timeout expression, like 30m.public Session get(Session.Builder builder)
get in interface Session.Storepublic void save(Session session)
save in interface Session.Storepublic void create(Session session)
create in interface Session.Storepublic void delete(String id)
delete in interface Session.StoreCopyright © 2015. All rights reserved.