module TopModel::Redis::InstanceMethods
Public Instance Methods
redis_get()
click to toggle source
# File lib/topmodel/redis.rb, line 144 def redis_get load(ActiveSupport::JSON.decode(redis.get(redis_key))) end
Protected Instance Methods
create_indexes()
click to toggle source
# File lib/topmodel/redis.rb, line 117 def create_indexes indexed_attributes.each do |index| new_attribute = send(index) redis.sadd(self.class.redis_key(index, new_attribute), id) end end
destroy_indexes()
click to toggle source
# File lib/topmodel/redis.rb, line 110 def destroy_indexes indexed_attributes.each do |index| old_attribute = changes[index].try(:first) || send(index) redis.srem(self.class.redis_key(index, old_attribute), id) end end
generate_id()
click to toggle source
# File lib/topmodel/redis.rb, line 124 def generate_id redis.incr(self.class.redis_key(:uid)) end
indexed_attributes()
click to toggle source
# File lib/topmodel/redis.rb, line 128 def indexed_attributes attributes.keys & self.class.indexed_attributes end
raw_create()
click to toggle source
# File lib/topmodel/redis.rb, line 149 def raw_create redis_set create_indexes redis.sadd(self.class.redis_key, self.id) end
raw_destroy()
click to toggle source
# File lib/topmodel/redis.rb, line 102 def raw_destroy return if new? destroy_indexes redis.srem(self.class.redis_key, self.id) redis.del(redis_key) end
raw_update()
click to toggle source
# File lib/topmodel/redis.rb, line 155 def raw_update destroy_indexes redis_set create_indexes end
redis()
click to toggle source
# File lib/topmodel/redis.rb, line 132 def redis self.class.redis end
redis_key(*args)
click to toggle source
# File lib/topmodel/redis.rb, line 136 def redis_key(*args) self.class.redis_key(id, *args) end
redis_set()
click to toggle source
# File lib/topmodel/redis.rb, line 140 def redis_set redis.set(redis_key, serializable_hash.to_json) end