我们的YAML文件已经就绪了,我们要建立小精灵控制台和服务器之间的连接, 我们需要做的全部事情就是控制台运行后,执行下面的命令。
Now that we have our YAML file ready, all that we have to do to establish a connection between our
Gremlin Console and the Gremlin Server is to issue the following command once the console is
running.
我们已经连接到了服务器,可以发出一些小精灵命令。既然航线图已经加载到了我们的远程图数据库中, 我们可以立即开始执行一些查询。为了让查询去到远端的图,查询语句需要以:>做为前缀。
Now that we are connected to the Gremlin Server we can issue some Gremlin commands. Given
that the air-routes graph is already loaded into our remote graph we can immediately start to issue
some queries. In order to make sure the query goes to the remote graph, the query needs to be
prefixed with ":>".
7.2.2. 小精灵控制台的结果变量 The Gremlin Console’s result variable
在小精灵控制台工作时,另一件有用的事就是注意发送到服务器的查询的结果, 当控制台在本地模式时,和显示的一样,存储在一个变量中的被称为结果。看一下下面的查询。
When working within the Gremlin console, one other useful thing to be aware of is that the results
of queries sent to a server, when the console is in "local mode", as well as being displayed are stored
in a variable called result. Take a look at the query below.
如果我们要打印结果变量, 我们可以发现它包含了来自查询的结果
If we were to print the contents of the result variable we would find it contains the results from the
query.
控制台还是在本地模式,我们可以使用一些Groovy代码来进行后处理。在这个例子中是美化打印结果的内容。这一功能值得记住。有一些有趣的事,当进行远程服务器工作时,它允许您这样做,例如将后处理的结果保存在一个本地文件。
As the console is still in local mode we can use some inline Groovy code to post process, in this case
pretty print, the contents of result. This capability is worth keeping in mind. There are some
interesting things it allows you to do such as easily post processing results and saving them to a file
locally when working with a remote server.
7.2.3. 工作在远程模式 Working in remote mode
和保持控制台在本地一样,如果您要在远程的图中进行大量的查询,笔者发现把控制台放在远程模式更方便,这也相当有用。为些可以像下面这么做。
As useful as keeping the console in "local mode" can be, if you are going to be issuing a lot of queries
to the remote graph, I find it more convenient to put the console into "remote mode". This can be
done as follows.
控制台现在是在远程模式。所有的您输入的查询都将发送到了小精灵服务器,也不需要使用:>前缀了。
The console is now in "remote mode". All queries that you enter will be sent to the Gremlin Server
and there is no need to use the ":>" prefix.
有一件事要注意:来自服务器的输出有点与您使用带着本地廷克图的控制台执行命令得到的结果看起来不一样。这是因为控制台实质上在显示给用户前是对于输出执行了toString()方法。
One thing to notice is that the output that comes back from a Gremlin Server looks a little different
at times from when you use the commands using the Gremlin Console attached to a local
TinkerGraph. This is because Gremlin Console essentially does a toString() on the output before it is
shown to the user in these cases.
做为一个输出格式有点不同的例子,下面您会发现同一个查询,当您运行在本地,内存,廷克图的结果。
As an example of the slight differences in the output format, below you will find the results from
the same query when the graph was running as a local, in memory, TinkerGraph.
您完成了向服务器发送所有命令的操作,您就可以切换模式,如下所示。命令现在发送到您的本地控制台。这就意味着您可以同时工作在本地和远程。这个:remote console命令是一个切换键。每次您使用这个命令,控制台就会进行本地模式,远程模式的切换,以此类推。
Once you are done sending all commands to the Gremlin Server you can switch out of that mode as
follows. Commands will now be sent to your local console. This means that you can work with a
local and remote graph at the same time. The :remote console command is therefore a toggle. Each
time you use the command the console will switch between local mode and remote mode or vice
versa.
如果您完成了这个控制台会话的远程连接,您就可以像下面这样关闭它。关闭后,如果想让:remote console命令再次生效,您需要重新建立连接。
If you are completely done with the remote connection for this console session you can truly close it
as follows. Having done this you will need to reestablish the connection before the :remote console
will work again.
浙公网安备 33010602011771号