文章目录

  • 概述
  • Spring-Session 集成Redis集群
  • redis.properties
  • Spring-Session 集成Redis-Sentinel
  • Redis-Sentinel配置
  • Spring-Session 集成Redis-Cluster
  • Redis-Cluster配置
  • 演示验证
  • 启动Redis
  • 启动Nginx
  • 启动两台Tomcat
  • 查看Session保存效果

循序渐进,由易到难,这样才更有乐趣!

概述

本篇开始继续上一篇的内容基础上进行,本篇主要介绍Spring-Session实现配置使用Redis集群,会有两种配置方式,一种是Redis-Cluster,一种是Redis-Sentinel,并通过一个简单的demo进行实例演示!

对Redis-Cluster和Redis-Sentinel不太懂,或者不知道在Windows下面如何搭建的伙伴,请先移步到,

Redis高可用集群-哨兵模式(Redis-Sentinel)搭建配置教程【Windows环境】

Redis创建高可用集群教程【Windows环境】

进行简单的学习和配置好本次需要的环境!

Spring-Session 集成Redis集群

由于有了上一篇的介绍,上一篇中添加依赖:

spring-session-data-redis

而这个jar包会自动下载Spring-session和Jedis的依赖

spring-session
jedis

本次开始就直接上代码和配置,并进行简单的说明!

redis.properties
#jedisPoolConfig
redis.maxTotal=10
redis.maxIdle=8
redis.minIdle=0
redis.testOnBorrow=true
redis.testOnReturn=true
redis.maxWaitMillis=-1
redis.blockWhenExhausted=true
redis.evictionPolicyClassName=org.apache.commons.pool2.impl.DefaultEvictionPolicy
#redis-sentinel
redis.sentinel1.host=127.0.0.1
 redis.sentinel1.port=26379redis.sentinel2.host=127.0.0.1
 redis.sentinel2.port=26380redis.sentinel3.host=127.0.0.1
 redis.sentinel3.port=26381#redis-cluster
 #重试次数,在执行失败后,进行的重试次数,默认是5
 #此值设置过大时,容易报:Too many Cluster redirections
 redis.cluster.maxRedirects=3redis.cluster0.host=127.0.0.1
 redis.cluster0.port=20000redis.cluster1.host=127.0.0.1
 redis.cluster1.port=20001redis.cluster2.host=127.0.0.1
 redis.cluster2.port=20002redis.cluster3.host=127.0.0.1
 redis.cluster3.port=20003redis.cluster4.host=127.0.0.1
 redis.cluster4.port=20004redis.cluster5.host=127.0.0.1
 redis.cluster5.port=20005

Spring-Session 集成Redis-Sentinel

Redis-Sentinel配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">

<span class="token comment"><!-- 打开注解方式 --></span>
<span ><span ><span ><</span><span >context:</span>annotation-config</span><span >/></span></span>

<span class="token comment"><!--可以將redis配置写入配置文件中--></span>
<span ><span ><span ><</span><span >context:</span>property-placeholder</span> <span >location</span><span ><span >=</span><span >"</span>classpath:redis.properties<span >"</span></span><span >/></span></span>

<span class="token comment"><!--创建一个Spring Bean的名称springSessionRepositoryFilter实现过滤器。
筛选器负责将HttpSession实现替换为Spring会话支持。在这个实例中,Spring会话得到了Redis的支持。--></span>
<span ><span ><span ><</span>bean</span> <span >class</span><span ><span >=</span><span >"</span>org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration<span >"</span></span><span >/></span></span>

<span class="token comment"><!--创建了一个RedisConnectionFactory,它将Spring会话连接到Redis服务器。我们配置连接到默认端口(6379)上的本地主机!--></span>

<span class="token comment"><!-- //单机Redis
<bean class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
    <constructor-arg ref="jedisPoolConfig"/>
    <property name="port" value="6379"/>
    <property name="hostName" value="localhost"/>
