vajexal / amp-zookeeper
Zookeeper client for amphp
0.1.3
2021-05-26 16:32 UTC
Requires
- php: ^8.0
- ext-mbstring: *
- amphp/log: ^1.1
- amphp/socket: ^1.1
- league/uri: ^6.4
Requires (Dev)
- amphp/php-cs-fixer-config: dev-master
- amphp/phpunit-util: ^1.4
- symfony/var-dumper: ^5.2
This package is auto-updated.
Last update: 2025-03-27 00:41:20 UTC
README
Installation
composer require vajexal/amp-zookeeper
Usage
<?php declare(strict_types=1); use Amp\Loop; use Vajexal\AmpZookeeper\Zookeeper; use Vajexal\AmpZookeeper\ZookeeperConnector; require_once 'vendor/autoload.php'; Loop::run(function () { /** @var Zookeeper $zk */ $zk = yield (new ZookeeperConnector)->connect(); yield $zk->create('/foo', 'bar'); var_dump(yield $zk->get('/foo')); yield $zk->set('/foo', 'baz'); var_dump(yield $zk->get('/foo')); var_dump(yield $zk->getChildren('/')); yield $zk->delete('/foo'); var_dump(yield $zk->exists('/foo')); yield $zk->close(); });
Watches
<?php declare(strict_types=1); use Amp\Loop; use Vajexal\AmpZookeeper\Proto\WatcherEvent; use Vajexal\AmpZookeeper\Zookeeper; use Vajexal\AmpZookeeper\ZookeeperConnector; require_once 'vendor/autoload.php'; Loop::run(function () { /** @var Zookeeper $zk */ $zk = yield (new ZookeeperConnector) ->watcher(function (WatcherEvent $event) { var_dump($event); }) ->connect(); yield $zk->create('/foo', 'bar'); yield $zk->get('/foo', true); yield $zk->delete('/foo'); yield $zk->close(); });
Persistent watch can be added using addWatch
method
Ephemeral Nodes
<?php declare(strict_types=1); use Amp\Loop; use Vajexal\AmpZookeeper\CreateMode; use Vajexal\AmpZookeeper\Zookeeper; use Vajexal\AmpZookeeper\ZookeeperConnector; require_once 'vendor/autoload.php'; Loop::run(function () { /** @var Zookeeper $zk */ $zk = yield (new ZookeeperConnector)->connect(); yield $zk->create('/foo', 'bar', CreateMode::EPHEMERAL); var_dump(yield $zk->getEphemerals()); yield $zk->close(); /** @var Zookeeper $zk */ $zk = yield (new ZookeeperConnector)->connect(); var_dump(yield $zk->exists('/foo')); $zk->close(); });
Sequential Nodes
<?php declare(strict_types=1); use Amp\Loop; use Vajexal\AmpZookeeper\CreateMode; use Vajexal\AmpZookeeper\Zookeeper; use Vajexal\AmpZookeeper\ZookeeperConnector; require_once 'vendor/autoload.php'; Loop::run(function () { /** @var Zookeeper $zk */ $zk = yield (new ZookeeperConnector)->connect(); yield $zk->create('/foo', 'bar', CreateMode::EPHEMERAL_SEQUENTIAL); var_dump(yield $zk->getChildren('/')); yield $zk->close(); });