ERR 该实例已禁用集群支持

问题描述 投票:0回答:3

我尝试使用有效的 URL 和端口连接到集群 Redis,但出现此错误:

Caused by: io.lettuce.core.RedisCommandExecutionException: ERR This instance has cluster support disabled
    at io.lettuce.core.ExceptionFactory.createExecutionException(ExceptionFactory.java:135)
    at io.lettuce.core.ExceptionFactory.createExecutionException(ExceptionFactory.java:108)
    at io.lettuce.core.protocol.AsyncCommand.completeResult(AsyncCommand.java:118)
    at io.lettuce.core.protocol.AsyncCommand.complete(AsyncCommand.java:109)

我有

cluster-enabled yes

java spring-boot spring-security redis
3个回答
1
投票

(是的,这是一个老问题)

这通常是尝试使用集群模式连接到独立服务器(作为开发容器启动?)的结果。 IOW,在代码中你可能有:

Config config = new Config();
config.useClusterServers() // <<--- Cluster mode
      .addNodeAddress("redis://127.0.0.1:7000");

但应该是:

Config config = new Config();
config.useSingleServer() // <<-- Single node mode
      .setAddress("redis://127.0.0.1:7000");

参见:https://github.com/redisson/redisson/wiki/2.-Configuration/#26-single-instance-mode


0
投票

确保使用conf作为参数

redis-server redis.conf

0
投票
  @Value("${spring.redis.host}")
  private String host;
  @Value("${spring.redis.port}")
  private int port;

  @Bean
  @Profile("!local")
  public RedisConnectionFactory redisConnectionFactory() {
    RedisClusterConfiguration redisClusterConfiguration = new RedisClusterConfiguration();
    redisClusterConfiguration = redisClusterConfiguration.clusterNode(host, port);
    return new JedisConnectionFactory(redisClusterConfiguration);
  }

  @Bean
  @Profile("!local")
  public RedisTemplate<String, Object> redisTemplate() {
    RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
    redisTemplate.setConnectionFactory(redisConnectionFactory());
    return redisTemplate;
  }

  @Bean
  @Profile("local")
  public RedisConnectionFactory redisStandaloneConnectionFactory() {
    RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration(host, port);
    return new JedisConnectionFactory(redisStandaloneConfiguration);
  }

  @Bean
  @Profile("local")
  public RedisTemplate<?, ?> redisStandaloneTemplate() {
    RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
    redisTemplate.setConnectionFactory(redisStandaloneConnectionFactory());
    return redisTemplate;
  }
© www.soinside.com 2019 - 2024. All rights reserved.