如何使用Gremlin控制台远程创建和访问变量?

18

我使用 Gremlin Console(即 JanusGraph)远程连接到一个 Gremlin 服务器,但是当我创建一个变量并访问它时,它不起作用。 我的最终目标是使用 Gremlin Console 创建索引...

gremlin> :remote connect tinkerpop.server conf/remote.yaml
==>Configured localhost/127.0.0.1:8182
gremlin> :remote console
==>All scripts will now be sent to Gremlin Server - 
[localhost/127.0.0.1:8182] - type ':remote console' to return to local mode
gremlin> a = "b"
==>b
gremlin> a
No such property: a for class: Script3
Type ':help' or ':h' for help.
2个回答

23

由于控制台默认是无状态的,所以不能在后续请求中像这样使用变量。因此,每个请求都在其自己的事务中执行,两个不同请求之间没有共享状态。

但是,您可以通过将session关键字附加到connect参数来配置控制台使用会话

gremlin> :remote connect tinkerpop.server conf/remote.yaml session
==>Configured localhost/127.0.0.1:8182-[15dc7030-0e5b-4b4b-a997-9d2cf519ebb2]
gremlin> :> x = 1
==>1
gremlin> :> y = 2
==>2
gremlin> :> x + y
==>3

我从TinkerPop文档中复制了这个例子。


3

下载janusdb并通过运行以下命令启动gremlin控制台:

/bin/gremlin.sh

使用以下命令构建janus图:

gremlin> graph = JanusGraphFactory.open('conf/janusgraph-cassandra-solr.properties')

通过运行以下命令获取您的图遍历源:

gremlin> g = graph.traversal()

现在,您可以直接连接到具有完全控制权的数据库。您可以存储返回值并在下一个查询中使用它。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接