Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ mago-format: # Run code formatting via mago.

.PHONY: run-tests
run-tests: # Run unit tests via PHPUnit.
docker compose run --rm php ./vendor/bin/phpunit --colors=always --configuration ./tests/phpunit.xml ./tests/Unit/
docker compose run --rm php ./vendor/bin/phpunit --colors=always --configuration ./tests/phpunit.xml ./tests/
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ composer require mimatus/locksmith

## Roadmap
- [x] Basic in-memory & Redis semaphore implementation
- [x] Redlock algorithm for Redis semaphore
- [x] Predis support for Redis semaphore
- [x] AMPHP Redis client support for Redis semaphore
- [ ] First class support and tests for Valkey/KeyDB
- [ ] Feedback and API stabilization
- [ ] Documentation improvements
- [x] Redlock algorithm for Redis semaphore
- [ ] Predis support for Redis semaphore
- [ ] AMPHP Redis client support for Redis semaphore
- [ ] MySQL/MariaDB/PostgreSQL semaphore implementation

## Usage
Expand Down Expand Up @@ -64,9 +65,10 @@ $locked(function (Closure $suspension): void {

$redis = new Redis();
$redis->connect('redis');
$phpRedisCleint = new PhpRedisClient($redis);

$semaphore = new RedisSemaphore(
redisClient: $redis,
redisClient: $phpRedisCleint,
maxConcurrentLocks: 3, // Max concurrent locks
);

Expand Down Expand Up @@ -97,15 +99,15 @@ $locked(function (Closure $suspension): void {
```php
$semaphores = new SemaphoreCollection([
new RedisSemaphore(
redisClient: $redis1,
redisClient: $redisClient1,
maxConcurrentLocks: 3,
),
new RedisSemaphore(
redisClient: $redis2,
redisClient: $redisClient2,
maxConcurrentLocks: 3,
),
new RedisSemaphore(
redisClient: $redis3,
redisClient: $redisClient3,
maxConcurrentLocks: 3,
),
]);
Expand Down Expand Up @@ -155,7 +157,7 @@ mago-analyze: Run static analysis via mago.
mago-format: Run code formatting via mago.
mago-lint-fix: Run linting with auto-fix via mago.
mago-lint: Run linting via mago.
run-tests: Run unit tests via PHPUnit.
run-tests: Run tests via PHPUnit.
```

## License
Expand Down
11 changes: 8 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
"type": "library",
"license": "MIT",
"require": {
"php": ">=8.3"
"php": ">=8.3",
"revolt/event-loop": "^1.0"
},
"suggest": {
"ext-redis": "To use this library with the PHP Redis extension."
"ext-redis": "To use this library with the PHP Redis extension.",
"predis/predis": "To use this library with the Predis client.",
"amphp/redis": "To use this library with the AMPHP Redis client."
},
"autoload": {
"psr-4": {
Expand All @@ -20,6 +23,8 @@
},
"require-dev": {
"ext-redis": "*",
"phpunit/phpunit": "^12.5"
"phpunit/phpunit": "^12.5",
"amphp/redis": "^2.0",
"predis/predis": "^3.3"
}
}
Loading