woodw/etcd-php

PHP 的 Etcd 客户端库

dev-master 2024-04-09 07:50 UTC

This package is auto-updated.

Last update: 2024-09-09 10:38:47 UTC


README

Build Status Latest Stable Version Total Downloads Latest Unstable Version License

PHP 的 Etcd 客户端库

etcd 是一个分布式配置系统,是 coreos 项目的一部分。

该仓库为 PHP 应用程序提供了 etcd 的客户端库。

安装和运行 etcd

git clone https://github.com/coreos/etcd.git
cd etcd
./build
./bin/etcd

由 LinkORB 工程团队提供

请访问我们的其他项目:linkorb.com/engineering

顺便说一句,我们在招聘!

安装

composer require linkorb/etcd-php

使用

客户端

实例化客户端

$client = new Client($server);

使用自定义 Guzzle Client 实例化客户端

$client = Client::constructWithGuzzleClient($guzzleClient, $server);

使用客户端实例

$client->set('/foo', 'fooValue');
// Set the ttl
$client->set('/foo', 'fooValue', 10);
// get key value
echo $client->get('/foo');

// Update value with key
$client->update('/foo', 'newFooValue');

// Delete key
$client->rm('/foo');

// Create a directory
$client->mkdir('/fooDir');
// Remove dir
$client->rmdir('/fooDir');    

命令行工具

设置键值

/foo/bar 键上设置值

$ bin/etcd-php etcd:set /foo/bar "Hello world"

/foo/bar 键上设置一个将在 60 秒后过期的值

$ bin/etcd-php etcd:set /foo/bar "Hello world" --ttl=60

仅当键之前不存在时创建新键 /foo/bar

$ bin/etcd-php etcd:mk /foo/new_bar "Hello world"

仅当键之前不存在时创建新目录 /fooDir

$ bin/etcd-php etcd:mkdir /fooDir

仅当键已存在时更新现有键 /foo/bar

$ bin/etcd-php etcd:update /foo/bar "Hola mundo"

创建或更新名为 /mydir 的目录

$ bin/etcd-php etcd:setDir /mydir

检索键值

获取本地 etcd 节点中单个键的当前值

$ bin/etcd-php etcd:get /foo/bar

列出目录

使用 ls 命令探索键空间

$ bin/etcd-php etcd:ls
/akey
/adir
$ bin/etcd-php etcd:ls /adir
/adir/key1
/adir/key2

添加 -recursive 递归列出遇到的子目录。

$ bin/etcd-php etcd:ls --recursive
/foo
/foo/bar
/foo/new_bar
/fooDir

删除键

删除键

$ bin/etcd-php etcd:rm /foo/bar

删除空目录或键值对

$ bin/etcd-php etcd:rmdir /path/to/dir 

递归删除键及其所有子键

$ bin/etcd-php etcd:rmdir /path/to/dir --recursive

导出节点

$ bin/etcd-php etcd:export --server=http://127.0.0.1:2379 --format=json --output=config.json /path/to/dir

监视更改

仅监视键的下一个更改

$ bin/etcd-php etcd:watch /foo/bar