gpt4 book ai didi

java - Redis 生菜 : Sending Custom Commands

转载 作者:IT王子 更新时间:2023-10-29 06:03:49 26 4
gpt4 key购买 nike

我正在使用 tile38.comlettuce.io在Java上。我正在尝试根据文档 enter link description here 发送自定义 NEARBY fleet FENCE POINT 33.462 -112.268 6000 命令,但我不知道该怎么做。

我一直在 Lettuce 中使用 CommandType,但我找不到发送 NEARBY 的方法。有人知道我该怎么做吗?

谢谢

最佳答案

您有多个选项来发送自定义命令:

自定义命令

使用自定义命令,您基本上可以定义一个实现 ProtocolKeyword 的类型界面可帮助您作为命令中涉及的所有关键字的单一引用点。您可以使用同步、异步或响应式 API 来调用命令:

enum MyKeywords implements ProtocolKeyword {
NEARBY, FENCE, POINT;

private final byte name[];

MyKeywords() {
// cache the bytes for the command name. Reduces memory and cpu pressure when using commands.
name = name().getBytes();
}

@Override
public byte[] getBytes() {
return name;
}
}

CommandArgs<String, String> args = new CommandArgs<>(codec).addKey(key).add(MyKeywords.FENCE).add("POINT").add(lon).add(lat)
List<Object> response = connection.sync().dispatch(MyCommands.FENCE, new NestedMultiOutput<>(codec), args);

命令接口(interface)

命令接口(interface)通过在 Java 接口(interface)上声明命令方法为您提供更高级别的抽象。它由与您要调用的命令相匹配的方法签名声明,并且比自定义命令更简洁:

interface Tile38 {

@Command("NEARBY ?0 FENCE POINT ?1 ?2")
List<Object> nearByFence(String key, double lon, double lat);
}

RedisClient client = …
RedisCommandFactory factory = new RedisCommandFactory(client.connect());
Tile38 commands = factory.getCommands(Tile38.class);

请注意,我不熟悉 Tile38 命令响应。因此,所有代码都使用 List<Object>这是最通用的返回类型。

另见

关于java - Redis 生菜 : Sending Custom Commands,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48576291/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com