Skip to content

Rexster Console

spmallette edited this page Jul 23, 2011 · 24 revisions

Rexster Console is a REPL similar to the REPL available from Gremlin. It differs in several ways:

  • Script evaluation within Rexster Console occurs remotely on a Rexster server.
  • Rexster Console communicates with any JSR223 compliant ScriptEngine hosted within the Rexster server. The variable pool is shared across each engine. In this way, its possible to make use of each language’s unique expressive qualities when manipulating variables.
  • Rexster Console provides access to configured graphs within Rexster server through the rexster variable that is injected into the variable pool on the server.

Getting Started

To start the console, first ensure that the Rexster server is running. Then start the console from the command line:

rexster-console.sh
        (l_(l
(_______( 0 0
(        (-Y-) <woof>
l l-----l l
l l,,   l l,,
opening session with Rexster [localhost:8185]--> ready
?h for help

rexster[gremlin]> 

Note the language name in square brackets. This represents the script engine language that the line will be evaluated with on the server. It’s easy to see what languages are available on the server:

rexster[gremlin]> ?l
-= Available Languages =-
?ECMAScript
?gremlin
?Groovy

To change languages simply type one of those languages (case sensitive) into the command-line:

rexster[gremlin]> ?Groovy
rexster[Groovy]> 

Variables are shared across script engines within a Rexster Console session.

rexster[gremlin]> x = 1 + 1
==>2
rexster[gremlin]> ?Groovy
rexster[Groovy]> x = x + 1
==>3
rexster[Groovy]> ?ECMAScript
rexster[ECMAScript]> y = x + 1 
==>4.0
rexster[ECMAScript]> ?gremlin
rexster[gremlin]> x + y
==>7.0

Getting access to graphs configured within Rexster is allowed through the rexster variable which is a context object on the server.

rexster[gremlin]> g = rexster.getGraph("tinkergraph")
==>tinkergraph[vertices:6 edges:6]
rexster[gremlin]> g.v(1).name
==>marko

Command Line

The Rexster Console requires three parameters for startup: host, port and start language. By default these are set as follows:

rexster-console.sh localhost 8185 gremlin

Port 8185 is the default RexPro port as defined in rexster.xml. Please see the Rexster Configuration section for more information on this setting.

Console Commands

From within the console, there are a number of actions that can be executed from the command line. Each command is prefixed with a question mark:

returns description
?{language-name} Change the language of the script engine. The language parameter is case sensitive and must be an available script engine on the server.
?l List the languages installed on Rexster.
?q Close the session and exit the command line.
?h Display help.

Rexster Context

When establishing a session with Rexster, the rexster context variable is injected into the variable pool that is shared with all the script engines. The rexster variable provides access to server-side resources such as the graphs configured within Rexster. The following operations are available from the rexster within script evaluations:

function description
getGraph(graphName) Gets a configured graph instance within Rexster. The graphName specified is a String value that is case sensitive and matches the name of a configured graph.
getGraphNames() Gets the list of configured graph instance names on the server.
getVersion() Gets the version of Rexster on the server.

rexster[gremlin]> graphNames = rexster.graphNames.toArray()
==>tinkergraph
==>gratefulgraph
==>tinkergraph-readonly
==>emptygraph
rexster[gremlin]> g = rexster.getGraph(graphNames[0])
==>tinkergraph[vertices:6 edges:6]
Clone this wiki locally