Class: RedisGraph::Metadata
- Inherits:
-
Object
- Object
- RedisGraph::Metadata
- Defined in:
- lib/redisgraph.rb
Instance Method Summary collapse
- #call_procedure(procedure) ⇒ Object
-
#initialize(opts = {}) ⇒ Metadata
constructor
A new instance of Metadata.
- #invalidate ⇒ Object
- #labels ⇒ Object
- #property_keys ⇒ Object
- #relationship_types ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Metadata
Returns a new instance of Metadata.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/redisgraph.rb', line 13 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
40 41 42 43 44 45 |
# File 'lib/redisgraph.rb', line 40 def call_procedure(procedure) res = @connection.call("GRAPH.QUERY", @graphname, "CALL #{procedure}()") res[1].flatten rescue Redis::CommandError => e raise CallError, e end |
#invalidate ⇒ Object
24 25 26 |
# File 'lib/redisgraph.rb', line 24 def invalidate @labels = @property_keys = @relationship_types = nil end |
#labels ⇒ Object
28 29 30 |
# File 'lib/redisgraph.rb', line 28 def labels @labels ||= @labels_proc.call end |
#property_keys ⇒ Object
32 33 34 |
# File 'lib/redisgraph.rb', line 32 def property_keys @property_keys ||= @property_keys_proc.call end |
#relationship_types ⇒ Object
36 37 38 |
# File 'lib/redisgraph.rb', line 36 def relationship_types @relationship_types ||= @relationship_types_proc.call end |