Gremlin.NET 是否支持提交异步字节码?
Does Gremlin.NET support submitting async bytecode?
有submitting queries asynchronously in Gremlin.Net, some get string
which is not recommended and others use RequestMessage
which is not as readable as using GraphTraversal
个函数的扩展函数。
有没有一种方法可以异步提交如下所示的查询,而无需提交字符串或 RequestMessage
?
var res = _graphTraversalSource.V().Has("name", "Armin").Out().Values<string>("name").ToList();
更多上下文
我正在编写一个查询 AWS Neptune 的 API。这是我在单例服务的构造函数中获取 GraphTraversalSource
的方法(不确定我是否应该将 RemoteConnection
设为单例并为每个查询生成一个 GraphTraversalSource
或者这是正确的方法) :
private readonly GraphTraversalSource _graphTraversalSource;
public NeptuneHandler(string endpoint, int port)
{
var gremlinClient = new GremlinClient(new GremlinServer(endpoint, port));
var remoteConnection = new DriverRemoteConnection(gremlinClient);
_graphTraversalSource = AnonymousTraversalSource.Traversal().WithRemote(remoteConnection);
}
您可以使用 Promise()
终止步骤异步执行遍历
var names = await g.V().Has("name", "Armin").Out().Values<string>("name").Promise(t => t.ToList());
Promise()
将回调作为其参数,调用您希望为遍历执行的通常终止步骤,在您的情况下为 ToList
。但是,如果您只想返回一个结果,则只需将 ToList()
替换为 Next()
.
请注意,我将图形遍历源的变量重命名为 g
,因为这是 Gremlin 的常用命名约定。
正如我在评论中提到的,建议在您的应用程序中重复使用此图形遍历源 g
,因为它可以包含适用于您要执行的所有遍历的配置。它还包含 DriverRemoteConnection
,它使用连接池与服务器进行通信。通过重用 g
,您还可以为应用程序中的所有遍历使用相同的连接池。
有submitting queries asynchronously in Gremlin.Net, some get string
which is not recommended and others use RequestMessage
which is not as readable as using GraphTraversal
个函数的扩展函数。
有没有一种方法可以异步提交如下所示的查询,而无需提交字符串或 RequestMessage
?
var res = _graphTraversalSource.V().Has("name", "Armin").Out().Values<string>("name").ToList();
更多上下文
我正在编写一个查询 AWS Neptune 的 API。这是我在单例服务的构造函数中获取 GraphTraversalSource
的方法(不确定我是否应该将 RemoteConnection
设为单例并为每个查询生成一个 GraphTraversalSource
或者这是正确的方法) :
private readonly GraphTraversalSource _graphTraversalSource;
public NeptuneHandler(string endpoint, int port)
{
var gremlinClient = new GremlinClient(new GremlinServer(endpoint, port));
var remoteConnection = new DriverRemoteConnection(gremlinClient);
_graphTraversalSource = AnonymousTraversalSource.Traversal().WithRemote(remoteConnection);
}
您可以使用 Promise()
终止步骤异步执行遍历
var names = await g.V().Has("name", "Armin").Out().Values<string>("name").Promise(t => t.ToList());
Promise()
将回调作为其参数,调用您希望为遍历执行的通常终止步骤,在您的情况下为 ToList
。但是,如果您只想返回一个结果,则只需将 ToList()
替换为 Next()
.
请注意,我将图形遍历源的变量重命名为 g
,因为这是 Gremlin 的常用命名约定。
正如我在评论中提到的,建议在您的应用程序中重复使用此图形遍历源 g
,因为它可以包含适用于您要执行的所有遍历的配置。它还包含 DriverRemoteConnection
,它使用连接池与服务器进行通信。通过重用 g
,您还可以为应用程序中的所有遍历使用相同的连接池。