Class: WaveBox::Box
- Inherits:
-
Object
- Object
- WaveBox::Box
- Defined in:
- lib/wave_box/box.rb
Instance Attribute Summary collapse
-
#expire ⇒ Object
readonly
Returns the value of attribute expire.
-
#max_size ⇒ Object
readonly
Returns the value of attribute max_size.
Instance Method Summary collapse
- #after(time) ⇒ Object
-
#initialize(options) ⇒ Box
constructor
A new instance of Box.
- #push(value, time = Time.now) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(options) ⇒ Box
Returns a new instance of Box.
5 6 7 8 9 10 11 12 |
# File 'lib/wave_box/box.rb', line 5 def initialize() @options = @expire = [:expire] @max_size = [:max_size] @redis = [:redis] @key = [:key] @encode = [:encode] end |
Instance Attribute Details
#expire ⇒ Object (readonly)
Returns the value of attribute expire.
3 4 5 |
# File 'lib/wave_box/box.rb', line 3 def expire @expire end |
#max_size ⇒ Object (readonly)
Returns the value of attribute max_size.
3 4 5 |
# File 'lib/wave_box/box.rb', line 3 def max_size @max_size end |
Instance Method Details
#after(time) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/wave_box/box.rb', line 29 def after(time) items = @redis.zrangebyscore( @key, "#{time.to_i}", "+inf") if @encode == false items else items.map { |x| decode(x) } end end |
#push(value, time = Time.now) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/wave_box/box.rb', line 14 def push(value, time = Time.now) if @encode == false v = value else v = encode(value) end @redis.zadd(@key, time.to_i, v) truncate! end |
#size ⇒ Object
25 26 27 |
# File 'lib/wave_box/box.rb', line 25 def size @redis.zcard @key end |