</bean>
--></span>
<span class="token comment"><!--集群Redis--></span>
<span ><span ><span ><</span>bean</span> <span >id</span><span ><span >=</span><span >"</span>jedisConnectionFactory<span >"</span></span> <span >class</span><span ><span >=</span><span >"</span>org.springframework.data.redis.connection.jedis.JedisConnectionFactory<span >"</span></span><span >></span></span>
    <span class="token comment"><!--Redis-Sentinel--></span>
    <span ><span ><span ><</span>constructor-arg</span> <span >index</span><span ><span >=</span><span >"</span>0<span >"</span></span> <span >ref</span><span ><span >=</span><span >"</span>redisSentinelConfig<span >"</span></span><span >/></span></span>

    <span class="token comment"><!--配置Redis连接池 ,测试使用可以不配置,使用默认就行!--></span>
    <span ><span ><span ><</span>constructor-arg</span> <span >index</span><span ><span >=</span><span >"</span>1<span >"</span></span> <span >ref</span><span ><span >=</span><span >"</span>jedisPoolConfig<span >"</span></span><span >/></span></span>

<span ><span ><span ></</span>bean</span><span >></span></span>

<span ><span ><span ><</span>bean</span> <span >id</span><span ><span >=</span><span >"</span>jedisPoolConfig<span >"</span></span> <span >class</span><span ><span >=</span><span >"</span>redis.clients.jedis.JedisPoolConfig<span >"</span></span><span >></span></span>

    <span class="token comment"><!--最大连接数, 默认8个--></span>
    <span ><span ><span ><</span>property</span> <span >name</span><span ><span >=</span><span >"</span>maxTotal<span >"</span></span> <span >value</span><span ><span >=</span><span >"</span>${redis.maxTotal}<span >"</span></span><span >/></span></span>

    <span class="token comment"><!--最大空闲连接数, 默认8--></span>
    <span ><span ><span ><</span>property</span> <span >name</span><span ><span >=</span><span >"</span>maxIdle<span >"</span></span> <span >value</span><span ><span >=</span><span >"</span>${redis.maxIdle}<span >"</span></span><span >/></span></span>

    <span class="token comment"><!--最小空闲连接数, 默认0--></span>
    <span ><span ><span ><</span>property</span> <span >name</span><span ><span >=</span><span >"</span>minIdle<span >"</span></span> <span >value</span><span ><span >=</span><span >"</span>${redis.minIdle}<span >"</span></span><span >/></span></span>

    <span class="token comment"><!--在获取连接的时候检查有效性, 默认false--></span>
    <span ><span ><span ><</span>property</span> <span >name</span><span ><span >=</span><span >"</span>testOnBorrow<span >"</span></span> <span >value</span><span ><span >=</span><span >"</span>${redis.testOnBorrow}<span >"</span></span><span >/></span></span>

    <span class="token comment"><!--在空闲时检查有效性, 默认false, 新版jedis 不支持这个参数了--></span>
    <span ><span ><span ><</span>property</span> <span >name</span><span ><span >=</span><span >"</span>testOnReturn<span >"</span></span> <span >value</span><span ><span >=</span><span >"</span>${redis.testOnReturn}<span >"</span></span><span >/></span></span>

    <span class="token comment"><!--获取连接时的最大等待毫秒数(如果设置为阻塞时BlockWhenExhausted),如果超时就抛异常, 小于零:阻塞不确定的时间,  默认-1--></span>
    <span ><span ><span ><</span>property</span> <span >name</span><span ><span >=</span><span >"</span>maxWaitMillis<span >"</span></span> <span >value</span><span ><span >=</span><span >"</span>${redis.maxWaitMillis}<span >"</span></span><span >/></span></span>

    <span class="token comment"><!--连接耗尽时是否阻塞, false报异常,ture阻塞直到超时, 默认true--></span>
    <span ><span ><span ><</span>property</span> <span >name</span><span ><span >=</span><span >"</span>blockWhenExhausted<span >"</span></span> <span >value</span><span ><span >=</span><span >"</span>${redis.blockWhenExhausted}<span >"</span></span><span >/></span></span>

    <span class="token comment"><!--设置的逐出策略类名, 默认DefaultEvictionPolicy(当连接超过最大空闲时间,或连接数超过最大空闲连接数)--></span>
    <span ><span ><span ><</span>property</span> <span >name</span><span ><span >=</span><span >"</span>evictionPolicyClassName<span >"</span></span> <span >value</span><span ><span >=</span><span >"</span>${redis.evictionPolicyClassName}<span >"</span></span><span >/></span></span>

    <span class="token comment"><!--还有很多配置参数,参数的调优还没接触过,后面有机会结合项目整理整理--></span>
