zoukankan      html  css  js  c++  java
  • redisTemplate 集群版

    1.pom
    <spring.version>4.2.4.RELEASE</spring.version>
    <redis.version>2.9.0</redis.version>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-redis</artifactId>
        <version>1.8.4.RELEASE</version>
    </dependency>

    2.redis配置文件

      <!-- 配置Cluster -->
        <bean id="redisClusterConfiguration"
            class="org.springframework.data.redis.connection.RedisClusterConfiguration">
            <property name="maxRedirects" value="3"></property>
            <!-- 节点配置 -->
            <property name="clusterNodes">
                <set>
                    <bean class="org.springframework.data.redis.connection.RedisClusterNode">
                        <constructor-arg name="host" value="${redis.host1}"></constructor-arg>
                        <constructor-arg name="port" value="${redis.port1}"></constructor-arg>
                    </bean>
                    <bean class="org.springframework.data.redis.connection.RedisClusterNode">
                        <constructor-arg name="host" value="${redis.host2}"></constructor-arg>
                        <constructor-arg name="port" value="${redis.port2}"></constructor-arg>
                    </bean>
                    <bean class="org.springframework.data.redis.connection.RedisClusterNode">
                        <constructor-arg name="host" value="${redis.host3}"></constructor-arg>
                        <constructor-arg name="port" value="${redis.port3}"></constructor-arg>
                    </bean>
                    <bean class="org.springframework.data.redis.connection.RedisClusterNode">
                        <constructor-arg name="host" value="${redis.host4}"></constructor-arg>
                        <constructor-arg name="port" value="${redis.port4}"></constructor-arg>
                    </bean>
                    <bean class="org.springframework.data.redis.connection.RedisClusterNode">
                        <constructor-arg name="host" value="${redis.host5}"></constructor-arg>
                        <constructor-arg name="port" value="${redis.port5}"></constructor-arg>
                    </bean>
                    <bean class="org.springframework.data.redis.connection.RedisClusterNode">
                        <constructor-arg name="host" value="${redis.host6}"></constructor-arg>
                        <constructor-arg name="port" value="${redis.port6}"></constructor-arg>
                    </bean>
                </set>
            </property>
        </bean>
        <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
            <property name="maxIdle" value="100" />
            <property name="maxTotal" value="600" />
        </bean>
    
        <bean id="jedisConnectionFactory"
            class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
            <constructor-arg ref="redisClusterConfiguration" />
            <constructor-arg ref="jedisPoolConfig" />
        </bean>
    
    
    
        <!-- redis 访问的模版 -->
        <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
            <property name="connectionFactory" ref="jedisConnectionFactory" />
            <!-- 添加如下序列化配置解决key乱码问题以及令keys()方法生效 -->
            <property name="keySerializer">
                <bean
                    class="org.springframework.data.redis.serializer.StringRedisSerializer" />
            </property>
            <property name="valueSerializer">
                <bean
                    class="org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer" />
            </property>
            <property name="hashKeySerializer">
                <bean
                    class="org.springframework.data.redis.serializer.StringRedisSerializer" />
            </property>
            <property name="hashValueSerializer">
                <bean
                    class="org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer" />
            </property>
            <!--开启事务 -->
            <property name="enableTransactionSupport" value="true"></property>
        </bean>

     引一篇文章:https://blog.csdn.net/MOTUI/article/details/52903397

  • 相关阅读:
    RAID10磁盘阵列损坏的修复
    Linux系统中物理劵增加、删除;卷组的扩容、缩容;逻辑卷的增加与删除
    Ubuntu alternate和desktop区别 zz
    freecommander 快捷键列表 zz
    调试小技巧
    Java框架
    获取url的文件名(动态改变css)
    Urlrewrite方法集
    NVelocity模板引擎,初级体验,非常有用的东东.(转)
    CodeSmith&NetTiers Step by Step[转]
  • 原文地址:https://www.cnblogs.com/step-and-step/p/10071237.html
Copyright © 2011-2022 走看看