开发者社区> 问答> 正文

spring data redis 的sentinel配置问题-java报错

"

有人配置过spring data redis 的 sentinel 吗??为什么我链接其他机子,但是项目跑起来的时候日志显示却是链接本机子的。我配置是链接192.168.1.130的 sentinel ,但是log 链接却是127.0.0.1的,不知道为什么这样??


"

展开
收起
montos 2020-06-01 21:11:07 582 0
1 条回答
写回答
取消 提交回答
  • "贴一下jedis 哨兵那块的连接代码呗。光看配置文件,看不出来问题来。######回复 <a href=""http://my.oschina.net/redhat1520"" class=""referer"" target=""_blank"">@黑帽子 : ok。能解决就ok######这个问题我找到了,原来是Linux那边redis的sentinel配置里都是127.0.0.1,改为正式ip就行了。######我redis链接都是在配置里面完成的,redisSentinelConfiguration里面配置sentinel的host和port, 再把这个redisSentinelConfiguration注入到redisConnectionFactory,都是在配置里完成的。######

    这是我的配置 验证OK

    <pre class=""brush:xml; toolbar: true; auto-links: false;""><bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig"> <property name="testWhileIdle" value="true" /> <property name="minEvictableIdleTimeMillis" value="30000" /> <property name="timeBetweenEvictionRunsMillis" value="30000" /> <property name="maxTotal" value="600" /> <property name="maxIdle" value="300" /> </bean>

    <bean id="jedisSentinelPool" class="redis.clients.jedis.JedisSentinelPool" destroy-method="destroy">
    	<constructor-arg name="masterName">
    		<value>master1</value>
    	</constructor-arg>
    	<constructor-arg name="sentinels">
    		<set value-type="java.lang.String">
    			<value>${redis.host1}</value>
    			<value>${redis.host2}</value>
    		</set>
    	</constructor-arg>
    	<constructor-arg name="poolConfig" ref="jedisPoolConfig" />
    </bean></pre> 
    


    redis.host1=10.10.10.41:26379
    redis.host2=10.10.10.41:26380 


    "
    2020-06-01 21:11:16
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
ApsaraDB for Redis——与创客同行 立即下载
微博的Redis定制之路 立即下载
云数据库Redis版的开源之路 立即下载