diff --git a/.gitignore b/.gitignore index 4c36e38..072705c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea/ vendor/ +composer.lock diff --git a/composer.json b/composer.json index 3d8403b..2f2001b 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "waylandace/bee-queue", + "name": "trungpv1601/bee-queue", "description": "PHP handler for bee-queue redis queue", "type": "library", "license": "MIT", @@ -13,9 +13,5 @@ "psr-4": { "Dynatech\\Libraries\\BeeQueue\\": "src/" } - }, - "minimum-stability": "stable", - "require": { - "php": "^7.2.0" } } diff --git a/composer.lock b/composer.lock deleted file mode 100644 index 985d350..0000000 --- a/composer.lock +++ /dev/null @@ -1,19 +0,0 @@ -{ - "_readme": [ - "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", - "This file is @generated automatically" - ], - "content-hash": "b13b5e322fe402cd0ee744637dfa4d48", - "packages": [], - "packages-dev": [], - "aliases": [], - "minimum-stability": "stable", - "stability-flags": [], - "prefer-stable": false, - "prefer-lowest": false, - "platform": { - "php": ">7.2.0" - }, - "platform-dev": [] -} diff --git a/src/Queue.php b/src/Queue.php index 4ce4bdb..141cbf9 100644 --- a/src/Queue.php +++ b/src/Queue.php @@ -31,9 +31,13 @@ public function __construct( } else { $redis['host'] = $redis['host'] ?? '127.0.0.1'; $redis['port'] = $redis['port'] ?? 6379; + $redis['password'] = $redis['password'] ?? false; $this->redis = new \Redis(); $this->redis->connect($redis['host'], $redis['port']); + if ($redis['password']) { + $this->redis->auth($redis['password']); + } } $this->settings = [ @@ -96,4 +100,31 @@ public function isStoreJobs(): bool { return $this->settings['storeJobs'] === true; } + + /** + * [destroy description] + * @return [type] [description] + */ + public function destroy() + { + $queueKeys = $this->redis->keys($this->settings['keyPrefix'] . '*'); + $this->redis->delete($queueKeys); + } + + /** + * [checkHealth description] + * @return [type] [description] + */ + public function checkHealth(): array + { + $results = [ + 'waiting' => $this->redis->lLen($this->toKey('waiting')) ?? 0, + 'active' => $this->redis->lLen($this->toKey('active')) ?? 0, + 'succeeded' => $this->redis->sCard($this->toKey('succeeded')) ?? 0, + 'failed' => $this->redis->sCard($this->toKey('failed')) ?? 0, + 'delayed' => $this->redis->zCard($this->toKey('delayed')) ?? 0, + 'newestJob' => $this->redis->get($this->toKey('id')) ?? 0, + ]; + return $results; + } }