【问题标题】:RedisCommandExecutionException in Java Lettuce Redis clientJava Lettuce Redis 客户端中的 RedisCommandExecutionException
【发布时间】:2021-06-28 06:42:33
【问题描述】:

我在使用带有 ACL 的 Java Lettuce Redis 客户端时遇到问题:我收到 io.lettuce.core.RedisCommandExecutionException: WRONGPASS invalid username-password pair or user is disabled 异常。 我有一个 Redis Docker 容器配置如下:

我的Dockerfile

FROM redis:6.2.1

COPY redis.conf /usr/local/etc/redis/redis.conf
COPY users.acl /etc/redis/users.acl

EXPOSE 6379

CMD ["redis-server", "/usr/local/etc/redis/redis.conf"]

redis.conf 文件是:

aclfile /etc/redis/users.acl

users.acl 文件是:

user myuser on +@all ~* >mypassword
user default off

我使用以下命令运行容器:

docker run -it -p 6379:6379 --name myredis myredis

我的 Java 客户端是:

...

import io.lettuce.core.RedisClient;
import io.lettuce.core.api.StatefulRedisConnection;

public class Main {
    public static void main(String... args) {
        try {
            RedisClient redisClient = RedisClient.create("redis://myuser:mypassword@localhost");
            StatefulRedisConnection<String, String> connection = redisClient.connect();
            System.out.println("Connected to Redis");
            connection.close();
            redisClient.shutdown();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            System.out.println("End!");
        }
    }
}

当我尝试运行它时,我得到了错误:

io.lettuce.core.RedisConnectionException: Unable to connect to localhost:6379
    at io.lettuce.core.RedisConnectionException.create(RedisConnectionException.java:78)
    at io.lettuce.core.RedisConnectionException.create(RedisConnectionException.java:56)
    at io.lettuce.core.AbstractRedisClient.getConnection(AbstractRedisClient.java:234)
    at io.lettuce.core.RedisClient.connect(RedisClient.java:207)
    at io.lettuce.core.RedisClient.connect(RedisClient.java:192)
    at [MY_PACKAGE].Main.main(Main.java:16)
Caused by: io.lettuce.core.RedisCommandExecutionException: WRONGPASS invalid username-password pair or user is 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:120)
    at io.lettuce.core.protocol.AsyncCommand.complete(AsyncCommand.java:111)
    at io.lettuce.core.protocol.CommandHandler.complete(CommandHandler.java:654)
    at io.lettuce.core.protocol.CommandHandler.decode(CommandHandler.java:614)
    at io.lettuce.core.protocol.CommandHandler.channelRead(CommandHandler.java:565)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:352)
    at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1422)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360)
    at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:931)
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:700)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:635)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:552)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:514)
    at io.netty.util.concurrent.SingleThreadEventExecutor$6.run(SingleThreadEventExecutor.java:1050)
    at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
    at java.base/java.lang.Thread.run(Thread.java:834)

我做错了什么?提前致谢。

【问题讨论】:

  • 生菜版本:5.2.1。尝试升级到6.1.0,我收到错误:io.lettuce.core.RedisCommandExecutionException: NOPERM this user has no permissions to run the 'hello' command or its subcommand,我无法理解,因为在我看来,用户似乎拥有所有命令的权限:"commands" =&gt; "+@all"
  • 看来,只要我删除users.acl 中的user default off 行(重新构建Docker 映像并启动一个新容器),同一个客户端就能够连接到Redis 实例.有人知道这里发生了什么吗? Tnx。

标签: java redis lettuce


【解决方案1】:

这对我有用(生菜 6.0.4),但它是纯粹的魔法:

改变

user default off

进入

user default off -@all +hello

我阅读了 redis 和 lettuce 文档,但找不到合适的解释,但这对您来说可能听起来更合法:

user default on nopass -@all +hello

这将使客户端能够使用默认用户仅运行 hello 命令,然后通过某种方式,客户端将知道使用配置的用户 (myuser) 来执行更多命令。

希望对你有所帮助,等待大家的解释:penguin:

【讨论】:

  • 非常感谢,我会尽快尝试。
猜你喜欢
  • 2015-12-13
  • 1970-01-01
  • 2017-04-24
  • 1970-01-01
  • 2017-01-05
  • 1970-01-01
  • 1970-01-01
  • 2020-12-01
  • 1970-01-01
相关资源
最近更新 更多