<span ><span ><span ></</span>bean</span><span >></span></span>

<span class="token comment"><!--哨兵模式配置--></span>
<span ><span ><span ><</span>bean</span> <span >id</span><span ><span >=</span><span >"</span>redisSentinelConfig<span >"</span></span> <span >class</span><span ><span >=</span><span >"</span>org.springframework.data.redis.connection.RedisSentinelConfiguration<span >"</span></span><span >></span></span>

    <span ><span ><span ><</span>property</span> <span >name</span><span ><span >=</span><span >"</span>master<span >"</span></span><span >></span></span>
        <span ><span ><span ><</span>bean</span> <span >class</span><span ><span >=</span><span >"</span>org.springframework.data.redis.connection.RedisNode<span >"</span></span><span >></span></span>
            <span ><span ><span ><</span>property</span> <span >name</span><span ><span >=</span><span >"</span>name<span >"</span></span> <span >value</span><span ><span >=</span><span >"</span>mymaster<span >"</span></span><span >></span></span><span ><span ><span ></</span>property</span><span >></span></span>
        <span ><span ><span ></</span>bean</span><span >></span></span>
    <span ><span ><span ></</span>property</span><span >></span></span>

    <span ><span ><span ><</span>property</span> <span >name</span><span ><span >=</span><span >"</span>sentinels<span >"</span></span><span >></span></span>
        <span ><span ><span ><</span>set</span><span >></span></span>
            <span ><span ><span ><</span>bean</span>  <span >id</span><span ><span >=</span><span >"</span>sentinel1<span >"</span></span> <span >class</span><span ><span >=</span><span >"</span>org.springframework.data.redis.connection.RedisNode<span >"</span></span><span >></span></span>
                <span ><span ><span ><</span>constructor-arg</span> <span >name</span><span ><span >=</span><span >"</span>host<span >"</span></span> <span >value</span><span ><span >=</span><span >"</span>${redis.sentinel1.host}<span >"</span></span><span >/></span></span>
                <span ><span ><span ><</span>constructor-arg</span> <span >name</span><span ><span >=</span><span >"</span>port<span >"</span></span> <span >value</span><span ><span >=</span><span >"</span>${redis.sentinel1.port}<span >"</span></span><span >/></span></span>
            <span ><span ><span ></</span>bean</span><span >></span></span>
            <span ><span ><span ><</span>bean</span>  <span >id</span><span ><span >=</span><span >"</span>sentinel2<span >"</span></span> <span >class</span><span ><span >=</span><span >"</span>org.springframework.data.redis.connection.RedisNode<span >"</span></span> <span >></span></span>
                <span ><span ><span ><</span>constructor-arg</span> <span >name</span><span ><span >=</span><span >"</span>host<span >"</span></span> <span >value</span><span ><span >=</span><span >"</span>${redis.sentinel2.host}<span >"</span></span><span >/></span></span>
                <span ><span ><span ><</span>constructor-arg</span> <span >name</span><span ><span >=</span><span >"</span>port<span >"</span></span> <span >value</span><span ><span >=</span><span >"</span>${redis.sentinel2.port}<span >"</span></span><span >/></span></span>
            <span ><span ><span ></</span>bean</span><span >></span></span>
            <span ><span ><span ><</span>bean</span>  <span >id</span><span ><span >=</span><span >"</span>sentinel3<span >"</span></span> <span >class</span><span ><span >=</span><span >"</span>org.springframework.data.redis.connection.RedisNode<span >"</span></span><span >></span></span>
                <span ><span ><span ><</span>constructor-arg</span> <span >name</span><span ><span >=</span><span >"</span>host<span >"</span></span> <span >value</span><span ><span >=</span><span >"</span>${redis.sentinel3.host}<span >"</span></span><span >/></span></span>
                <span ><span ><span ><</span>constructor-arg</span> <span >name</span><span ><span >=</span><span >"</span>port<span >"</span></span> <span >value</span><span ><span >=</span><span >"</span>${redis.sentinel3.port}<span >"</span></span><span >/></span></span>
            <span ><span ><span ></</span>bean</span><span >></span></span>
        <span ><span ><span ></</span>set</span><span >></span></span>
    <span ><span ><span ></</span>property</span><span >></span></span>
