This sub-project contains the redis-store
implementation, a Redis-backended Tomcat PersistentManager
.
The implementation serializes sessions from their Java representation, storing the resulting byte[]
in the Redis store, keyed by the Session
id (i.e. JSESSIONID
).
Supported Tomcat and Java versions:
Version | Tomcat | Java |
---|---|---|
1.3.x.RELEASE | 8.5 | 8, 7 |
1.2.x.RELEASE | 8.0, 7.0 | 8, 7, 6 |
- Obtain or build a
redis-store
jar - Place the jar in the classpath for your Tomcat instance, e.g. the instance's
lib
directory - Configure the Tomcat instance to use
redis-store
- Configure
redis-store
Version 1.2.1+, 1.3.x+ | |
---|---|
repository | https://repo.spring.io/release/ |
group | com.gopivotal.manager |
name | redis-store |
version | 1.3.1.RELEASE (as an example) |
Version 1.2.0 | |
---|---|
repository | http://maven.gopivotal.com.s3.amazonaws.com/release/ |
group | com.gopivotal.manager |
name | redis-store |
version | 1.2.0.RELEASE |
# clone repository
% git clone https://github.com/pivotalsoftware/session-managers
% cd session-managers
# build
% mvn package
# redis-store jar will be in redis-store/target
% ls -1 redis-store/target/*jar
redis-store/target/redis-store-1.3.2.BUILD-SNAPSHOT-sources.jar
redis-store/target/redis-store-1.3.2.BUILD-SNAPSHOT.jar
To use the Store, edit either the Tomcat instance's or application's context.xml
, adding the following <Valve />
and <Manager />
definitions:
<Context>
...
<Valve className="com.gopivotal.manager.SessionFlushValve" />
<Manager className="org.apache.catalina.session.PersistentManager">
<Store className="com.gopivotal.manager.redis.RedisStore" />
</Manager>
...
</Context>
Configure redis-store
using <Store />
attributes:
Attribute | Default | Description |
---|---|---|
connectionPoolSize |
-1 |
Maximum number of concurrent connections |
database |
0 |
Redis database. Cluster will ignore this property |
host |
localhost |
Redis host. Cluster should follow this pattern: <host>:<port>;<host>:<port>;<host>:<port> |
password |
<none> |
Redis AUTH password |
sessionKeyPrefix |
sessions |
Prefix for redis keys. Useful for situations where 1 redis cluster serves multiple application clusters with potentially conflicting session IDs. |
port |
6379 |
Redis port. Also ignored in cluster |
timeout |
2000 |
Connection timeout (in milliseconds) |
uri |
<none> |
Connection URI, e.g. redis://username:password@localhost:6370/0 . Invalid for cluster configuration |
cluster |
false |
Flag for cluster configuration |
Example: set the maximum number of concurrent connections to 20:
<Context>
...
<Store
className="com.gopivotal.manager.redis.RedisStore"
connectionPoolSize="20"
/>
...
</Context>