Class: Redlics::Query::Operation
- Inherits:
-
Object
- Object
- Redlics::Query::Operation
- Includes:
- Operators
- Defined in:
- lib/redlics/query/operation.rb
Overview
Operation class
Instance Attribute Summary collapse
-
#namespaces ⇒ Object
readonly
Gives read access to the listed instance variables.
Class Method Summary collapse
-
.finalize(namespaces) ⇒ Integer, NilClass
Finalize query operation called from garbage collector.
-
.reset_redis_namespaces(namespaces) ⇒ Integer, NilClass
Reset Redis created namespace keys.
Instance Method Summary collapse
-
#exists?(id) ⇒ Boolean
Check if object id exists in track bits.
-
#initialize(operator, queries) ⇒ Redlics::Query::Operation
constructor
Initialization of a query operation object.
-
#is_leaf? ⇒ Boolean
Check if query operation is a leaf in the binary tree.
-
#reset!(space = nil) ⇒ Boolean
Reset processed data (also operation keys on Redis).
-
#track_bits ⇒ String
Get or process track bits on Redis.
-
#tracks ⇒ Integer
Get or process tracks on Redis.
Methods included from Operators
Constructor Details
#initialize(operator, queries) ⇒ Redlics::Query::Operation
Initialization of a query operation object.
18 19 20 21 22 23 24 |
# File 'lib/redlics/query/operation.rb', line 18 def initialize(operator, queries) @operator = operator.upcase.freeze @queries = queries.freeze @track_bits = nil @namespaces = [] ObjectSpace.define_finalizer(self, self.class.finalize(namespaces)) if Redlics.config.auto_clean end |
Instance Attribute Details
#namespaces ⇒ Object (readonly)
Gives read access to the listed instance variables.
11 12 13 |
# File 'lib/redlics/query/operation.rb', line 11 def namespaces @namespaces end |
Class Method Details
.finalize(namespaces) ⇒ Integer, NilClass
Finalize query operation called from garbage collector.
92 93 94 |
# File 'lib/redlics/query/operation.rb', line 92 def finalize(namespaces) proc { reset_redis_namespaces(namespaces) } end |
Instance Method Details
#exists?(id) ⇒ Boolean
Check if object id exists in track bits.
56 57 58 |
# File 'lib/redlics/query/operation.rb', line 56 def exists?(id) Redlics.redis { |r| r.getbit(@track_bits || traverse, id.to_i) } == 1 end |
#is_leaf? ⇒ Boolean
Check if query operation is a leaf in the binary tree.
81 82 83 |
# File 'lib/redlics/query/operation.rb', line 81 def is_leaf? is_a?(Redlics::Query::Operation) && @track_bits.nil? end |
#reset!(space = nil) ⇒ Boolean
Reset processed data (also operation keys on Redis).
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/redlics/query/operation.rb', line 65 def reset!(space = nil) space = space.to_sym if space case space when :tree @queries.each { |q| q.reset!(:tree) } reset! else @tracks, @track_bits = nil, nil self.class.reset_redis_namespaces(@namespaces) @namespaces = [] end return true end |
#track_bits ⇒ String
Get or process track bits on Redis.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/redlics/query/operation.rb', line 36 def track_bits @track_bits ||= ( keys = [] track_bits_namespace = Key.unique_namespace @namespaces << track_bits_namespace if @operator == 'NOT' keys << Key.with_namespace(@queries[0].track_bits) else @queries.each { |q| keys << Key.with_namespace(q.track_bits) } end Redlics.script(Redlics::LUA_SCRIPT, [], ['operation'.to_msgpack, keys.to_msgpack, { operator: @operator, dest: Key.with_namespace(track_bits_namespace) }.to_msgpack]) track_bits_namespace ) end |