<span ><span ><span ></</span>bean</span><span >></span></span>

</beans>

Spring-Session 集成Redis-Cluster

Redis-Cluster配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">

<span class="token comment"><!-- 打开注解方式 --></span>
<span ><span ><span ><</span><span >context:</span>annotation-config</span><span >/></span></span>


<span class="token comment"><!--可以將redis配置写入配置文件中--></span>
<span ><span ><span ><</span><span >context:</span>property-placeholder</span> <span >location</span><span ><span >=</span><span >"</span>classpath:redis.properties<span >"</span></span><span >/></span></span>

<span class="token comment"><!--创建一个Spring Bean的名称springSessionRepositoryFilter实现过滤器。
筛选器负责将HttpSession实现替换为Spring会话支持。在这个实例中,Spring会话得到了Redis的支持。--></span>
<span ><span ><span ><</span>bean</span> <span >class</span><span ><span >=</span><span >"</span>org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration<span >"</span></span><span >/></span></span>

<span class="token comment"><!--创建了一个RedisConnectionFactory,它将Spring会话连接到Redis服务器。我们配置连接到默认端口(6379)上的本地主机!--></span>
<span class="token comment"><!--集群Redis--></span>
<span ><span ><span ><</span>bean</span> <span >id</span><span ><span >=</span><span >"</span>jedisConnectionFactory<span >"</span></span> <span >class</span><span ><span >=</span><span >"</span>org.springframework.data.redis.connection.jedis.JedisConnectionFactory<span >"</span></span><span >></span></span>
    <span class="token comment"><!--Redis-CLuster--></span>
    <span ><span ><span ><</span>constructor-arg</span> <span >index</span><span ><span >=</span><span >"</span>0<span >"</span></span> <span >ref</span><span ><span >=</span><span >"</span>redisClusterConfig<span >"</span></span><span >/></span></span>

    <span class="token comment"><!--配置Redis连接池 ,可以不配置,使用默认就行!--></span>
    <span ><span ><span ><</span>constructor-arg</span> <span >index</span><span ><span >=</span><span >"</span>1<span >"</span></span> <span >ref</span><span ><span >=</span><span >"</span>jedisPoolConfig<span >"</span></span><span >/></span></span>
<span ><span ><span ></</span>bean</span><span >></span></span>


<span ><span ><span ><</span>bean</span> <span >id</span><span ><span >=</span><span >"</span>jedisPoolConfig<span >"</span></span> <span >class</span><span ><span >=</span><span >"</span>redis.clients.jedis.JedisPoolConfig<span >"</span></span><span >></span></span>

    <span class="token comment"><!--最大连接数, 默认8个--></span>
    <span ><span ><span ><</span>property</span> <span >name</span><span ><span >=</span><span >"</span>maxTotal<span >"</span></span> <span >value</span><span ><span >=</span><span >"</span>${redis.maxTotal}<span >"</span></span><span >/></span></span>

    <span class="token comment"><!--最大空闲连接数, 默认8--></span>
    <span ><span ><span ><</span>property</span> <span >name</span><span ><span >=</span><span >"</span>maxIdle<span >"</span></span> <span >value</span><span ><span >=</span><span >"</span>${redis.maxIdle}<span >"</span></span><span >/></span></span>

    <span class="token comment"><!--最小空闲连接数, 默认0--></span>
    <span ><span ><span ><</span>property</span> <span >name</span><span ><span >=</span><span >"</span>minIdle<span >"</span></span> <span >value</span><span ><span >=</span><span >"</span>${redis.minIdle}<span >"</span></span><span >/></span></span>

    <span class="token comment"><!--在获取连接的时候检查有效性, 默认false--></span>
    <span ><span ><span ><</span>property</span> <span >name</span><span ><span >=</span><span >"</span>testOnBorrow<span >"</span></span> <span >value</span><span ><span >=</span><span >"</span>${redis.testOnBorrow}<span >"</span></span><span >/></span></span>

    <span class="token comment"><!--在空闲时检查有效性, 默认false, 新版jedis 不支持这个参数了--></span>
    <span ><span ><span ><</span>property</span> <span >name</span><span ><span >=</span><span >"</span>testOnReturn<span >"</span></span> <span >value</span><span ><span >=</span><span >"</span>${redis.testOnReturn}<span >"</span></span><span >/></span></span>

    <span class="token comment"><!--获取连接时的最大等待毫秒数(如果设置为阻塞时BlockWhenExhausted),如果超时就抛异常, 小于零:阻塞不确定的时间,  默认-1--></span>
    <span ><span ><span ><</span>property</span> <span >name</span><span ><span >=</span><span >"</span>maxWaitMillis<span >"</span></span> <span >value</span><span ><span >=</span><span >"</span>${redis.maxWaitMillis}<span >"</span></span><span >/></span></span>

    <span class="token comment"><!--连接耗尽时是否阻塞, false报异常,ture阻塞直到超时, 默认true--></span>
    <span ><span ><span ><</span>property</span> <span >name</span><span ><span >=</span><span >"</span>blockWhenExhausted<span >"</span></span> <span >value</span><span ><span >=</span><span >"</span>${redis.blockWhenExhausted}<span >"</span></span><span >/></span></span>

    <span class="token comment"><!--设置的逐出策略类名, 默认DefaultEvictionPolicy(当连接超过最大空闲时间,或连接数超过最大空闲连接数)--></span>
    <span ><span ><span ><</span>property</span> <span >name</span><span ><span >=</span><span >"</span>evictionPolicyClassName<span >"</span></span> <span >value</span><span ><span >=</span><span >"</span>${redis.evictionPolicyClassName}<span >"</span></span><span >/></span></span>

    <span class="token comment"><!--还有很多配置参数,参数的调优还没接触过,后面有机会结合项目整理整理--></span>
