-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Redis Stream command support
- Loading branch information
1 parent
89900ec
commit e620378
Showing
34 changed files
with
5,355 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
extensions/redis-client/runtime/src/etc/RedisCommandGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
///usr/bin/env jbang "$0" "$@" ; exit $? | ||
//DEPS io.smallrye.reactive:smallrye-mutiny-vertx-redis-client:2.24.1 | ||
//DEPS info.picocli:picocli:4.6.3 | ||
//DEPS org.slf4j:slf4j-simple:1.7.36 | ||
|
||
import static java.lang.System.*; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.Callable; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import io.vertx.mutiny.core.Vertx; | ||
import io.vertx.mutiny.redis.client.Redis; | ||
import io.vertx.mutiny.redis.client.RedisAPI; | ||
import io.vertx.mutiny.redis.client.Response; | ||
import io.vertx.redis.client.RedisOptions; | ||
import picocli.CommandLine; | ||
import picocli.CommandLine.Command; | ||
import picocli.CommandLine.Option; | ||
|
||
|
||
@Command(name = "RedisCommandGenerator", mixinStandardHelpOptions = true, version = "RedisCommandGenerator 0.1", description = "Generate REdis Command Javadoc and signatures") | ||
public class RedisCommandGenerator implements Callable<Integer> { | ||
|
||
static Logger logger = LoggerFactory.getLogger("👻 >> "); | ||
|
||
|
||
@Option(names = {"--redis"}, | ||
description = "Redis connection string (redis://localhost:6379). Start Redis with: `docker run -p 6379:6379 redis:latest`", | ||
defaultValue = "redis://localhost:6379") | ||
private String url; | ||
|
||
@Option(names = "--command", description = "The command name from https://redis.io/commands/", required = true) | ||
private String command; | ||
|
||
public Integer call() { | ||
logger.info("Connecting to Redis"); | ||
|
||
Vertx vertx = Vertx.vertx(); | ||
Redis client = Redis.createClient(vertx, new RedisOptions().setConnectionString(url)); | ||
RedisAPI api = RedisAPI.api(client); | ||
|
||
Response response = api.commandAndAwait(List.of("DOCS", command.toLowerCase())); | ||
System.out.println(javadoc(command, response.get(command))); | ||
|
||
vertx.closeAndAwait(); | ||
return 0; | ||
} | ||
|
||
private String javadoc(String cmd, Response response) { | ||
String content = "/**\n"; | ||
content += String.format(" * Execute the command <a href=\"https://redis.io/commands/%s\">$s</a>.\n", cmd.toLowerCase(), cmd.toUpperCase()); | ||
content += String.format(" * Summary: %s\n", response.get("summary").toString()); | ||
content += String.format(" * Group: %s\n", response.get("group").toString()); | ||
if (response.get("since") != null) { | ||
content += String.format(" * Requires Redis %s+\n", response.get("since").toString()); | ||
} | ||
boolean deprecated = false; | ||
if (response.get("deprecated_since") != null) { | ||
content += String.format(" * Deprecated since Redis %s\n", response.get("deprecated_since").toString()); | ||
deprecated = true; | ||
} | ||
content += " * <p>\n"; | ||
for (Response arg: response.get("arguments")) { | ||
content += String.format(" * @param %s %s\n", arg.get("name").toString(), arg.get("type")); | ||
} | ||
content += " * @return TODO\n"; | ||
if (deprecated) { | ||
content += " * @deprecated"; | ||
} | ||
content += " */\n"; | ||
return content; | ||
} | ||
|
||
public static void main(String... args) { | ||
int exitCode = new CommandLine(new RedisCommandGenerator()).execute(args); | ||
System.exit(exitCode); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...edis-client/runtime/src/main/java/io/quarkus/redis/datasource/stream/ClaimedMessages.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package io.quarkus.redis.datasource.stream; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Represents claimed messages | ||
* | ||
* @param <K> the type of the key | ||
* @param <F> the field type for the payload | ||
* @param <V> the value type for the payload | ||
*/ | ||
public class ClaimedMessages<K, F, V> { | ||
private final String id; | ||
private final List<StreamMessage<K, F, V>> messages; | ||
|
||
public ClaimedMessages(String id, List<StreamMessage<K, F, V>> messages) { | ||
this.id = id; | ||
this.messages = messages; | ||
} | ||
|
||
public String getId() { | ||
return this.id; | ||
} | ||
|
||
public List<StreamMessage<K, F, V>> getMessages() { | ||
return this.messages; | ||
} | ||
} |
Oops, something went wrong.