avariya / etcd-php
v2.2.5
2017-03-30 09:41 UTC
Requires
- php: >=5.6.0
- guzzlehttp/guzzle: ^6.2
Requires (Dev)
- phpunit/phpunit: ~5.0
This package is not auto-updated.
Last update: 2022-02-01 13:02:25 UTC
README
PHP 的 Etcd 客户端库
etcd 是一个分布式配置系统,是 CoreOS 项目的核心部分。
此存储库为 PHP 应用程序提供 etcd 客户端库。
安装和运行 etcd
git clone https://github.com/coreos/etcd.git
cd etcd
./build
./bin/etcd
由 Printdeal 工程团队提供
这是基于 Linkorb 工程团队早期工作的贡献
使用方法
客户端
$client = new Client($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:watch /foo/bar