【问题标题】:Jedis connection in Spring fails to authenticate on RedisSpring 中的 Jedis 连接无法在 Redis 上进行身份验证
【发布时间】:2021-09-06 05:06:07
【问题描述】:

我有一个 Spring Boot 应用程序通过 tls 和密码连接到 Redis。

我正在使用以下配置来实例化 RedistTemplate 和 JedisConnection

 @Bean
  JedisConnectionFactory jedisConnectionFactory() {
     RedisStandaloneConfiguration conf = new RedisStandaloneConfiguration(host,port);
     conf.setPassword(RedisPassword.of("myPassword"));
     JedisConnectionFactory jedisConFactory = null;
     JedisClientConfiguration confJedis = JedisClientConfiguration.builder().useSsl().build();
     jedisConFactory =  new JedisConnectionFactory(conf,confJedis);
     //jedisConFactory.setPassword("myPassword");
     return jedisConFactory;
  }


 @Bean
  public RedisTemplate<String, Object> redisTemplate() {
      RedisTemplate<String, Object> template = new RedisTemplate<>();
      template.setConnectionFactory(jedisConnectionFactory());
      return template;
  }

我收到以下错误:

class org.springframework.dao.InvalidDataAccessApiUsageExceptionNOAUTH Authentication required.; nested exception is redis.clients.jedis.exceptions.JedisDataException: NOAUTH Authentication required.

这似乎是 Redis 未收到密码的错误。

在 redis 上启用 TLS 配置之前,我使用的是这个配置:

  @Bean
  JedisConnectionFactory jedisConnectionFactory() {
     RedisStandaloneConfiguration conf = new RedisStandaloneConfiguration(host,port);
     conf.setPassword(RedisPassword.of("myPassword"));
     JedisConnectionFactory jedisConFactory = null;
     jedisConFactory =  new JedisConnectionFactory(conf);
     return jedisConFactory;
  }

而且它工作得很好。 所以在“如何”中,我使用 TLS 在 Jedis 配置中设置密码不起作用,我什至使用了不推荐使用的方法(在上面的 sn-p 中注释):

//jedisConFactory.setPassword("myPassword");

看看它是否可以工作但没有成功。

有人看到我做错了吗?

【问题讨论】:

    标签: redis spring-data jedis


    【解决方案1】:

    我遇到了同样的问题,并通过将 .and().usePooling() 添加到代码中来解决它,如下所示:

    JedisClientConfiguration confJedis = JedisClientConfiguration.builder().useSsl().and().usePooling().build();
    

    我找到了答案here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-14
      • 2016-01-11
      • 1970-01-01
      • 2016-09-14
      • 1970-01-01
      • 2018-11-04
      相关资源
      最近更新 更多