class Redgraph::Graph
Attributes
connection[RW]
graph_name[RW]
Public Class Methods
new(graph_name, redis_options = {})
click to toggle source
@example Graph.new
(“foobar”, url: “redis://localhost:6379/0”, logger: Logger.new(STDOUT)) @param graph_name
[String] Name of the graph @param redis_options [Hash] Redis client options
# File lib/redgraph/graph.rb, line 18 def initialize(graph_name, redis_options = {}) @graph_name = graph_name @connection = Redis.new(redis_options) @module_version = module_version raise ServerError unless @module_version end
Public Instance Methods
delete()
click to toggle source
Deletes an existing graph
# File lib/redgraph/graph.rb, line 35 def delete @connection.call("GRAPH.DELETE", graph_name) rescue Redis::CommandError => e # Catch exception if the graph was already deleted return nil if e.message =~ /ERR Invalid graph operation on empty key/ raise e end
get_label(id)
click to toggle source
@param id [Integer] label id @return [String, nil] label
# File lib/redgraph/graph.rb, line 78 def get_label(id) @labels ||= labels @labels[id] || (@labels = labels)[id] end
get_property(id)
click to toggle source
@param id [Integer] property id @return [String, nil] property
# File lib/redgraph/graph.rb, line 86 def get_property(id) @properties ||= properties @properties[id] || (@properties = properties)[id] end
get_relationship_type(id)
click to toggle source
@param id [Integer] relationship type id @return [String, nil] relationship type
# File lib/redgraph/graph.rb, line 94 def get_relationship_type(id) @relationship_types ||= relationship_types @relationship_types[id] || (@relationship_types = relationship_types)[id] end
labels()
click to toggle source
@return [Array] Existing labels
# File lib/redgraph/graph.rb, line 51 def labels result = _query("CALL db.labels()") result.resultset.map(&:values).flatten end
list()
click to toggle source
@return [Array] Existing graph names
# File lib/redgraph/graph.rb, line 45 def list @connection.call("GRAPH.LIST") end
module_version()
click to toggle source
Returns the version of the RedisGraph module
# File lib/redgraph/graph.rb, line 27 def module_version modules = @connection.call("MODULE", "LIST") module_graph = modules.detect { |_, name, _, version| name == 'graph' } module_graph[3] if module_graph end
properties()
click to toggle source
@return [Array] Existing properties
# File lib/redgraph/graph.rb, line 58 def properties result = _query("CALL db.propertyKeys()") result.resultset.map(&:values).flatten end
query(cmd)
click to toggle source
You can run custom cypher queries
# File lib/redgraph/graph.rb, line 71 def query(cmd) _query(cmd).rows end
relationship_types()
click to toggle source
@return [Array] Existing relationship types
# File lib/redgraph/graph.rb, line 65 def relationship_types result = _query("CALL db.relationshipTypes()") result.resultset.map(&:values).flatten end
Private Instance Methods
_query(cmd)
click to toggle source
# File lib/redgraph/graph.rb, line 101 def _query(cmd) data = @connection.call("GRAPH.QUERY", graph_name, cmd, "--compact") QueryResponse.new(data, self) end