kotlin - RedisClusterCommands scriptLoad()
问题描述
我正在使用 Lettuce lib 连接到 Redis Cluster 服务器,当我尝试调用 RedisClusterCommands.scriptLoad() 时出现错误。它抛出异常:
io.lettuce.core.RedisException: io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: /127.0.0.1:7004
at io.lettuce.core.LettuceFutures.awaitOrCancel(LettuceFutures.java:129) ~[lettuce-core-5.1.6.RELEASE.jar:?]
at io.lettuce.core.cluster.ClusterFutureSyncInvocationHandler.handleInvocation(ClusterFutureSyncInvocationHandler.java:123) ~[lettuce-core-5.1.6.RELEASE.jar:?]
at io.lettuce.core.internal.AbstractInvocationHandler.invoke(AbstractInvocationHandler.java:80) ~[lettuce-core-5.1.6.RELEASE.jar:?]
at com.sun.proxy.$Proxy123.scriptLoad(Unknown Source) ~[?:?]
at com.slotty.common.services.redis.RedisManager.loadLuaScriptRaw(RedisManager.kt:106) ~[com.slotty.common-2.0.0.jar:?]
at com.slotty.common.services.redis.RedisManager.loadLuaScript(RedisManager.kt:77) ~[com.slotty.common-2.0.0.jar:?]
at com.slotty.core.server.BaseServer.createServerStore(BaseServer.kt:154) ~[com.slotty.core-2.0.0.jar:?]
at com.slotty.core.server.BaseServer.initStores(BaseServer.kt:150) ~[com.slotty.core-2.0.0.jar:?]
at com.slotty.core.server.BaseZone.initStores(BaseZone.kt:163) ~[com.slotty.core-2.0.0.jar:?]
at com.slotty.core.server.BaseServer.initServices(BaseServer.kt:87) ~[com.slotty.core-2.0.0.jar:?]
at com.slotty.core.server.BaseZone.initServices(BaseZone.kt:49) ~[com.slotty.core-2.0.0.jar:?]
at com.slotty.core.server.BaseServer.initialize(BaseServer.kt:65) ~[com.slotty.core-2.0.0.jar:?]
at com.slotty.core.server.BaseServer.init(BaseServer.kt:55) [com.slotty.core-2.0.0.jar:?]
at com.smartfoxserver.v2.entities.managers.SFSExtensionManager.createExtension(SFSExtensionManager.java:303) [sfs2x.jar:?]
at com.smartfoxserver.v2.entities.managers.SFSZoneManager.createZone(SFSZoneManager.java:426) [sfs2x.jar:?]
at com.smartfoxserver.v2.entities.managers.SFSZoneManager.initializeZones(SFSZoneManager.java:239) [sfs2x.jar:?]
at com.smartfoxserver.v2.SmartFoxServer.start(SmartFoxServer.java:292) [sfs2x.jar:?]
at com.smartfoxserver.v2.Main.main(Main.java:14) [sfs2x.jar:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_102]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_102]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_102]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_102]
at com.exe4j.runtime.LauncherEngine.launch(Unknown Source) [i4jruntime.jar:?]
at com.install4j.runtime.launcher.Launcher.main(Unknown Source) [i4jruntime.jar:?]
Caused by: io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: /127.0.0.1:7004
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method) ~[?:1.8.0_102]
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717) ~[?:1.8.0_102]
at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:327) ~[netty-transport-4.1.33.Final.jar:4.1.33.Final]
at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:340) ~[netty-transport-4.1.33.Final.jar:4.1.33.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:665) ~[netty-transport-4.1.33.Final.jar:4.1.33.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:612) ~[netty-transport-4.1.33.Final.jar:4.1.33.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:529) ~[netty-transport-4.1.33.Final.jar:4.1.33.Final]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:491) ~[netty-transport-4.1.33.Final.jar:4.1.33.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:905) ~[netty-common-4.1.33.Final.jar:4.1.33.Final]
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.33.Final.jar:4.1.33.Final]
at java.lang.Thread.run(Thread.java:745) ~[?:1.8.0_102]
Caused by: java.net.ConnectException: Connection refused
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method) ~[?:1.8.0_102]
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717) ~[?:1.8.0_102]
at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:327) ~[netty-transport-4.1.33.Final.jar:4.1.33.Final]
at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:340) ~[netty-transport-4.1.33.Final.jar:4.1.33.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:665) ~[netty-transport-4.1.33.Final.jar:4.1.33.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:612) ~[netty-transport-4.1.33.Final.jar:4.1.33.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:529) ~[netty-transport-4.1.33.Final.jar:4.1.33.Final]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:491) ~[netty-transport-4.1.33.Final.jar:4.1.33.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:905) ~[netty-common-4.1.33.Final.jar:4.1.33.Final]
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.33.Final.jar:4.1.33.Final]
at java.lang.Thread.run(Thread.java:745) ~[?:1.8.0_102]
这是我的初始化连接代码:我尝试使用 RedisClusterClient 连接到 redis 服务器。IP 10.10.10.1 和端口是 7000
val redisUri = with(redisServiceInfo) {
RedisURI.builder()
.withHost(host)
.also { if (password != null) it.withPassword(password) }
.withPort(port)
.withTimeout(Duration.ofMillis(timeout))
.build()
}
val clusterClient = RedisClusterClient.create(redisUri)
val connection = clusterClient.connect()
this.connection = connection
this.clusterClient = clusterClient
然后我通过 RedisClusterCommands 做一个 scriptLoad
shaResult = redisService.sync().scriptLoad(script)
我的 Redis 服务器有 6 个节点:3 个主节点 3 个从节点,从 7000 -> 7002 的端口是主节点,从 7003 -> 7005 是从节点。错误总是发生在从节点上经过测试我发现连接是随机返回具有不同主机名的URI,有时它返回redis.domain.local有时它返回正确的 ip,有时它返回127.0.0.1
在连接到服务器后,我尝试将节点的 IP 替换为 10.10.10.1,并且功能运行良好。
建立连接时我错过了任何配置吗?
解决方案
推荐阅读
- solr - SOLR同时搜索多个动态字段_b布尔字段
- git - 如何在 bash 或 Jenkins 管道中安全地添加凭据来 git pull
- sql - 使用另一个表从一个表中选择内容
- python-3.x - 我从 python 2.7 迁移到 3.8.5,现在我的代码将无法运行。我正在显示 UnboundLocalError: local variable 'Url_name' referenced before assignment
- reactjs - Next.js 将 old-url 重定向到 new-url next.config 问题
- rust - 如何在 Gstreamer Rust 中将 udpsrc 链接到 rtpbin?
- html - SVG 无法正确放入角落
- java - 我列出从零到最大值的素数的功能给了我很多没有意义的额外内容
- linux - 如何提取 grep 命令中的第一列并传递给 linux cmd 中的下一个命令?
- python - 根据给定的数据框创建一个新的数据框