Etcd::Keys - etcd key space API
version 0.004
use Etcd; my $etcd = Etcd->new; # set value for key $etcd->set("/message", "hello world"); # get key my $response = $etcd->get("/message"); # delete key $etcd->delete("/message"); # atomic compare-and-swap value for key $etcd->compare_and_swap("/message", "new", "old"); # atomic compare-and-delete key $etcd->compare_and_delete("/message", "old"); # create key. like set, but fails if the key exists $etcd->create("/message", "value"); # update key. like set, but fails if the key doesn't exist $etcd->update("/message", "value"); # check if key exists my $exists = $etcd->exists("/message"); # create dir, a "valueless" key to hold subkeys $etcd->create_dir("/dir"); # delete key and everything under it $etcd->delete_dir("/dir"); # atomically create in-order key $etcd->create_in_order("/dir", "value"); # block until key changes $etcd->watch("/message");
This module provides access to etcd's key space API. The methods here map almost exactly to operations described in the etcd API documentation. See "SEE ALSO" in Etcd for further reading.
All methods except exists returns a Etcd::Response object on success and die on error. On error, $@ will contain either a reference to a Etcd::Error object (for API-level errors) or a regular string (for network, transport or other errors).
exists
die
$@
All methods can take any number of additional arguments in key => value form. These are added to the query parameters in the URL that gets submitted to etcd. This is how you would pass options for ttl or recursive, for example.
key => value
ttl
recursive
Any arguments of this kind that clash with the internal operation of a method will silently be ignored; for example, passing a value key to set will be ignored because that's how the value is passed internally.
value
set
$etcd->set("/message", "hello world");
Set a value for a key. The key will be created if it doesn't exist.
This invokes the PUT method for the given key.
PUT
get
my $node = $etcd->get("/message");
Get a key.
This invokes the GET method for the given key.
GET
delete
$etcd->delete("/message");
Delete a key.
This invokes the DELETE method for the given key.
DELETE
compare_and_swap
$etcd->compare_and_swap("/message", "new", "old");
Atomic compare-and-swap the value of a key.
This invokes the PUT method for the given key with the prevValue query parameter.
prevValue
compare_and_delete
$etcd->compare_and_delete("/message", "old");
Atomic compare-and-delete the value of a key.
This invokes the DELETE method for the given key with the prevValue query parameter.
create
$etcd->create("/message", "value");
Create a key. Like set, but fails if the key exists.
This invokes the PUT method for the given key with the prevExist query parameter set to false.
prevExist
false
update
$etcd->update("/message", "value");
Update the value of a key. Like set, but fails if the key doesn't exist.
This invokes the PUT method for the given key with the prevExist query parameter set to true.
true
my $exists = $etcd->exists("/message");
Check if key exists. Unlike the other methods, it does not return a reference to a Etcd::Response object but insteads returns a true or false value. It may still throw an error.
create_dir
$etcd->create_dir("/dir");
Creates a directory, a "valueless" key to hold sub-keys.
This invokes the PUT method for the given key with the dir query parameter set to true.
dir
delete_dir
$etcd->delete_dir("/dir");
Deletes a key and all its sub-keys.
This invokes the DELETE method for the given key with the dir query parameter set to true.
$etcd->create_in_order("/dir", "value");
Atomically creates an in-order key.
This invokes the POST method for the given key.
POST
watch
$etcd->watch("/message");
Block until the given key changes, then return the change.
This invokes the GET method for the given key with the wait query parameter set to true.
wait
There is no convenient way to specify the prevIndex test to compare_and_swap or compare_and_delete. These can be implemented directly with set.
prevIndex
watch has no asynchronous mode.
See "SUPPORT" in Etcd for information on how to report bugs or feature requests.
Robert Norris <rob@eatenbyagrue.org>
This software is copyright (c) 2014 by Robert Norris.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Etcd, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Etcd
CPAN shell
perl -MCPAN -e shell install Etcd
For more information on module installation, please visit the detailed CPAN module installation guide.