YYAANNGGLLI 2015-12-01 07:27 采纳率: 0%
浏览 4897
已结题

redis的sentinel使用以及spring集成方面的问题

一. 我已经在linux端做好了master以及两个slave的redis,sentinel配置

二. 但是关于spring集成方面(即redis.xml的配置),我用了网上两种方法都没有成功。

1.参考于http://sumory.com/2014/08/15/spring-redis-sentinel/

 <bean id="jedisConnectionFactory"
        class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
        <property name="usePool" value="true"></property>
        <property name="hostName" value="192.168.86.5" />
        <property name="port" value="6371" />
        <property name="password" value="" />
        <property name="timeout" value="100000" />
        <property name="database" value="0"></property>
        <constructor-arg index="0" ref="jedisPoolConfig" />
    </bean>


    <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
        <property name="maxTotal" value="300" />
        <property name="maxIdle" value="100" />
        <property name="maxWaitMillis" value="1000" />
        <property name="testOnBorrow" value="false" />
        <property name="testOnReturn" value="true" />
    </bean>

    <bean id="jedisPool" class="redis.clients.jedis.JedisSentinelPool">
        <constructor-arg index="0" value="mymaster" />
        <constructor-arg index="1">
            <set>
                <value>192.168.86.5:26370</value>
                <value>192.168.86.5:26372</value>
            </set>
        </constructor-arg>
        <constructor-arg index="2" ref="jedisPoolConfig" />
    </bean>

    <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
        <property name="connectionFactory" ref="jedisConnectionFactory" />
        <property name="KeySerializer">
            <bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
        </property>
        <property name="ValueSerializer">
            <bean class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" />
        </property>
    </bean>

我想了想,应该是我的以上配置没有写正确,配置了jedispool但是没有调用。但是我的确不知道该怎么改,求懂sentinel的大神帮我看一下。

2.参考于http://blog.csdn.net/peterwanghao/article/details/44980085


    <bean id="redisSentinelConfiguration"
        class="org.springframework.data.redis.connection.RedisSentinelConfiguration">
        <property name="master">
            <bean class="org.springframework.data.redis.connection.RedisNode">
                <property name="name" value="mymaster"></property>
            </bean>
        </property>
        <property name="sentinels">
            <set>
                <bean class="org.springframework.data.redis.connection.RedisNode">
                    <constructor-arg name="host" value="192.168.86.5"></constructor-arg>
                    <constructor-arg name="port" value="26370"></constructor-arg>
                </bean>
                <bean class="org.springframework.data.redis.connection.RedisNode">
                    <constructor-arg name="host" value="192.168.86.5" />
                    <constructor-arg name="port" value="26371" />
                </bean>
                <bean class="org.springframework.data.redis.connection.RedisNode">
                    <constructor-arg name="host" value="192.168.86.5" />
                    <constructor-arg name="port" value="26372" />
                </bean>
            </set>
        </property>
    </bean>

    <bean id="jeidsConnectionFactory"
        class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
        <constructor-arg ref="redisSentinelConfiguration" />
    </bean>
    <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate"
        p:connection-factory-ref="jeidsConnectionFactory" />

用这个方法就更离奇了,我新建了一个项目用以测试这个配置时是可以使用的,整个redis的sentinel功能一切正常。但是我把这个代码移植到要做的项目运行中,始终都会报错( org.springframework.beans.NotWritablePropertyException: Invalid property 'sentinels' of bean class [org.springframework.data.redis.connection.RedisSentinelConfiguration]: Bean property 'sentinels' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?)

按理说sentinel不可写这个错是因为RedisSentinelConfiguration中没有sentinel的set、get方法,但确实是有的,不然测试的时候也不会成功。实在是不知道怎么解决了,查遍了百度,求大神帮我看看

  • 写回答

2条回答 默认 最新

  • YYAANNGGLLI 2015-12-02 09:02
    关注

    今天终于解决问题了,终于知道第二种方法为什么会出错。
    今天我把公司项目里其余的依赖全删掉,一个一个排查,终于找到是spring-web,spring-webmvc这两个依赖导致的问题,之前的版本是3.2.2,然后我把改成4.0.0之后就可以使用了。我想是因为版本低导致有冲突。

    评论

报告相同问题?

悬赏问题

  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题