Shiro implements clustering through Redis management sessions http://sgq0085.iteye.com/blog/2170405
Maven
<dependency> <groupId>org.springframework.session</groupId> <artifactId>spring-session-data-redis</artifactId> <version>1.0.0.BUILD-SNAPSHOT</version> <type>pom<type> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>4.1.3.RELEASE</version> </dependency>
Hello World (based on Spring, other frameworks can also refer to this idea and make small modifications)
web.xml Add the following Filter
<filter> <filter-name>spring-session</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> <init-param> <param-name>targetBeanName</param-name> <param-value>springSession</param-value> </init-param> </filter> <filter-mapping> <filter-name>spring-session</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
spring.xml add
<!--Redis is added here, because the Session strategy of Redis that comes with Spring is used --> <bean id="v2redisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" p:host-name="10.0.0.40" p:port="6379" p:use-pool="true" p:database="8" /> <bean id="stringRedisSerializer" class="org.springframework.data.redis.serializer.StringRedisSerializer"/> <bean id="v2redisTemplate" class="org.springframework.data.redis.core.RedisTemplate" p:connection-factory-ref="v2redisConnectionFactory" p:keySerializer-ref="stringRedisSerializer" p:valueSerializer-ref="stringRedisSerializer" p:hashKeySerializer-ref="stringRedisSerializer" p:hashValueSerializer-ref="stringRedisSerializer" /> <!-- Here is to provide the parameters passed in the constructor for the following Session policy filter, because the Session filter depends on the object to construct, so create a first --> <bean name="redisOperationsSessionRepository" class="org.springframework.session.data.redis.RedisOperationsSessionRepository"> <constructor-arg ref="v2redisConnectionFactory"></constructor-arg> </bean> <!-- This is the Session policy filter, which replaces the original Session persistence mechanism of the container with Spring's Redis persistence Session mechanism. --> <!-- Note that this name must be consistent with the lower value of targetBean in web.xml. --> <bean name="springSession" class="org.springframework.session.web.http.SessionRepositoryFilter"> <constructor-arg ref="redisOperationsSessionRepository"></constructor-arg> </bean>
The usage is the same as the normal usage of Session.