|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Spiral\RoadRunner\Symfony\Lock; |
| 6 | + |
| 7 | +use RoadRunner\Lock\LockInterface as RrLockInterface; |
| 8 | +use Symfony\Component\Lock\Key; |
| 9 | +use Symfony\Component\Lock\PersistingStoreInterface; |
| 10 | +use Symfony\Component\Lock\SharedLockStoreInterface; |
| 11 | + |
| 12 | +final class RoadRunnerStore implements SharedLockStoreInterface |
| 13 | +{ |
| 14 | + private string $processId; |
| 15 | + |
| 16 | + public function __construct( |
| 17 | + private readonly RrLockInterface $rrLock, |
| 18 | + ?string $processId = null |
| 19 | + ) { |
| 20 | + $this->processId = $processId ?? '*'; |
| 21 | + } |
| 22 | + |
| 23 | + public function save(Key $key): void |
| 24 | + { |
| 25 | + $this->rrLock->lock((string) $key, $this->processId); |
| 26 | + } |
| 27 | + |
| 28 | + public function exists(Key $key): bool |
| 29 | + { |
| 30 | + return $this->rrLock->exists((string) $key, $this->processId); |
| 31 | + } |
| 32 | + |
| 33 | + public function putOffExpiration(Key $key, float $ttl): void |
| 34 | + { |
| 35 | + $this->rrLock->updateTTL((string) $key, $this->processId, $ttl); |
| 36 | + } |
| 37 | + |
| 38 | + public function delete(Key $key): void |
| 39 | + { |
| 40 | + $this->rrLock->forceRelease((string) $key); |
| 41 | + } |
| 42 | + |
| 43 | + public function saveRead(Key $key): void |
| 44 | + { |
| 45 | + $this->rrLock->lockRead((string) $key, $this->processId); |
| 46 | + } |
| 47 | +} |
0 commit comments