Class: RedisGraph::Metadata

Inherits:
Object
  • Object
show all
Defined in:
lib/redisgraph.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Metadata

Returns a new instance of Metadata.



14
15
16
17
18
19
20
21
22
23
# File 'lib/redisgraph.rb', line 14

def initialize(opts = {})
  @graphname = opts[:graphname]
  @connection = opts[:connection]

  # cache semantics around these labels, propertyKeys, and relationshipTypes
  # defers first read and is invalidated when changed.
  @labels_proc =  -> { call_procedure('db.labels') }
  @property_keys_proc = -> { call_procedure('db.propertyKeys') }
  @relationship_types_proc = -> { call_procedure('db.relationshipTypes') }
end

Instance Method Details

#call_procedure(procedure) ⇒ Object



41
42
43
44
45
46
# File 'lib/redisgraph.rb', line 41

def call_procedure(procedure)
  res = @connection.call("GRAPH.QUERY", @graphname, "CALL #{procedure}()")
  res[1].flatten
rescue Redis::CommandError => e
  raise CallError, e
end

#invalidateObject



25
26
27
# File 'lib/redisgraph.rb', line 25

def invalidate
  @labels = @property_keys = @relationship_types = nil
end

#labelsObject



29
30
31
# File 'lib/redisgraph.rb', line 29

def labels
  @labels ||= @labels_proc.call
end

#property_keysObject



33
34
35
# File 'lib/redisgraph.rb', line 33

def property_keys
  @property_keys ||= @property_keys_proc.call
end

#relationship_typesObject



37
38
39
# File 'lib/redisgraph.rb', line 37

def relationship_types
  @relationship_types ||= @relationship_types_proc.call
end