Redis sessions store for Tomcat
Posted: Wed, Mar 9 01:17 AM (PST)Do you need store your Tomcat sessions in database?
That is solution for you! Redis database is an open source, advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets.
How do I use it?
Download, extract and compile Redis database with:
$ curl -O http://redis.googlecode.com/files/redis-2.2.2.tar.gz $ tar xzf redis-2.2.2.tar.gz $ cd redis-2.2.2 $ make
The binaries that are now compiled are available in the src directory. Run Redis with:
$ src/redis-server
You can interact with Redis using the built-in client:
$ src/redis-cli redis> set foo bar OK redis> get foo "bar"
Our Redis database is ready.
Next step: download the latests build Redis Store for Tomcat at:
http://github.com/xetorthio/RedisStore/downloads
Copy jar into the lib folder of your tomcat installation directory, then edit conf/server.xml file and within your context tag add the following lines:
<Manager className="org.apache.catalina.session.PersistentManager" saveOnRestart="true" maxActiveSessions="1" minIdleSwap="1" maxIdleSwap="1" maxIdleBackup="1">
<Store className="org.apache.catalina.session.RedisStore"
host="localhost"
port="6379"
password="something"
database="0"
/>
</Manager>
Make sure that whatever you store in the session is Serializable.
Tags: