local function insert (key, value, lock_id, lifetime_milliseconds, idle_timeout_milliseconds, additional_keys) if is_locked_by_another_owner(key, lock_id) or is_any_locked_by_another_owner(additional_keys, lock_id) then return { "locked_by_other" } end if get_existing_entry(key) then debugLog("failed to insert new entry because entry for key '%s' already exists", key) return { "already_exists" } end set_value(key, value, nil, lifetime_milliseconds, idle_timeout_milliseconds, additional_keys) debugLog("successfully inserted key '%s' with new value", key) return { "ok", value } end local function update (key, value, lock_id, lifetime_milliseconds, idle_timeout_milliseconds, new_additional_keys) if is_locked_by_another_owner(key, lock_id) or is_any_locked_by_another_owner(new_additional_keys, lock_id) then return { "locked_by_other" } end local existing_entry = get_existing_entry(key) if not existing_entry then return { "not_found" } end local existing_additional_keys = existing_entry.additional_lock_keys if is_any_locked_by_another_owner(existing_additional_keys, lock_id) then return { "locked_by_other" } end local combined_additional_keys = combine(existing_additional_keys, new_additional_keys) set_value(key, value, existing_entry.creation_time_milliseconds, lifetime_milliseconds, idle_timeout_milliseconds, combined_additional_keys) debugLog("successfully updated key '%s' with new value", key) return { "ok", value } end