Redis认证客户端同时选择RESP协议版本



我有一个简单的微型应用程序,现在我正试图连接Redis独立集群与以下配置

application.yml

redis:
uri: redis://redis.dev.com
port: 6379
username: db_cache
password: password
io-thread-pool-size: 10
computation-thread-pool-size: 10
cache:
expiration-after-write-policy: 1h
pool:
enabled: true
min-idle: 5
max-total: 15
max-idle: 10

micronautRedisLettuce = "5.3.2"
micronautVersion = "3.8.1"

应用程序即将启动,但是当我到达健康端点时,我得到503响应,下面有一些协议问题的错误消息

io.micronaut.management.health.indicator.HealthResult - {} - Health indicator [redis(Primary)] reported exception: io.lettuce.core.RedisConnectionException: Unable to connect to dbaasprod-re-sppst-dc-107793.dev.target.com/<unresolved>:6379
io.lettuce.core.RedisConnectionException: Unable to connect to dbaasprod-re-sppst-dc-107793.dev.target.com/<unresolved>:6379
at io.lettuce.core.RedisConnectionException.create(RedisConnectionException.java:78) ~[lettuce-core-6.2.1.RELEASE.jar:6.2.1.RELEASE]
at io.lettuce.core.RedisConnectionException.create(RedisConnectionException.java:56) ~[lettuce-core-6.2.1.RELEASE.jar:6.2.1.RELEASE]
at io.lettuce.core.AbstractRedisClient.getConnection(AbstractRedisClient.java:350) ~[lettuce-core-6.2.1.RELEASE.jar:6.2.1.RELEASE]
at io.lettuce.core.RedisClient.connect(RedisClient.java:216) ~[lettuce-core-6.2.1.RELEASE.jar:6.2.1.RELEASE]
at io.lettuce.core.RedisClient.connect(RedisClient.java:201) ~[lettuce-core-6.2.1.RELEASE.jar:6.2.1.RELEASE]
at io.micronaut.configuration.lettuce.health.RedisHealthIndicator.healthResultForClient(RedisHealthIndicator.java:107) ~[micronaut-redis-lettuce-5.3.2.jar:5.3.2]
at io.micronaut.configuration.lettuce.health.RedisHealthIndicator.lambda$getResult$0(RedisHealthIndicator.java:99) ~[micronaut-redis-lettuce-5.3.2.jar:5.3.2]
at reactor.core.publisher.FluxFlatMap$FlatMapMain.onNext(FluxFlatMap.java:386) ~[reactor-core-3.5.0.jar:3.5.0]
at reactor.core.publisher.FluxIterable$IterableSubscription.slowPath(FluxIterable.java:272) ~[reactor-core-3.5.0.jar:3.5.0]
at reactor.core.publisher.FluxIterable$IterableSubscription.request(FluxIterable.java:230) ~[reactor-core-3.5.0.jar:3.5.0]
at reactor.core.publisher.FluxFlatMap$FlatMapMain.onSubscribe(FluxFlatMap.java:371) ~[reactor-core-3.5.0.jar:3.5.0]
at reactor.core.publisher.FluxIterable.subscribe(FluxIterable.java:165) ~[reactor-core-3.5.0.jar:3.5.0]
at reactor.core.publisher.FluxIterable.subscribe(FluxIterable.java:87) ~[reactor-core-3.5.0.jar:3.5.0]
at reactor.core.publisher.Flux.subscribe(Flux.java:8660) ~[reactor-core-3.5.0.jar:3.5.0]
at reactor.core.publisher.FluxConcatArray$ConcatArraySubscriber.onComplete(FluxConcatArray.java:258) ~[reactor-core-3.5.0.jar:3.5.0]
at reactor.core.publisher.FluxConcatArray.subscribe(FluxConcatArray.java:78) ~[reactor-core-3.5.0.jar:3.5.0]
at reactor.core.publisher.Flux.subscribe(Flux.java:8660) ~[reactor-core-3.5.0.jar:3.5.0]
at reactor.core.publisher.FluxFlatMap$FlatMapMain.onNext(FluxFlatMap.java:426) ~[reactor-core-3.5.0.jar:3.5.0]
at reactor.core.publisher.FluxIterable$IterableSubscription.slowPath(FluxIterable.java:272) ~[reactor-core-3.5.0.jar:3.5.0]
at reactor.core.publisher.FluxIterable$IterableSubscription.request(FluxIterable.java:230) ~[reactor-core-3.5.0.jar:3.5.0]
at reactor.core.publisher.FluxFlatMap$FlatMapMain.onSubscribe(FluxFlatMap.java:371) ~[reactor-core-3.5.0.jar:3.5.0]
at reactor.core.publisher.FluxIterable.subscribe(FluxIterable.java:165) ~[reactor-core-3.5.0.jar:3.5.0]
at reactor.core.publisher.FluxIterable.subscribe(FluxIterable.java:87) ~[reactor-core-3.5.0.jar:3.5.0]
at reactor.core.publisher.Mono.subscribe(Mono.java:4444) ~[reactor-core-3.5.0.jar:3.5.0]
at io.micronaut.management.health.monitor.HealthMonitorTask.monitor(HealthMonitorTask.java:98) ~[micronaut-management-3.8.1.jar:3.8.1]
at io.micronaut.management.health.monitor.$HealthMonitorTask$Definition$Exec.dispatch(Unknown Source) ~[micronaut-management-3.8.1.jar:3.8.1]
at io.micronaut.context.AbstractExecutableMethodsDefinition$DispatchedExecutableMethod.invoke(AbstractExecutableMethodsDefinition.java:378) ~[micronaut-inject-3.8.1.jar:3.8.1]
at io.micronaut.inject.DelegatingExecutableMethod.invoke(DelegatingExecutableMethod.java:76) ~[micronaut-inject-3.8.1.jar:3.8.1]
at io.micronaut.scheduling.processor.ScheduledMethodProcessor.lambda$process$5(ScheduledMethodProcessor.java:127) ~[micronaut-context-3.8.1.jar:3.8.1]
at io.micrometer.core.instrument.composite.CompositeTimer.record(CompositeTimer.java:141) ~[micrometer-core-1.10.2.jar:1.10.2]
at io.micrometer.core.instrument.Timer.lambda$wrap$0(Timer.java:196) ~[micrometer-core-1.10.2.jar:1.10.2]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539) ~[?:?]
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305) ~[?:?]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305) ~[?:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) ~[?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[?:?]
at java.lang.Thread.run(Thread.java:833) ~[?:?]
Caused by: io.lettuce.core.RedisCommandExecutionException: NOAUTH HELLO must be called with the client already authenticated, otherwise the HELLO AUTH <user> <pass> option can be used to authenticate the client and select the RESP protocol version at the same time
at io.lettuce.core.internal.ExceptionFactory.createExecutionException(ExceptionFactory.java:147) ~[lettuce-core-6.2.1.RELEASE.jar:6.2.1.RELEASE]
at io.lettuce.core.internal.ExceptionFactory.createExecutionException(ExceptionFactory.java:116) ~[lettuce-core-6.2.1.RELEASE.jar:6.2.1.RELEASE]
at io.lettuce.core.protocol.AsyncCommand.completeResult(AsyncCommand.java:120) ~[lettuce-core-6.2.1.RELEASE.jar:6.2.1.RELEASE]
at io.lettuce.core.protocol.AsyncCommand.complete(AsyncCommand.java:111) ~[lettuce-core-6.2.1.RELEASE.jar:6.2.1.RELEASE]
at io.lettuce.core.protocol.CommandWrapper.complete(CommandWrapper.java:63) ~[lettuce-core-6.2.1.RELEASE.jar:6.2.1.RELEASE]
at io.lettuce.core.protocol.CommandHandler.complete(CommandHandler.java:747) ~[lettuce-core-6.2.1.RELEASE.jar:6.2.1.RELEASE]
at io.lettuce.core.protocol.CommandHandler.decode(CommandHandler.java:682) ~[lettuce-core-6.2.1.RELEASE.jar:6.2.1.RELEASE]
at io.lettuce.core.protocol.CommandHandler.channelRead(CommandHandler.java:599) ~[lettuce-core-6.2.1.RELEASE.jar:6.2.1.RELEASE]```

从RedisURI中需要根据集群类型指定不同的url

URI语法

Redis Standalone
* redis://[[username:]password@]host [: port][/database][? [timeout=timeout[d|h|m|s|ms|us|ns]] [ &database=database] [&clientName=clientName] [&verifyPeer=NONE|CA|FULL]]
Redis Standalone (SSL)
* rediss://[[username:]password@]host [: port][/database][? [timeout=timeout[d|h|m|s|ms|us|ns]] [ &database=database] [&clientName=clientName] [&verifyPeer=NONE|CA|FULL]]
Redis Standalone (Unix Domain Sockets)
* redis-socket:// [[username:]password@]path[ ?[timeout=timeout[d|h|m|s|ms|us|ns]][&database=database] [&clientName=clientName] [&verifyPeer=NONE|CA|FULL]]
Redis Sentinel
* redis-sentinel://[[username:]password@]host1 [: port1][, host2 [:port2]][, hostN [:portN]][/ database][? [timeout=timeout[d|h|m|s|ms|us|ns]] [ &sentinelMasterId=sentinelMasterId] [&database=database] [&clientName=clientName] [&verifyPeer=NONE|CA|FULL]]

Redis uri可能包含身份验证细节,有效地导致用户名带密码,仅密码,或者不进行身份验证。连接通过使用RedisCredentials提供的信息进行身份验证。凭据在连接时从RedisCredentialsProvider获得。当静态地在URI上配置用户名/密码时,一个StaticCredentialsProvider保存配置的信息。

指出

  • 当使用Redis Sentinel时,来自URI的密码仅适用于数据节点。必须为每个哨兵节点配置哨兵身份验证。
  • 从Redis 6开始支持用户名。

在我的情况下,因为它是一个独立的服务器,我修改了url格式,包括密码,它工作。

uri: redis://password@redis.dev.com

对于某些集群,username可能是强制性的,那么您可以按照以下格式指定

uri: redis://username:password@redis.dev.com

相关内容

  • 没有找到相关文章

最新更新