Class: TimedRedSet

Inherits:
RedSet show all
Defined in:
lib/redness/timed_red_set.rb

Instance Attribute Summary

Attributes inherited from RedSet

#key

Class Method Summary collapse

Methods inherited from RedSet

#add, cap, count, get, get_strings, #initialize, redis, remove, #remove, #value

Constructor Details

This class inherits a constructor from RedSet

Class Method Details

.add(key, member) ⇒ Object



3
4
5
# File 'lib/redness/timed_red_set.rb', line 3

def self.add(key, member)
  super(key, member, :score => lambda { Precisionable.int_from_float(Time.now) })
end

.get_with_timestamps(key, options = {}) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/redness/timed_red_set.rb', line 37

def self.get_with_timestamps(key, options = {})
  get(key, options.merge({
      :with_scores => true,
      :scoring => lambda {|x| Time.at(Precisionable.float_from_int(x))}
    })
  )
end

.score(key, member) ⇒ Object



32
33
34
35
# File 'lib/redness/timed_red_set.rb', line 32

def self.score(key, member)
  precise_time = super
  Time.at(Precisionable.float_from_int(precise_time)) if precise_time
end

.since(key, start, options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/redness/timed_red_set.rb', line 7

def self.since(key, start, options={})
  precise_start = Precisionable.int_from_float(start)

  redis.execute_with_uncertainty([]) do
    raw = redis.zrevrangebyscore(key, "+inf", precise_start, with_scores: options[:with_scores])

    if options[:upper] and options[:lower]
      lower = options[:lower].to_i
      upper = options[:upper].to_i

      raw = raw[lower..upper]
    end

    if options[:with_scores]
      result = {}
      raw.each do |member, score|
        result[member.to_i] = Time.at(Precisionable.float_from_int(score))
      end
      result
    else
      raw.map(&:to_i)
    end
  end
end