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, 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



27
28
29
30
31
32
33
# File 'lib/redness/timed_red_set.rb', line 27

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



22
23
24
25
# File 'lib/redness/timed_red_set.rb', line 22

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
# 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
    if options[:upper] and options[:lower]
      lower = options[:lower].to_i
      upper = options[:upper].to_i

      redis.zrevrangebyscore(key, "+inf", precise_start)[lower..upper].map(&:to_i)
    else
      redis.zrevrangebyscore(key, "+inf", precise_start).map(&:to_i)
    end
  end
end