Skip to content

Latest commit

 

History

History
113 lines (71 loc) · 2.79 KB

etcd.md

File metadata and controls

113 lines (71 loc) · 2.79 KB

Title

Intro.

etcd란

  1. simple interface
  2. key/value starage
  3. watch for changes

Install

OSX

$ curl -L  https://github.com/coreos/etcd/releases/download/v2.1.3/etcd-v2.1.3-darwin-amd64.zip -o etcd-v2.1.3-darwin-amd64.zip
$ unzip etcd-v2.1.3-darwin-amd64.zip
$ cd etcd-v2.1.3-darwin-amd64 
$ ./etcd

Open another terminal:

$ ./etcdctl set mykey "this is awesome"
this is awesome
$ ./etcdctl get mykey
this is awesome

OSX Homebrew

$ brew install etcd
$ etcd

Open another terminal:

$ etcdctl set mykey "this is awesome"
this is awesome
$ etcdctl get mykey
this is awesome

Install

For nodejs >= 0.10 and iojs:

$ npm install node-etcd

For nodejs == 0.8:

$ npm install node-etcd@3.0.2

Methods

Basic usage

Etcd = require('node-etcd');
etcd = new Etcd();
etcd.set('key', 'value');
etcd.get('key', console.log);
etcd.del('key', console.log);

.set(key, value, [options], [callback])

etcd.set('key', 'value', {ttl: 5}, console.log);
  • ttl (time to live in seconds)

.create(path, value, [options], [callback])

Atomically create in-order keys.

etcd.create('queue', 'first');
etcd.create('queue', 'next', console.log);

.watcher(key, [index], [options])

Returns an eventemitter for watching for changes on a key

watcher = etcd.watcher('key');
watcher.on('change', console.log); // Triggers on all changes

You can cancel a watcher by calling .stop().

Signals:

  • change - emitted on value change
  • reconnect - emitted on reconnect
  • error - emitted on invalid content
  • <etcd action> - the etcd action that triggered the watcher (ex: set, delete, expire).
  • stop - watcher was canceled.
  • resync - watcher lost sync (server cleared and outdated the index).

Use the .watch() command in you need more direct control.

Node.js and MySQL for Auto-Recovery System

  1. get
  2. watcher instance
  3. etcd 초기화(setup, notify, connect)
  4. watcher 작성
  5. test

REFERENCE