RediSearchAsyncCommands 在执行搜索命令时抱怨“java.lang.UnsupportedOperationException”

问题描述 投票:0回答:1

我在redis上采用spring-redisearch作为搜索框架,当我进行搜索时,它抛出以下异常,有问题的AbstractMap是Collections$.EmptyMap

java.lang.UnsupportedOperationException
    at java.base/java.util.AbstractMap.put(AbstractMap.java:209)
    at io.lettuce.core.output.MapOutput.set(MapOutput.java:56)
    at com.redislabs.lettusearch.output.SearchOutput.set(SearchOutput.java:60)
    at io.lettuce.core.protocol.RedisStateMachine.safeSetSingle(RedisStateMachine.java:826)
    at io.lettuce.core.protocol.RedisStateMachine.handleSingle(RedisStateMachine.java:358)
    at io.lettuce.core.protocol.RedisStateMachine$State$Type.handle(RedisStateMachine.java:206)
    at io.lettuce.core.protocol.RedisStateMachine.doDecode(RedisStateMachine.java:334)
    at io.lettuce.core.protocol.RedisStateMachine.decode(RedisStateMachine.java:295)
    at io.lettuce.core.protocol.CommandHandler.decode(CommandHandler.java:841)
    at io.lettuce.core.protocol.CommandHandler.decode0(CommandHandler.java:792)
    at io.lettuce.core.protocol.CommandHandler.decode(CommandHandler.java:775)
    at io.lettuce.core.protocol.CommandHandler.decode(CommandHandler.java:658)
    at io.lettuce.core.protocol.CommandHandler.channelRead(CommandHandler.java:598)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
    at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
    at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:788)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562)
    at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
    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:833)

以下是代码片段,在调试过程中,我可以看到搜索结果驻留在RedisFuture中,但是在调用get()时抛出上述异常。

RediSearchAsyncCommands<String, String> command= rediSearchConnection.async();
Object result = command.search("index:name", "@name:searchTerm", options).get();
if (result instanceof SearchResults) {
    SearchResults<String, String> searchResults = (SearchResults<String, String>) result;
    for (int i = 0; i < searchResults.getCount(); i++) {
        Document<String, String> document = searchResults.get(i);
        logger.info(document.get("primaryKey"));
    }
}

Pom.xml

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-redis</artifactId>
    <version>3.2.1</version>
</dependency>
<dependency>
    <groupId>com.redislabs</groupId>
    <artifactId>spring-redisearch</artifactId>
    <version>3.1.2</version>
</dependency>
<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-pool2</artifactId>
    <version>2.12.0</version>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
</dependency>

我尝试以同步方式做到这一点,尝试了不同版本的 spring-boot 和 spring-redisearch,但仍然不起作用,我不知道发生了什么,有什么建议吗?谢谢。

redis redisearch redislabs
1个回答
0
投票

自己回答一下,我的 sping-redisearch 版本与 redis-stack 版本不兼容,redisearch 状态机无法正常工作并调用了错误的方法。改为6.2.6作品

© www.soinside.com 2019 - 2024. All rights reserved.