正在尝试通过Lettuce (Java)向Redis发送RedisTimeSeries命令。它适用于简单的命令,如TS.Create,但我不能让稍微复杂的命令工作(如TS.ADD,它接受键,分数,值作为参数)或TS.Range (它接受参数和返回列表)。
Redis运行在Linux上(Ubuntu运行在Windows10到WSL上),RedisTimeSeries安装在Redis上。Redis和RedisTimeSeries命令已经在linux上使用Redis-cli进行了测试,它们工作得很好。我使用VS Code + JDK 13.0 + Maven为Redis构建和测试Java客户端。到目前为止,Lettuce支持的Redis命令是通过客户端工作的,外加一些简单的RedisTimeSeries命令。
代码片段:
RedisCommands<String, String> syncCommands = MyRedisClient.getSyncCommands(connection);
// this works:
RedisCodec<String, String> codec = StringCodec.UTF8;
String result = syncCommands.dispatch(TS.CREATE, new StatusOutput<>(codec),new CommandArgs<>(codec).addKey("myTS"));
System.out.println("Custom Command TS.CREATE " + result);
//custom command definition:
public enum TS implements ProtocolKeyword{
CREATE;
public final byte[] bytes;
private TS() {
bytes = "TS.CREATE".getBytes(StandardCharsets.US_ASCII);
}
@Override
public byte[] getBytes() {
return bytes;
}
}但是当我切换所有东西来测试TS.ADD时,即使我相应地添加了额外的参数,它也不起作用。例如:
String result = syncCommands.dispatch(TS.ADD, new StatusOutput<>(codec),new CommandArgs<>(codec).addKey("myTS").addValue("1000001").addValue("2.199")); 下面是运行中的例外情况:
Exception in thread "main" io.lettuce.core.RedisException: java.lang.IllegalStateException
at io.lettuce.core.LettuceFutures.awaitOrCancel(LettuceFutures.java:129)
at io.lettuce.core.FutureSyncInvocationHandler.handleInvocation(FutureSyncInvocationHandler.java:69)
at io.lettuce.core.internal.AbstractInvocationHandler.invoke(AbstractInvocationHandler.java:80)
at com.sun.proxy.$Proxy0.dispatch(Unknown Source)
at MyRedisClient.main(MyRedisClient.java:72)发布于 2020-07-06 07:47:24
很抱歉这么晚才看到这个。如果您还没有找到解决方案,我最初使用动态命令实现了RediSearch命令。
public interface RediSearchCommands extends Commands {
@Command("FT.SUGADD ?0 ?1 ?2")
Long sugadd(String key, String string, double score);
...
}
public void testSuggestions() {
RedisCommandFactory factory = new RedisCommandFactory(client.connect());
RediSearchCommands commands = factory.getCommands(RediSearchCommands.class);
commands.sugadd(key, "Herbie Hancock", 1.0);
}完整来源:https://github.com/RediSearch/lettusearch/commit/567de42c147e0f07184df444cd1ae9798ae2514e
https://stackoverflow.com/questions/58686517
复制相似问题