lib/ohm/lua/save.lua in ohm-2.0.0.alpha4 vs lib/ohm/lua/save.lua in ohm-2.0.0.alpha5

- old
+ new

@@ -33,9 +33,15 @@ local attrs = cmsgpack.unpack(ARGV[2]) local indices = cmsgpack.unpack(ARGV[3]) local uniques = cmsgpack.unpack(ARGV[4]) local function save(model, attrs) + if model.id == nil then + model.id = redis.call("INCR", model.name .. ":id") + end + + model.key = model.name .. ":" .. model.id + redis.call("SADD", model.name .. ":all", model.id) redis.call("DEL", model.key) if math.mod(#attrs, 2) == 1 then error("Wrong number of attribute/value pairs")