class RediSet::Query

Attributes

constraints[R]

Public Class Methods

from_hash(constraint_hash) click to toggle source
# File lib/redi_set/query.rb, line 5
def self.from_hash(constraint_hash)
  constraints = constraint_hash.map do |key, val|
    attribute = Attribute.new(name: key)
    qualities = Array(val).map { |v| Quality.new(attribute: attribute, name: v) }
    Constraint.new(qualities: qualities)
  end
  RediSet::Query.new(constraints)
end
new(constraints) click to toggle source
# File lib/redi_set/query.rb, line 14
def initialize(constraints)
  @constraints = constraints
end

Public Instance Methods

execute(redis) click to toggle source
# File lib/redi_set/query.rb, line 18
def execute(redis)
  redis.multi do
    constraints.select(&:requires_union?).each { |c| c.store_union(redis) }
    redis.sinter(constraints.map(&:intersection_key))
  end.last
end