Class: RedBlocks::SubtractionSet
- Defined in:
- lib/red_blocks/subtraction_set.rb
Instance Attribute Summary collapse
- #cache_time ⇒ Object
-
#set1 ⇒ Object
Returns the value of attribute set1.
-
#set2 ⇒ Object
Returns the value of attribute set2.
Attributes inherited from Set
Instance Method Summary collapse
- #expression(id) ⇒ Object
-
#initialize(set1, set2, cache_time: nil) ⇒ SubtractionSet
constructor
A new instance of SubtractionSet.
- #key_suffix ⇒ Object
- #sets ⇒ Object
- #update! ⇒ Object
Methods inherited from Set
#disabled?, #expiration_time, #get, #ids, #key, key_pattern, #label, #size, #update_if_disabled!
Methods included from SetOptimizer
Methods included from SetUtils
included, #joined_key, #normalize_entries, #validate_array_entry, #validate_entries!
Constructor Details
#initialize(set1, set2, cache_time: nil) ⇒ SubtractionSet
Returns a new instance of SubtractionSet.
6 7 8 9 10 11 12 13 14 |
# File 'lib/red_blocks/subtraction_set.rb', line 6 def initialize(set1, set2, cache_time: nil) unless [set1, set2].all? { |set| set.is_a?(RedBlocks::Set) } raise TypeError.new("set1 and set2 must be a Array<RedBlocks::Set>, but got the following list: #{sets.map(&:class).join(', ')}") end @set1 = set1 @set2 = set2 @cache_time = cache_time end |
Instance Attribute Details
#cache_time ⇒ Object
28 29 30 |
# File 'lib/red_blocks/subtraction_set.rb', line 28 def cache_time @cache_time || super end |
#set1 ⇒ Object
Returns the value of attribute set1.
3 4 5 |
# File 'lib/red_blocks/subtraction_set.rb', line 3 def set1 @set1 end |
#set2 ⇒ Object
Returns the value of attribute set2.
3 4 5 |
# File 'lib/red_blocks/subtraction_set.rb', line 3 def set2 @set2 end |
Instance Method Details
#expression(id) ⇒ Object
32 33 34 |
# File 'lib/red_blocks/subtraction_set.rb', line 32 def expression(id) set1.expression(id) end |
#key_suffix ⇒ Object
16 17 18 |
# File 'lib/red_blocks/subtraction_set.rb', line 16 def key_suffix joined_key(sets.map(&:key).sort, sep: '|', wrap: true) end |
#sets ⇒ Object
36 37 38 |
# File 'lib/red_blocks/subtraction_set.rb', line 36 def sets [set1, set2] end |
#update! ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/red_blocks/subtraction_set.rb', line 20 def update! disabled_sets.each(&:update!) # [Note] The following operation will be faster if we use Redis script. RedBlocks.client.zunionstore(key, [set1.key]) RedBlocks.client.zrem(key, set2.ids(paginator: RedBlocks::Paginator.all)) RedBlocks.client.expire(key, expiration_time) end |