Skip to content

Commit 68e21aa

Browse files
committed
Removed the semaphore size from the key
1 parent 05d798b commit 68e21aa

File tree

5 files changed

+13
-15
lines changed

5 files changed

+13
-15
lines changed

src/Symfony/Component/Semaphore/Key.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function __construct(string $resource, int $limit, int $weight = 1)
4747

4848
public function __toString(): string
4949
{
50-
return $this->resource.':'.$this->limit;
50+
return $this->resource;
5151
}
5252

5353
public function getLimit(): int

src/Symfony/Component/Semaphore/SemaphoreFactory.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,12 @@ public function __construct(PersistingStoreInterface $store)
3939
/**
4040
* Creates a semaphore for the given resource.
4141
*
42-
* @param string $resource The semaphore name
43-
* @param int $limit The semaphore limit
4442
* @param float|null $ttlInSecond Maximum expected semaphore duration in seconds
4543
* @param bool $autoRelease Whether to automatically release the semaphore or not when the semaphore instance is destroyed
4644
*/
47-
public function createSemaphore(string $resource, int $limit, ?float $ttlInSecond = 300.0, bool $autoRelease = true): SemaphoreInterface
45+
public function createSemaphore(string $resource, int $limit, int $weight = 1, ?float $ttlInSecond = 300.0, bool $autoRelease = true): SemaphoreInterface
4846
{
49-
$semaphore = new Semaphore(new Key($resource, $limit), $this->store, $ttlInSecond, $autoRelease);
47+
$semaphore = new Semaphore(new Key($resource, $limit, $weight), $this->store, $ttlInSecond, $autoRelease);
5048
$semaphore->setLogger($this->logger);
5149

5250
return $semaphore;

src/Symfony/Component/Semaphore/Store/RedisStore.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class RedisStore implements PersistingStoreInterface
3737
public function __construct($redisClient)
3838
{
3939
if (!$redisClient instanceof \Redis && !$redisClient instanceof \RedisArray && !$redisClient instanceof \RedisCluster && !$redisClient instanceof \Predis\ClientInterface && !$redisClient instanceof RedisProxy) {
40-
throw new InvalidArgumentException(sprintf('%s() expects parameter 1 to be Redis, RedisArray, RedisCluster or Predis\ClientInterface, %s given', __METHOD__, \is_object($redisClient) ? \get_class($redisClient) : \gettype($redisClient)));
40+
throw new InvalidArgumentException(sprintf('"%s()" expects parameter 1 to be Redis, RedisArray, RedisCluster or Predis\ClientInterface, "%s" given.', __METHOD__, \is_object($redisClient) ? \get_class($redisClient) : \gettype($redisClient)));
4141
}
4242

4343
$this->redis = $redisClient;
@@ -125,7 +125,7 @@ private function evaluate(string $script, string $resource, array $args)
125125
return $this->redis->eval(...array_merge([$script, 1, $resource], $args));
126126
}
127127

128-
throw new InvalidArgumentException(sprintf('%s() expects being initialized with a Redis, RedisArray, RedisCluster or Predis\ClientInterface, %s given', __METHOD__, \is_object($this->redis) ? \get_class($this->redis) : \gettype($this->redis)));
128+
throw new InvalidArgumentException(sprintf('"%s()" expects being initialized with a Redis, RedisArray, RedisCluster or Predis\ClientInterface, "%s" given.', __METHOD__, \is_object($this->redis) ? \get_class($this->redis) : \gettype($this->redis)));
129129
}
130130

131131
private function getUniqueToken(Key $key): string

src/Symfony/Component/Semaphore/Store/StoreFactory.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class StoreFactory
3535
public static function createStore($connection)
3636
{
3737
if (!\is_string($connection) && !\is_object($connection)) {
38-
throw new \TypeError(sprintf('Argument 1 passed to %s() must be a string or a connection object, %s given.', __METHOD__, \gettype($connection)));
38+
throw new \TypeError(sprintf('Argument 1 passed to "%s()" must be a string or a connection object, "%s" given.', __METHOD__, \gettype($connection)));
3939
}
4040

4141
switch (true) {
@@ -48,7 +48,7 @@ public static function createStore($connection)
4848
return new RedisStore($connection);
4949

5050
case !\is_string($connection):
51-
throw new InvalidArgumentException(sprintf('Unsupported Connection: %s.', \get_class($connection)));
51+
throw new InvalidArgumentException(sprintf('Unsupported Connection: "%s".', \get_class($connection)));
5252
case 0 === strpos($connection, 'redis://'):
5353
case 0 === strpos($connection, 'rediss://'):
5454
if (!class_exists(AbstractAdapter::class)) {
@@ -59,6 +59,6 @@ public static function createStore($connection)
5959
return new RedisStore($connection);
6060
}
6161

62-
throw new InvalidArgumentException(sprintf('Unsupported Connection: %s.', $connection));
62+
throw new InvalidArgumentException(sprintf('Unsupported Connection: "%s".', $connection));
6363
}
6464
}

src/Symfony/Component/Semaphore/Tests/SemaphoreTest.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function testAcquireThrowException()
7373
;
7474

7575
$this->expectException(RuntimeException::class);
76-
$this->expectExceptionMessage('Failed to acquire the "key:1" semaphore.');
76+
$this->expectExceptionMessage('Failed to acquire the "key" semaphore.');
7777

7878
$semaphore->acquire();
7979
}
@@ -124,7 +124,7 @@ public function testRefreshWhenItFails()
124124
;
125125

126126
$this->expectException(SemaphoreExpiredException::class);
127-
$this->expectExceptionMessage('The semaphore "key:1" has expired: message.');
127+
$this->expectExceptionMessage('The semaphore "key" has expired: message.');
128128

129129
$semaphore->refresh();
130130
}
@@ -143,7 +143,7 @@ public function testRefreshWhenItFailsHard()
143143
;
144144

145145
$this->expectException(RuntimeException::class);
146-
$this->expectExceptionMessage('Failed to define an expiration for the "key:1" semaphore.');
146+
$this->expectExceptionMessage('Failed to define an expiration for the "key" semaphore.');
147147

148148
$semaphore->refresh();
149149
}
@@ -177,7 +177,7 @@ public function testReleaseWhenItFails()
177177
;
178178

179179
$this->expectException(SemaphoreReleasingException::class);
180-
$this->expectExceptionMessage('The semaphore "key:1" could not be released: message.');
180+
$this->expectExceptionMessage('The semaphore "key" could not be released: message.');
181181

182182
$semaphore->release();
183183
}
@@ -196,7 +196,7 @@ public function testReleaseWhenItFailsHard()
196196
;
197197

198198
$this->expectException(RuntimeException::class);
199-
$this->expectExceptionMessage('Failed to release the "key:1" semaphore.');
199+
$this->expectExceptionMessage('Failed to release the "key" semaphore.');
200200

201201
$semaphore->release();
202202
}

0 commit comments

Comments
 (0)