local function unlock_and_remove (key, lock_id) if not owns_lock(key, lock_id) then return { "lock_not_owned" } end local existing_entry = get_existing_entry(key) if not existing_entry then return { "not_found" } end local additional_keys = existing_entry.additional_lock_keys if not owns_locks(additional_keys, lock_id) then return { "lock_not_owned" } end remove_entry(key) release_lock(key, lock_id) release_locks(additional_keys, lock_id) return { "ok", existing_entry.value } end return scriptResult(unlock_and_remove(KEYS[1], ARGV[3]))