Search code examples
scalaredislettuce

Lettuce 6.0.1.RELEASE deprecated .withPassword


With Earlier version 5.1.6.RELEASE , withPassword works perfectly. How ever with latest version it shows warning that withPassword is deprecated.It takes Array[Char] or charSequence .

  @transient lazy val redisClient = RedisClient.create(
    RedisURI.builder()
      .withHost(redisHost)
      .withPort(redisPort)
      .withPassword(redisAuth)
      .withSsl(true)
      .build()


Solution

  • According to the documentation you shouldn't use the withPassword method taking a String as a parameter but use a CharSequence or an Array[Char]

    • @deprecated since 6.0. Use {@link #withPassword(CharSequence)} or {@link #withPassword(char[])} avoid String caching.

    See also the api docs or the plain comments at the source code.

    So if simply change your code to

    @transient lazy val redisClient = RedisClient.create(
        RedisURI.builder()
          .withHost(redisHost)
          .withPort(redisPort)
          .withPassword(redisAuth.toCharArray)
          .withSsl(true)
          .build()
    

    you will at least avoid the warning (but kind of workaround the reason why the introduced that deprecatation). Maybe this question + answers is worth reading: Why is char[] preferred over String for passwords?.