Class: RedSetUnion
- Inherits:
-
Object
- Object
- RedSetUnion
- Defined in:
- lib/redness/red_set_union.rb
Instance Attribute Summary collapse
-
#keys ⇒ Object
Returns the value of attribute keys.
-
#redis ⇒ Object
Returns the value of attribute redis.
Instance Method Summary collapse
- #get(options = {}) ⇒ Object
-
#initialize(*keys) ⇒ RedSetUnion
constructor
A new instance of RedSetUnion.
Constructor Details
#initialize(*keys) ⇒ RedSetUnion
Returns a new instance of RedSetUnion.
4 5 6 7 8 9 |
# File 'lib/redness/red_set_union.rb', line 4 def initialize(*keys) self.keys = keys self.redis = Red.new @temporary_key = "tmp:red_set_union" end |
Instance Attribute Details
#keys ⇒ Object
Returns the value of attribute keys.
2 3 4 |
# File 'lib/redness/red_set_union.rb', line 2 def keys @keys end |
#redis ⇒ Object
Returns the value of attribute redis.
2 3 4 |
# File 'lib/redness/red_set_union.rb', line 2 def redis @redis end |
Instance Method Details
#get(options = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/redness/red_set_union.rb', line 11 def get( = {}) lower_bound = [:lower] || 0 upper_bound = [:upper] || -1 redis.execute_with_uncertainty([]) do results = redis.multi_with_caution do redis.zunionstore(@temporary_key, keys) redis.zrevrange(@temporary_key, lower_bound, upper_bound) redis.del(@temporary_key) end if results.present? results[1].flatten.compact.uniq.map(&:to_i) else [] end end end |