// in the normal flow where the increment value is greater or equals the configured start value
// we can use the stored increment value as is, thus we are atomic and don't need locking in the normal case
if ($increment >=
$start) { return $increment;
} // if the configured start value is greater than the current increment
// we need a lock so that the value be only set once to the start value
$lock =
$this->lockFactory->
createLock('number-range-' .
$config['id'
]);
if (!
$lock->
acquire()) { // we can't acquire the lock, meaning another request will increase the increment value to the new start value
// so we can use the current increment for now
return $increment;
} try { // to set the current increment to the new configured start we use incrementBy, rather than simply setting the new start value
// to prevent issues where maybe the increment value is already increment to higher value by competing requests
$newIncr =
$this->redis->
incrBy($key,
$start -
$increment); // // @phpstan-ignore-line - because multiple redis implementations phpstan doesn't like this
\
assert(\
is_int($newIncr));