Code Monkey home page Code Monkey logo

etcd-php's Introduction

Build Status Latest Stable Version Total Downloads Latest Unstable Version License

Etcd client library for PHP

etcd is a distributed configuration system, part of the coreos project.

This repository provides a client library for etcd for PHP applications.

Installing and running etcd

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

Brought to you by the LinkORB Engineering team

Check out our other projects at linkorb.com/engineering.

Btw, we're hiring!

Installation

composer require linkorb/etcd-php

Usage

The client

Instantiate the client

$client = new Client($server);

Instantiate the client with custom Guzzle Client

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

Use the client instance

$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');    

The command line tool

Setting Key Values

Set a value on the /foo/bar key:

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

Set a value on the /foo/bar key with a value that expires in 60 seconds:

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

Create a new key /foo/bar, only if the key did not previously exist:

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

Create a new dir /fooDir, only if the key did not previously exist:

$ bin/etcd-php etcd:mkdir /fooDir

Update an existing key /foo/bar, only if the key already existed:

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

Create or update a directory called /mydir:

$ bin/etcd-php etcd:setDir /mydir

Retrieving a key value

Get the current value for a single key in the local etcd node:

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

Listing a directory

Explore the keyspace using the ls command

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

Add -recursive to recursively list subdirectories encountered.

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

Deleting a key

Delete a key:

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

Delete an empty directory or a key-value pair

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

Recursively delete a key and all child keys:

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

Export node

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

Watching for changes

Watch for only the next change on a key:

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

etcd-php's People

Contributors

agoosev avatar congpeijun avatar gfyrag avatar jet-desk avatar joostfaassen avatar leesaferite avatar pataquets avatar robberphex avatar sammarks avatar tinywan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

etcd-php's Issues

License

Could you include a license with this project?

Trying to watch directory listing with wait indexes

Hi. I was experimenting with this library, but I hit a problem. I would like to watch a directory and get a list of all the keys in it whenever a key is added or removed.

First, the listDir() function does not accept a wait index. Other functions allow an optional array of query parameters to be added, but not the listDir() function.

Second, the modifyIndex of a directory does not change when you create keys in it, so I could not use that. Reading etcd-io/etcd#603 it appears you have to use the x-etcd-index header to get the index to watch on. How hard would it be to get that included in the response?

Thanks!

Support symfony/console v6?

I can't use linkorb/etcd-php after upgrade laravel to 9, because laravel 9 use symfony/console v6 (and laravel 8 use symfony/console v5).
Could you support symfony/console v6 or v5? Thank you.

etcd Auth Not Supported

Thanks for creating this library, it's pretty close to exactly what we need. Unfortunately, after reviewing the documentation and code, it appears that authentication to etcd is not supported by this client. Guzzle supports basic auth (http://docs.guzzlephp.org/en/5.3/clients.html#auth), but it doesn't look like this can be passed into the Client class.

Is this something on your roadmap or is there a work around that you suggest?

Reduce coupling with Symfony components

It's good that it is possible to work with etcd from the console (Symfony Console Component). But does everyone need this? Does everyone who wants to work with etcd develop their projects on Symfony? Does everyone need a Symfony dependency?

It is considered good practice to move optional features into a separate repository or make an optional dependency (require-dev and suggest) rather than a strict one (require).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.