<span ><span ><span ></</span>bean</span><span >></span></span>

<span class="token comment"><!--集群模式配置--></span>
<span ><span ><span ><</span>bean</span> <span >id</span><span ><span >=</span><span >"</span>redisClusterConfig<span >"</span></span> <span >class</span><span ><span >=</span><span >"</span>org.springframework.data.redis.connection.RedisClusterConfiguration<span >"</span></span><span >></span></span>
    <span ><span ><span ><</span>property</span> <span >name</span><span ><span >=</span><span >"</span>maxRedirects<span >"</span></span> <span >value</span><span ><span >=</span><span >"</span>${redis.cluster.maxRedirects}<span >"</span></span><span >/></span></span>
    <span ><span ><span ><</span>property</span> <span >name</span><span ><span >=</span><span >"</span>clusterNodes<span >"</span></span><span >></span></span>
            <span ><span ><span ><</span>set</span><span >></span></span>
                <span ><span ><span ><</span>bean</span> <span >id</span><span ><span >=</span><span >"</span>cluster0<span >"</span></span> <span >class</span><span ><span >=</span><span >"</span>org.springframework.data.redis.connection.RedisNode<span >"</span></span><span >></span></span>
                    <span ><span ><span ><</span>constructor-arg</span> <span >name</span><span ><span >=</span><span >"</span>host<span >"</span></span> <span >value</span><span ><span >=</span><span >"</span>${redis.cluster0.host}<span >"</span></span><span >/></span></span>
                    <span ><span ><span ><</span>constructor-arg</span> <span >name</span><span ><span >=</span><span >"</span>port<span >"</span></span> <span >value</span><span ><span >=</span><span >"</span>${redis.cluster0.port}<span >"</span></span><span >/></span></span>
                <span ><span ><span ></</span>bean</span><span >></span></span>
                <span ><span ><span ><</span>bean</span> <span >id</span><span ><span >=</span><span >"</span>cluster1<span >"</span></span> <span >class</span><span ><span >=</span><span >"</span>org.springframework.data.redis.connection.RedisNode<span >"</span></span><span >></span></span>
                    <span ><span ><span ><</span>constructor-arg</span> <span >name</span><span ><span >=</span><span >"</span>host<span >"</span></span> <span >value</span><span ><span >=</span><span >"</span>${redis.cluster1.host}<span >"</span></span><span >/></span></span>
                    <span ><span ><span ><</span>constructor-arg</span> <span >name</span><span ><span >=</span><span >"</span>port<span >"</span></span> <span >value</span><span ><span >=</span><span >"</span>${redis.cluster1.port}<span >"</span></span><span >/></span></span>
                <span ><span ><span ></</span>bean</span><span >></span></span>
                <span ><span ><span ><</span>bean</span> <span >id</span><span ><span >=</span><span >"</span>cluster2<span >"</span></span> <span >class</span><span ><span >=</span><span >"</span>org.springframework.data.redis.connection.RedisNode<span >"</span></span><span >></span></span>
                    <span ><span ><span ><</span>constructor-arg</span> <span >name</span><span ><span >=</span><span >"</span>host<span >"</span></span> <span >value</span><span ><span >=</span><span >"</span>${redis.cluster2.host}<span >"</span></span><span >/></span></span>
                    <span ><span ><span ><</span>constructor-arg</span> <span >name</span><span ><span >=</span><span >"</span>port<span >"</span></span> <span >value</span><span ><span >=</span><span >"</span>${redis.cluster2.port}<span >"</span></span><span >/></span></span>
                <span ><span ><span ></</span>bean</span><span >></span></span>
                <span ><span ><span ><</span>bean</span> <span >id</span><span ><span >=</span><span >"</span>cluster3<span >"</span></span> <span >class</span><span ><span >=</span><span >"</span>org.springframework.data.redis.connection.RedisNode<span >"</span></span><span >></span></span>
                    <span ><span ><span ><</span>constructor-arg</span> <span >name</span><span ><span >=</span><span >"</span>host<span >"</span></span> <span >value</span><span ><span >=</span><span >"</span>${redis.cluster3.host}<span >"</span></span><span >/></span></span>
                    <span ><span ><span ><</span>constructor-arg</span> <span >name</span><span ><span >=</span><span >"</span>port<span >"</span></span> <span >value</span><span ><span >=</span><span >"</span>${redis.cluster3.port}<span >"</span></span><span >/></span></span>
                <span ><span ><span ></</span>bean</span><span >></span></span>
                <span ><span ><span ><</span>bean</span> <span >id</span><span ><span >=</span><span >"</span>cluster4<span >"</span></span> <span >class</span><span ><span >=</span><span >"</span>org.springframework.data.redis.connection.RedisNode<span >"</span></span><span >></span></span>
                    <span ><span ><span ><</span>constructor-arg</span> <span >name</span><span ><span >=</span><span >"</span>host<span >"</span></span> <span >value</span><span ><span >=</span><span >"</span>${redis.cluster4.host}<span >"</span></span><span >/></span></span>
                    <span ><span ><span ><</span>constructor-arg</span> <span >name</span><span ><span >=</span><span >"</span>port<span >"</span></span> <span >value</span><span ><span >=</span><span >"</span>${redis.cluster4.port}<span >"</span></span><span >/></span></span>
                <span ><span ><span ></</span>bean</span><span >></span></span>
                <span ><span ><span ><</span>bean</span> <span >id</span><span ><span >=</span><span >"</span>cluster5<span >"</span></span> <span >class</span><span ><span >=</span><span >"</span>org.springframework.data.redis.connection.RedisNode<span >"</span></span><span >></span></span>
                    <span ><span ><span ><</span>constructor-arg</span> <span >name</span><span ><span >=</span><span >"</span>host<span >"</span></span> <span >value</span><span ><span >=</span><span >"</span>${redis.cluster5.host}<span >"</span></span><span >/></span></span>
                    <span ><span ><span ><</span>constructor-arg</span> <span >name</span><span ><span >=</span><span >"</span>port<span >"</span></span> <span >value</span><span ><span >=</span><span >"</span>${redis.cluster5.port}<span >"</span></span><span >/></span></span>
                <span ><span ><span ></</span>bean</span><span >></span></span>
        <span ><span ><span ></</span>set</span><span >></span></span>
        <span ><span ><span ></</span>property</span><span >></span></span>
<span ><span ><span ></</span>bean</span><span >></span></span>

</beans>

演示验证

只演示Redis-Cluster,Redis-Cluster和Redis-Cluster就配置稍有不同,其他一样!

启动Redis

启动Nginx

启动两台Tomcat

上述三步和上一篇一样,这里就不在介绍!

查看Session保存效果

使用RedisDesktopManager,具体看下面截图,保存成功!

redis集群导致session失效 redis集群session共享_redis集群导致session失效

本次集群配置教程结束!