Client for 'etcd', a 'Key-value' Database

Client to interact with the 'etcd' 'key-value' data store < https://github.com/coreos/etcd>. Functions included for managing directories, keys, nodes, and getting statistics.


Build Status

etcd R client

etcd is a key-value DB written in Go. It has an HTTP API, which this R package wraps.

etcd API docs

Development follows closely the newest version of etcd released by the Coreos folks. As of 2016-09-07 that's etcd v3.0.7

See the etcd Github repo for help on installing etcd.

There are various ways to install it, and they depend on your operating sytsem.

You can install via homebrew, install from source, and via Docker.

Start etcd

at the command line

etcd

Installing etseed

Install etseed

install.packages("etseed")

Development version

install.packages("devtools")
devtools::install_github("ropensci/etseed")
library("etseed")

Make a client

First task when using this package is to initialize a client with the etcd() function. it's a wrapper around an R6 class.

(client <- etcd())
#> <etcd client>
#>   host: 127.0.0.1
#>   port: 2379
#>   api_version: v2
#>   scheme: http
#>   allow redirect: TRUE

Default settings in etcd() connect you to localhost, and port 2379, using etcd API version 2, with an http scheme.

Get version

client$version()
#> $etcdserver
#> [1] "3.0.7"
#> 
#> $etcdcluster
#> [1] "3.0.0"

Create a directory

client$create("/neighbor", dir = TRUE)
#> $action
#> [1] "set"
#> 
#> $node
#> $node$key
#> [1] "/neighbor"
#> 
#> $node$dir
#> [1] TRUE
#> 
#> $node$modifiedIndex
#> [1] 156
#> 
#> $node$createdIndex
#> [1] 156

Create a key

client$create(key = "/mykey", value = "this is awesome")
#> $action
#> [1] "set"
#> 
#> $node
#> $node$key
#> [1] "/mykey"
#> 
#> $node$value
#> [1] "this is awesome"
#> 
#> $node$modifiedIndex
#> [1] 158
#> 
#> $node$createdIndex
#> [1] 158

Use ttl parameter to make it dissappear after x seconds

client$create(key = "/stuff", value = "tables", ttl = 5)
#> $action
#> [1] "set"
#> 
#> $node
#> $node$key
#> [1] "/stuff"
#> 
#> $node$value
#> [1] "tables"
#> 
#> $node$expiration
#> [1] "2016-09-07T17:21:08.993528228Z"
#> 
#> $node$ttl
#> [1] 5
#> 
#> $node$modifiedIndex
#> [1] 159
#> 
#> $node$createdIndex
#> [1] 159

And the key will be gone after 5 seconds, see:

client$key("/stuff")
#> Error in etcd_GET(sprintf("%s%s/%s/", etcdbase(), "keys", key), ...) :
#>   client error: (404) Not Found

Update a key

Create a key

client$create(key = "/foo", value = "bar")
#> $action
#> [1] "set"
#> 
#> $node
#> $node$key
#> [1] "/foo"
#> 
#> $node$value
#> [1] "bar"
#> 
#> $node$modifiedIndex
#> [1] 161
#> 
#> $node$createdIndex
#> [1] 161

Then update the key

client$update(key = "/foo", value = "bar stool")
#> $action
#> [1] "set"
#> 
#> $node
#> $node$key
#> [1] "/foo"
#> 
#> $node$value
#> [1] "bar stool"
#> 
...

Create in-order keys

client$create_inorder("/queue", "thing1")
#> $action
#> [1] "create"
#> 
#> $node
#> $node$key
#> [1] "/queue/00000000000000000163"
#> 
#> $node$value
#> [1] "thing1"
#> 
#> $node$modifiedIndex
#> [1] 163
#> 
#> $node$createdIndex
#> [1] 163
client$create_inorder("/queue", "thing2")
#> $action
#> [1] "create"
#> 
#> $node
#> $node$key
#> [1] "/queue/00000000000000000164"
#> 
#> $node$value
#> [1] "thing2"
#> 
#> $node$modifiedIndex
#> [1] 164
#> 
#> $node$createdIndex
#> [1] 164
client$create_inorder("/queue", "thing3")
#> $action
#> [1] "create"
#> 
#> $node
#> $node$key
#> [1] "/queue/00000000000000000165"
#> 
#> $node$value
#> [1] "thing3"
#> 
#> $node$modifiedIndex
#> [1] 165
#> 
#> $node$createdIndex
#> [1] 165

List keys

client$keys()
#> $action
#> [1] "get"
#> 
#> $node
#> $node$dir
#> [1] TRUE
#> 
#> $node$nodes
#> $node$nodes[[1]]
#> $node$nodes[[1]]$key
...

List a key

client$key("/mykey")
#> $action
#> [1] "get"
#> 
#> $node
#> $node$key
#> [1] "/mykey"
#> 
#> $node$value
#> [1] "this is awesome"
#> 
#> $node$modifiedIndex
#> [1] 158
#> 
#> $node$createdIndex
#> [1] 158

Meta

ropensci_footer

News

etseed 0.1.0

NEW FEATURES

  • Released to CRAN.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("etseed")

0.1.0 by Scott Chamberlain, 3 years ago


https://github.com/ropensci/etseed


Report a bug at https://github.com/ropensci/etseed/issues


Browse source code at https://github.com/cran/etseed


Authors: Scott Chamberlain [aut, cre]


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports httr, jsonlite, R6

Suggests roxygen2, knitr, testthat


Suggested by nodbi.


See at CRAN