Module: RedisRecord::Base

Extended by:
ActiveSupport::Concern
Included in:
RedisRecord
Defined in:
lib/redis_record/base.rb,
lib/redis_record/base/class_methods.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#destroyObject Also known as: destroy!



24
25
26
27
28
29
30
31
32
# File 'lib/redis_record/base.rb', line 24

def destroy
  success = nil
  RedisRecord.REDIS.multi do
    run_callbacks :destroy do
      success = RedisRecord.REDIS.del key
    end
  end
  success.value == 1 ? self : nil
end

#keyObject



40
41
42
# File 'lib/redis_record/base.rb', line 40

def key
  self.class.key(id)
end

#saveObject Also known as: save!



13
14
15
16
17
18
19
20
21
# File 'lib/redis_record/base.rb', line 13

def save
  success = nil
  RedisRecord.REDIS.multi do
    run_callbacks :save do
      success = RedisRecord.REDIS.mapped_hmset(key, attributes)
    end
  end
  self.persisted = (success.value == "OK")
end

#update_attributes(attrs) ⇒ Object



35
36
37
38
# File 'lib/redis_record/base.rb', line 35

def update_attributes(attrs)
  assign_attributes attrs
  save
end