Add atomic reservation support in Redis for goal alert deduplication with expiration. Update Cron logic and add unit tests for validation.
This commit is contained in:
@@ -450,6 +450,21 @@ class redis implements redis_i
|
||||
return 'temporary_cache_' . uniqid();
|
||||
}
|
||||
|
||||
/**
|
||||
* Atomically set a key with TTL only when it does not already exist.
|
||||
*/
|
||||
public function set_if_absent_with_expiration(string $key, string $value, int $seconds): bool
|
||||
{
|
||||
if (!self::is_connected()) {
|
||||
self::connect();
|
||||
}
|
||||
|
||||
$seconds = max(1, $seconds);
|
||||
$result = $this->redis->set($key, $value, 'EX', $seconds, 'NX');
|
||||
|
||||
return $result === true || strtoupper((string)$result) === 'OK';
|
||||
}
|
||||
|
||||
public function mget(array $array_map): array
|
||||
{
|
||||
// Get multiple keys from Redis
|
||||
@@ -485,4 +500,4 @@ class redis implements redis_i
|
||||
$this->delete('perm:' . $cache_key);
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user