Class: SuperSpreader::RedisModel
- Inherits:
-
Object
- Object
- SuperSpreader::RedisModel
- Includes:
- ActiveModel::Attributes, ActiveModel::Model, ActiveModel::Serialization
- Defined in:
- lib/super_spreader/redis_model.rb
Direct Known Subclasses
Instance Method Summary collapse
- #default_values ⇒ Object
- #delete ⇒ Object
-
#initialize(values = default_values) ⇒ RedisModel
constructor
A new instance of RedisModel.
- #persisted? ⇒ Boolean
- #save ⇒ Object (also: #save!)
Constructor Details
#initialize(values = default_values) ⇒ RedisModel
Returns a new instance of RedisModel.
12 13 14 |
# File 'lib/super_spreader/redis_model.rb', line 12 def initialize(values = default_values) super end |
Instance Method Details
#default_values ⇒ Object
16 17 18 |
# File 'lib/super_spreader/redis_model.rb', line 16 def default_values redis.hgetall(redis_key) end |
#delete ⇒ Object
24 25 26 |
# File 'lib/super_spreader/redis_model.rb', line 24 def delete redis.del(redis_key) end |
#persisted? ⇒ Boolean
20 21 22 |
# File 'lib/super_spreader/redis_model.rb', line 20 def persisted? redis.get(redis_key).present? end |
#save ⇒ Object Also known as: save!
28 29 30 31 32 33 34 35 36 |
# File 'lib/super_spreader/redis_model.rb', line 28 def save redis.multi do |pipeline| pipeline.del(redis_key) serializable_hash.each do |key, value| pipeline.hset(redis_key, key, value) end end end |