module ActiveRedis::ConnectionExt::PersistenceLayer
Public Instance Methods
create_info_table(model)
click to toggle source
# File lib/active_redis/connection_ext/persistence_layer.rb, line 15 def create_info_table(model) adapter.hmset model.info_table_name, "next_id", 0 end
destroy(model, id)
click to toggle source
# File lib/active_redis/connection_ext/persistence_layer.rb, line 19 def destroy(model, id) raise ActiveRedis::NotSpecifiedIdError, "Must specified ID for destroy record!" unless id destroy_by_keys model.table_name(id) end
destroy_all(model)
click to toggle source
# File lib/active_redis/connection_ext/persistence_layer.rb, line 24 def destroy_all(model) destroy_by_keys fetch_keys(model) end
expire_record(model, id, seconds = -1)
click to toggle source
# File lib/active_redis/connection_ext/persistence_layer.rb, line 28 def expire_record(model, id, seconds = -1) raise ActiveRedis::NotSpecifiedIdError, "Must specified ID for destroy record!" unless id if seconds > 0 adapter.expire model.table_name(id), seconds else adapter.persist model.table_name(id) end end
next_id(model)
click to toggle source
# File lib/active_redis/connection_ext/persistence_layer.rb, line 9 def next_id(model) table = model.info_table_name create_info_table(model) unless adapter.exists(table) adapter.hincrby table, "next_id", 1 end
save_table(model, attributes)
click to toggle source
# File lib/active_redis/connection_ext/persistence_layer.rb, line 4 def save_table(model, attributes) raise ActiveRedis::NotSpecifiedIdError, "Must specified ID for saving record!" if !attributes || !attributes[:id] adapter.hmset(model.table_name(attributes[:id]), attributes.flatten) == ActiveRedis::Constants::SAVE_SUCCESS_ANSWER end
Private Instance Methods
destroy_by_keys(keys)
click to toggle source
# File lib/active_redis/connection_ext/persistence_layer.rb, line 38 def destroy_by_keys(keys) adapter.del keys end