-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28623 from cescoffier/redis-graph
Implement the Redis Graph commands
- Loading branch information
Showing
22 changed files
with
1,377 additions
and
4 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
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
90 changes: 90 additions & 0 deletions
90
...s/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/graph/GraphCommands.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,90 @@ | ||
package io.quarkus.redis.datasource.graph; | ||
|
||
import java.time.Duration; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import io.quarkus.redis.datasource.RedisCommands; | ||
import io.smallrye.common.annotation.Experimental; | ||
|
||
/** | ||
* Allows executing commands from the {@code graph} group. | ||
* These commands require the <a href="https://redis.io/docs/stack/graph/">Redis Graph</a> module to be installed in the | ||
* Redis server. | ||
* <p> | ||
* See <a href="https://redis.io/commands/?group=graph">the graph command list</a> for further information about | ||
* these commands. | ||
* <p> | ||
* | ||
* @param <K> the type of the key | ||
*/ | ||
@Experimental("The Redis graph support is experimental") | ||
public interface GraphCommands<K> extends RedisCommands { | ||
|
||
/** | ||
* Execute the command <a href="https://redis.io/commands/graph.delete">GRAPH.DELETE</a>. | ||
* Summary: Completely removes the graph and all of its entities. | ||
* Group: graph | ||
* | ||
* @param key the key, must not be {@code null} | ||
*/ | ||
void graphDelete(K key); | ||
|
||
/** | ||
* Execute the command <a href="https://redis.io/commands/graph.delete">GRAPH.EXPLAIN</a>. | ||
* Summary: Constructs a query execution plan but does not run it. Inspect this execution plan to better understand | ||
* how your query will get executed. | ||
* Group: graph | ||
* <p> | ||
* | ||
* @param key the key, must not be {@code null} | ||
* @param query the query, must not be {@code null} | ||
* @return the string representation of the query execution plan | ||
*/ | ||
String graphExplain(K key, String query); | ||
|
||
/** | ||
* Execute the command <a href="https://redis.io/commands/graph.list">GRAPH.LIST</a>. | ||
* Summary: Lists all graph keys in the keyspace. | ||
* Group: graph | ||
* <p> | ||
* | ||
* @return the list of list of keys storing graphs | ||
*/ | ||
List<K> graphList(); | ||
|
||
/** | ||
* Execute the command <a href="https://redis.io/commands/graph.delete">GRAPH.QUERY</a>. | ||
* Summary: Executes the given query against a specified graph. | ||
* Group: graph | ||
* <p> | ||
* | ||
* @param key the key, must not be {@code null} | ||
* @param query the query, must not be {@code null} | ||
* @return a map, potentially empty, containing the requested items to return. The map is empty if | ||
* the query does not have a {@code return} clause. For each request item, a {@link GraphQueryResponseItem} is | ||
* returned. It can represent a scalar item | ||
* ({@link io.quarkus.redis.datasource.graph.GraphQueryResponseItem.ScalarItem}), | ||
* a node ({@link io.quarkus.redis.datasource.graph.GraphQueryResponseItem.NodeItem}, or a relation | ||
* ({@link io.quarkus.redis.datasource.graph.GraphQueryResponseItem.RelationItem}). | ||
*/ | ||
List<Map<String, GraphQueryResponseItem>> graphQuery(K key, String query); | ||
|
||
/** | ||
* Execute the command <a href="https://redis.io/commands/graph.delete">GRAPH.QUERY</a>. | ||
* Summary: Executes the given query against a specified graph. | ||
* Group: graph | ||
* <p> | ||
* | ||
* @param key the key, must not be {@code null} | ||
* @param query the query, must not be {@code null} | ||
* @param timeout a timeout, must not be {@code null} | ||
* @return a map, potentially empty, containing the requested items to return. The map is empty if | ||
* the query does not have a {@code return} clause. For each request item, a {@link GraphQueryResponseItem} is | ||
* returned. It can represent a scalar item | ||
* ({@link io.quarkus.redis.datasource.graph.GraphQueryResponseItem.ScalarItem}), | ||
* a node ({@link io.quarkus.redis.datasource.graph.GraphQueryResponseItem.NodeItem}, or a relation | ||
* ({@link io.quarkus.redis.datasource.graph.GraphQueryResponseItem.RelationItem}). | ||
*/ | ||
List<Map<String, GraphQueryResponseItem>> graphQuery(K key, String query, Duration timeout); | ||
} |
90 changes: 90 additions & 0 deletions
90
...lient/runtime/src/main/java/io/quarkus/redis/datasource/graph/GraphQueryResponseItem.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,90 @@ | ||
package io.quarkus.redis.datasource.graph; | ||
|
||
import java.util.List; | ||
|
||
public interface GraphQueryResponseItem { | ||
|
||
enum Kind { | ||
SCALAR, | ||
NODE, | ||
RELATION | ||
} | ||
|
||
Kind kind(); | ||
|
||
String name(); | ||
|
||
default ScalarItem asScalarItem() { | ||
if (this instanceof ScalarItem) { | ||
return (ScalarItem) this; | ||
} | ||
throw new ClassCastException("Cannot cast " + this + " of kind " + kind() + " to a " + ScalarItem.class.getName()); | ||
} | ||
|
||
default NodeItem asNodeItem() { | ||
if (this instanceof NodeItem) { | ||
return (NodeItem) this; | ||
} | ||
throw new ClassCastException("Cannot cast " + this + " of kind " + kind() + " to a " + NodeItem.class.getName()); | ||
} | ||
|
||
default RelationItem asRelationItem() { | ||
if (this instanceof RelationItem) { | ||
return (RelationItem) this; | ||
} | ||
throw new ClassCastException("Cannot cast " + this + " of kind " + kind() + " to a " + RelationItem.class.getName()); | ||
} | ||
|
||
interface ScalarItem extends GraphQueryResponseItem { | ||
|
||
boolean asBoolean(); | ||
|
||
int asInteger(); | ||
|
||
double asDouble(); | ||
|
||
boolean isNull(); | ||
|
||
String asString(); | ||
|
||
@Override | ||
default Kind kind() { | ||
return Kind.SCALAR; | ||
} | ||
} | ||
|
||
interface NodeItem extends GraphQueryResponseItem { | ||
long id(); | ||
|
||
List<String> labels(); | ||
|
||
List<ScalarItem> properties(); | ||
|
||
ScalarItem get(String property); | ||
|
||
@Override | ||
default Kind kind() { | ||
return Kind.NODE; | ||
} | ||
} | ||
|
||
interface RelationItem extends GraphQueryResponseItem { | ||
long id(); | ||
|
||
String type(); | ||
|
||
long source(); | ||
|
||
long destination(); | ||
|
||
List<ScalarItem> properties(); | ||
|
||
ScalarItem get(String property); | ||
|
||
@Override | ||
default Kind kind() { | ||
return Kind.RELATION; | ||
} | ||
} | ||
|
||
} |
91 changes: 91 additions & 0 deletions
91
...client/runtime/src/main/java/io/quarkus/redis/datasource/graph/ReactiveGraphCommands.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,91 @@ | ||
package io.quarkus.redis.datasource.graph; | ||
|
||
import java.time.Duration; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import io.quarkus.redis.datasource.ReactiveRedisCommands; | ||
import io.smallrye.mutiny.Uni; | ||
|
||
/** | ||
* Allows executing commands from the {@code graph} group. | ||
* These commands require the <a href="https://redis.io/docs/stack/graph/">Redis Graph</a> module to be installed in the | ||
* Redis server. | ||
* <p> | ||
* See <a href="https://redis.io/commands/?group=graph">the graph command list</a> for further information about | ||
* these commands. | ||
* <p> | ||
* | ||
* @param <K> the type of the key | ||
*/ | ||
public interface ReactiveGraphCommands<K> extends ReactiveRedisCommands { | ||
|
||
/** | ||
* Execute the command <a href="https://redis.io/commands/graph.delete">GRAPH.DELETE</a>. | ||
* Summary: Completely removes the graph and all of its entities. | ||
* Group: graph | ||
* | ||
* @param key the key, must not be {@code null} | ||
* @return a uni producing {@code null} when the operation completes | ||
**/ | ||
Uni<Void> graphDelete(K key); | ||
|
||
/** | ||
* Execute the command <a href="https://redis.io/commands/graph.delete">GRAPH.EXPLAIN</a>. | ||
* Summary: Constructs a query execution plan but does not run it. Inspect this execution plan to better understand | ||
* how your query will get executed. | ||
* Group: graph | ||
* <p> | ||
* | ||
* @param key the key, must not be {@code null} | ||
* @param query the query, must not be {@code null} | ||
* @return a uni producing the string representation of the query execution plan | ||
*/ | ||
Uni<String> graphExplain(K key, String query); | ||
|
||
/** | ||
* Execute the command <a href="https://redis.io/commands/graph.list">GRAPH.LIST</a>. | ||
* Summary: Lists all graph keys in the keyspace. | ||
* Group: graph | ||
* <p> | ||
* | ||
* @return a uni producing the list of list of keys storing graphs | ||
*/ | ||
Uni<List<K>> graphList(); | ||
|
||
/** | ||
* Execute the command <a href="https://redis.io/commands/graph.delete">GRAPH.QUERY</a>. | ||
* Summary: Executes the given query against a specified graph. | ||
* Group: graph | ||
* <p> | ||
* | ||
* @param key the key, must not be {@code null} | ||
* @param query the query, must not be {@code null} | ||
* @return a map, potentially empty, containing the requested items to return. The map is empty if | ||
* the query does not have a {@code return} clause. For each request item, a {@link GraphQueryResponseItem} is | ||
* returned. It can represent a scalar item | ||
* ({@link io.quarkus.redis.datasource.graph.GraphQueryResponseItem.ScalarItem}), | ||
* a node ({@link io.quarkus.redis.datasource.graph.GraphQueryResponseItem.NodeItem}, or a relation | ||
* ({@link io.quarkus.redis.datasource.graph.GraphQueryResponseItem.RelationItem}). | ||
*/ | ||
Uni<List<Map<String, GraphQueryResponseItem>>> graphQuery(K key, String query); | ||
|
||
/** | ||
* Execute the command <a href="https://redis.io/commands/graph.delete">GRAPH.QUERY</a>. | ||
* Summary: Executes the given query against a specified graph. | ||
* Group: graph | ||
* <p> | ||
* | ||
* @param key the key, must not be {@code null} | ||
* @param query the query, must not be {@code null} | ||
* @param timeout a timeout, must not be {@code null} | ||
* @return a map, potentially empty, containing the requested items to return. The map is empty if | ||
* the query does not have a {@code return} clause. For each request item, a {@link GraphQueryResponseItem} is | ||
* returned. It can represent a scalar item | ||
* ({@link io.quarkus.redis.datasource.graph.GraphQueryResponseItem.ScalarItem}), | ||
* a node ({@link io.quarkus.redis.datasource.graph.GraphQueryResponseItem.NodeItem}, or a relation | ||
* ({@link io.quarkus.redis.datasource.graph.GraphQueryResponseItem.RelationItem}). | ||
*/ | ||
Uni<List<Map<String, GraphQueryResponseItem>>> graphQuery(K key, String query, Duration timeout); | ||
|
||
} |
Oops, something went wrong.