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.
- #logical_database(val = nil) ⇒ Object included from DataType::ClassMethods
-
#parent ⇒ Object
included
from DataType::ClassMethods
Returns the value of attribute parent.
-
#prefix ⇒ Object
included
from DataType::ClassMethods
Returns the value of attribute prefix.
-
#suffix ⇒ Object
included
from DataType::ClassMethods
Returns the value of attribute suffix.
-
#uri(val = nil) ⇒ Object
included
from DataType::ClassMethods
Returns the value of attribute uri.
Attributes included from Settings
#current_key_version, #default_expiration, #delim, #encryption_keys, #encryption_personalization, #logical_database, #prefix, #schema_path, #schema_validator, #schemas, #suffix, #transaction_mode
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 Features::Autoloader
autoload_files, included, normalize_to_config_name
Methods included from DataType::Serialization
#deserialize_value, #deserialize_values, #deserialize_values_with_nil, #serialize_value
Methods included from DataType::DatabaseCommands
#current_expiration, #delete!, #echo, #exists?, #expire, #expireat, #move, #persist, #rename, #renamenx, #type
Methods included from DataType::Connection
#dbclient, #dbkey, #direct_access, #uri
Methods included from Familia::Connection::Behavior
#connect, #create_dbclient, #multi, #normalize_uri, #pipeline, #pipelined, #transaction, #uri=, #url, #url=
Methods included from Settings
#configure, #default_suffix, #pipelined_mode, #pipelined_mode=
Methods included from Base
add_feature, #as_json, #expired?, #expires?, find_feature, #generate_id, #to_json, #to_s, #ttl, #update_expiration, #uuid
Constructor Details
#initialize(*args) ⇒ Counter
Returns a new instance of Counter.
7 8 9 10 |
# File 'lib/familia/data_type/types/counter.rb', line 7 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.
#logical_database(val = nil) ⇒ Object Originally defined in module DataType::ClassMethods
#parent ⇒ Object Originally defined in module DataType::ClassMethods
Returns the value of attribute parent.
#prefix ⇒ Object Originally defined in module DataType::ClassMethods
Returns the value of attribute prefix.
#suffix ⇒ Object Originally defined in module DataType::ClassMethods
Returns the value of attribute suffix.
#uri(val = nil) ⇒ Object Originally defined in module DataType::ClassMethods
Returns the value of attribute uri.
Instance Method Details
#atomic_increment_and_get(amount = 1) ⇒ Object
25 26 27 |
# File 'lib/familia/data_type/types/counter.rb', line 25 def atomic_increment_and_get(amount = 1) incrementby(amount) end |
#increment_if_less_than(threshold, amount = 1) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/familia/data_type/types/counter.rb', line 17 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
13 14 15 |
# File 'lib/familia/data_type/types/counter.rb', line 13 def reset(val = 0) set(val).to_s.eql?('OK') end |
#value ⇒ Object
34 35 36 |
# File 'lib/familia/data_type/types/counter.rb', line 34 def value super.to_i end |
#value=(val) ⇒ Object
Override to ensure integer serialization
30 31 32 |
# File 'lib/familia/data_type/types/counter.rb', line 30 def value=(val) super(val.to_i) end |