Method: Sohm::Model#delete

Defined in:
lib/sohm.rb

#deleteObject

Delete the model, including all the following keys:

  • <Model>:<id>

  • <Model>:<id>:_counters

  • <Model>:<id>:<set name>

If the model has uniques or indices, they’re also cleaned up.



1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
# File 'lib/sohm.rb', line 1166

def delete
  memo_key = key["_indices"]
  commands = [["DEL", key], ["DEL", memo_key], ["DEL", key["_counters"]]]
  index_list = redis.call("SMEMBERS", memo_key)
  index_list.each do |index_key|
    commands << ["SREM", index_key, id]
  end
  model.tracked.each do |tracked_key|
    commands << ["DEL", key[tracked_key]]
  end

  model.synchronize do
    commands.each do |command|
      redis.queue(*command)
    end
    redis.commit
  end

  return self
end