Class: SuperSpreader::RedisModel

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Attributes, ActiveModel::Model, ActiveModel::Serialization
Defined in:
lib/super_spreader/redis_model.rb

Direct Known Subclasses

SchedulerConfig

Instance Method Summary collapse

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_valuesObject



16
17
18
# File 'lib/super_spreader/redis_model.rb', line 16

def default_values
  redis.hgetall(redis_key)
end

#deleteObject



24
25
26
# File 'lib/super_spreader/redis_model.rb', line 24

def delete
  redis.del(redis_key)
end

#persisted?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/super_spreader/redis_model.rb', line 20

def persisted?
  redis.get(redis_key).present?
end

#saveObject 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