Skip to content

Commit

Permalink
feat(cmd): Add get commands
Browse files Browse the repository at this point in the history
  • Loading branch information
CarmJos committed Jan 22, 2024
1 parent 548bb84 commit e29317a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cc.carm.plugin.mineredis;

import cc.carm.plugin.mineredis.api.RedisManager;
import cc.carm.plugin.mineredis.api.callback.RedisCallbackBuilder;
import cc.carm.plugin.mineredis.api.message.RedisMessage;
import cc.carm.plugin.mineredis.api.message.RedisMessageListener;
import cc.carm.plugin.mineredis.handler.RedisByteCodec;
Expand Down Expand Up @@ -68,7 +69,7 @@ public void handleMessage(String pattern, String channel, String source, long ti
.forEach(listeners::add);
}

listeners.forEach(listener -> listener.handle(new RedisMessage(channel, source, timestamp, ByteStreams.newDataInput(data))));
listeners.forEach(listener -> listener.handle(new RedisMessage(channel, source, timestamp, data)));
}

@Override
Expand Down Expand Up @@ -137,6 +138,19 @@ public RedisFuture<Long> publishAsync(@NotNull String channel, @NotNull Consumer
return publishAsync(channel, stream);
}

@Override
public RedisCallbackBuilder callback(@NotNull String channel, @NotNull ByteArrayDataOutput byteOutput) {
return new RedisCallbackBuilder(this, channel, byteOutput);
}

@SuppressWarnings("UnstableApiUsage")
@Override
public RedisCallbackBuilder callback(@NotNull String channel, @NotNull Consumer<ByteArrayDataOutput> byteOutput) {
ByteArrayDataOutput stream = ByteStreams.newDataOutput();
byteOutput.accept(stream);
return callback(channel, stream);
}

@SuppressWarnings("UnstableApiUsage")
protected byte[] writeMessages(@NotNull ByteArrayDataOutput byteOutput) {
ByteArrayDataOutput stream = ByteStreams.newDataOutput();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,22 @@ public void version(CommandIssuer issuer) {
core.checkUpdate(pluginVersion);
}

@Subcommand("get")
@Syntax("<key>")
@Description("获取指定键的值。")
public void get(CommandIssuer issuer, String key) {
if (issuer.isPlayer()) {
issuer.sendMessage("§c只有后台执行才能使用此命令。");
return;
}
issuer.sendMessage("§r正在获取键 §d" + key + "§r 的值...");
core.getManager().async().get(key).thenAccept(value -> {
if (value == null) {
issuer.sendMessage("§r键 §d" + key + "§r 不存在。");
} else {
issuer.sendMessage("§r键 §d" + key + "§r 的值为 §d" + value + "§r。");
}
});
}

}

0 comments on commit e29317a

Please sign in to comment.