Class: Familia::Counter
- Defined in:
- lib/familia/data_type/types/counter.rb
Instance Attribute Summary collapse
-
#features_enabled ⇒ Object
included
from Features
readonly
Returns the value of attribute features_enabled.
Instance Method Summary collapse
-
#atomic_increment_and_get(amount = 1) ⇒ Object
-
#increment_if_less_than(threshold, amount = 1) ⇒ Object
-
#initialize(*args) ⇒ Counter
constructor
A new instance of Counter.
-
#reset(val = 0) ⇒ Object
Enhanced counter semantics.
-
#value ⇒ Object
-
#value=(val) ⇒ Object
Override to ensure integer serialization.
Methods included from DataType::Serialization
#deserialize_value, #deserialize_values, #deserialize_values_with_nil, #serialize_value
Methods included from DataType::Commands
#current_expiration, #delete!, #echo, #exists?, #expire, #expireat, #move, #persist, #rename, #renamenx, #type
Methods included from Base
add_feature, #expired?, #expires?, find_feature, #generate_id, #to_s, #ttl, #update_expiration, #uuid
Constructor Details
#initialize(*args) ⇒ Counter
Returns a new instance of Counter.
5 6 7 8 |
# File 'lib/familia/data_type/types/counter.rb', line 5 def initialize(*args) super @opts[:default] ||= 0 end |
Instance Attribute Details
#features_enabled ⇒ Object (readonly) Originally defined in module Features
Returns the value of attribute features_enabled.
Instance Method Details
#atomic_increment_and_get(amount = 1) ⇒ Object
23 24 25 |
# File 'lib/familia/data_type/types/counter.rb', line 23 def atomic_increment_and_get(amount = 1) incrementby(amount) end |
#increment_if_less_than(threshold, amount = 1) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/familia/data_type/types/counter.rb', line 15 def increment_if_less_than(threshold, amount = 1) current = to_i return false if current >= threshold incrementby(amount) true end |
#reset(val = 0) ⇒ Object
Enhanced counter semantics
11 12 13 |
# File 'lib/familia/data_type/types/counter.rb', line 11 def reset(val = 0) set(val).to_s.eql?('OK') end |
#value ⇒ Object
32 33 34 |
# File 'lib/familia/data_type/types/counter.rb', line 32 def value super.to_i end |
#value=(val) ⇒ Object
Override to ensure integer serialization
28 29 30 |
# File 'lib/familia/data_type/types/counter.rb', line 28 def value=(val) super(val.to_i) end |