【发布时间】: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" => "+@all"。 -
看来,只要我删除
users.acl中的user default off行(重新构建Docker 映像并启动一个新容器),同一个客户端就能够连接到Redis 实例.有人知道这里发生了什么吗? Tnx。