Ross
Ross

Reputation: 877

ruby neo4j session persistence

I'm using neo4j in a Ruby CLI app.

Each time a command is run from the command line, "session = Neo4j::Session.open(:server_db)" is re-established which is quite slow.

Is there anyway to persist the "session" first time use and re-use it in subsequent command invocations from the command line.

Regards

Upvotes: 1

Views: 53

Answers (1)

Brian Underwood
Brian Underwood

Reputation: 10856

The neo4j-core gem uses the faraday gem to make persistent HTTP connections. That's defined here:

https://github.com/neo4jrb/neo4j-core/blob/master/lib/neo4j-server/cypher_session.rb#L24

That uses the NetHttpPersistent Faraday adapter here:

https://github.com/lostisland/faraday/blob/master/lib/faraday/adapter/net_http_persistent.rb

Which I believe uses the net-http-persistent library: https://github.com/drbrain/net-http-persistent

When calling open on Session, you can pass in a second argument Hash of options. You can specify a connection key in that hash which is a Faraday connection object which you've created. That might allow you to save some token/string somewhere and the reload the Faraday object each time from that to pick up the session from where it left off.

The other option is to have a daemon in the background which has the connection open

Upvotes: 1

Related Questions