class RedisGraph

Constants

VERSION

Attributes

connection[RW]
graphname[RW]
metadata[RW]

Public Class Methods

new(graph, redis_options = {}) click to toggle source

The RedisGraph constructor instantiates a Redis connection and validates that the graph module is loaded

# File lib/redisgraph.rb, line 51
def initialize(graph, redis_options = {})
  @graphname = graph
  connect_to_server(redis_options)
  @metadata = Metadata.new(graphname: @graphname,
                           connection: @connection)
end

Public Instance Methods

connect_to_server(options) click to toggle source
# File lib/redisgraph/connection.rb, line 2
def connect_to_server(options)
  @connection = Redis.new(options)
  @module_version = module_version()
  raise ServerError, "RedisGraph module not loaded." if @module_version.nil?
  raise ServerError, "RedisGraph module incompatible, expecting >= 1.99." if @module_version < 19900
end
delete() click to toggle source

Delete the graph and all associated keys

# File lib/redisgraph.rb, line 75
def delete
  @connection.call('GRAPH.DELETE', @graphname)
rescue Redis::CommandError => e
  raise DeleteError, e
end
explain(command) click to toggle source

Return the execution plan for a given command

# File lib/redisgraph.rb, line 68
def explain(command)
  @connection.call('GRAPH.EXPLAIN', @graphname, command)
rescue Redis::CommandError => e
  raise ExplainError, e
end
module_version() click to toggle source

Ensure that the connected Redis server supports modules and has loaded the RedisGraph module

# File lib/redisgraph/connection.rb, line 11
def module_version()
  redis_version = @connection.info["redis_version"]
  major_version = redis_version.split('.').first.to_i
  raise ServerError, "Redis 4.0 or greater required for RedisGraph support." unless major_version >= 4
  modules = @connection.call("MODULE", "LIST")
  module_graph = modules.detect { |_name_key, name, _ver_key, _ver| name == 'graph' }
  module_graph[3] if module_graph
end
query(command) click to toggle source

Execute a command and return its parsed result

# File lib/redisgraph.rb, line 59
def query(command)
  resp = @connection.call('GRAPH.QUERY', @graphname, command, '--compact')
  QueryResult.new(resp,
                  metadata:   @metadata)
rescue Redis::CommandError => e
  raise QueryError, e
end