简体   繁体   English

使用springboot连接拒绝Redis主从

[英]Connection Refused redis master slave with springboot

I have a master slave set up on ports 3824(master) and 3825(slave). 我在端口3824(主机)和3825(从机)上设置了一个主从机。 However, when I shutdown master, the read operation gives a connection refused exception. 但是,当我关闭主服务器时,读取操作会给出拒绝连接的异常。 Below is my configuration. 下面是我的配置。 How can I ensure that even if I kill master, I'm still reading from slave. 我如何确保即使我杀死了主人,我仍在从奴隶那里读书。 Where did i go wrong. 我哪里做错了。

@Bean
public RedisConnectionFactory redisFactory() {

LettuceClientConfiguration config = LettuceClientConfiguration.builder().readFrom(ReadFrom.SLAVE_PREFERRED).buld();
RedisStandaloneConfiguration serverConfig = new RedisStandaloneConfiguration("localhost",3825);
    LettuceConnectionFactory fact = new LettuceConnectionFactory(serverConfig, config);
    return fact;
}

To support high-availability within your application, you might need to implement the redis-sentinel . 为了在您的应用程序中支持高可用性 ,您可能需要实现redis-sentinel

Redis Sentinel when passed to RedisSentinelConfiguration act as a bridge b/w your application and the redis master-slave nodes running as in a group of servers. 当传递给RedisSentinelConfiguration时,Redis Sentinel充当应用程序和运行在一组服务器中的redis主从节点的桥。

It will mainly act as a configuration provider. 它主要充当配置提供者。 If a failover occurs, Sentinels will report the new address 如果发生故障转移,Sentinels将报告新地址

Spring Data Redis Sentinel Support : Spring Data Redis Sentinel支持

/**
 * Lettuce
 */
@Bean
public RedisConnectionFactory lettuceConnectionFactory() {
  RedisSentinelConfiguration sentinelConfig = new RedisSentinelConfiguration()
  .master("mymaster")
  .sentinel("127.0.0.1", 26379)
  .sentinel("127.0.0.1", 26380);
  return new LettuceConnectionFactory(sentinelConfig);
}

Upon master failure event, when the slave is promoted as master, all write requests will be routed to the newly elected master. 在发生主设备故障事件时,当从设备升级为主设备时,所有写请求都将路由到新选举的主设备。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM