Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Etcd

etcd client using the grpc protocol of etcd version 3 and later.

Hierarchy

  • Etcd

Index

Constructors

constructor

  • Creates a new etcd client.

    Parameters

    • Default value servers: string[] = [ "localhost:2379" ]

      array of etcd hosts to use

      Note: currently only the first server is used, this will be fixed before version 1

    • Default value options: EtcdOptions = {}

      additional options, see defaults for actual defaults

    Returns Etcd

Properties

clientLease

clientLease: string

clientLeasePromise

clientLeasePromise: Promise<string>

clientLeaseToken

clientLeaseToken: KeepAliveToken

clients

clients: any

credentials

credentials: any = grpc.credentials.createInsecure()

keepAlives

keepAlives: KeepAliveToken[] = []

KeepAliveToken's created by this client

options

options: EtcdOptions

servers

servers: string[]

Methods

Private callClient

  • callClient(client: any, method: any, arg: any): Promise<any>
  • Parameters

    • client: any
    • method: any
    • arg: any

    Returns Promise<any>

Private callClientStream

  • callClientStream(client: any, method: any): any
  • Parameters

    • client: any
    • method: any

    Returns any

close

  • close(): void
  • closes the network connection and stops all keep alives started with this client.

    Returns void

delete

  • delete(key: string, keyTo?: string): Promise<number>
  • delete a key from etcd.

    Parameters

    • key: string

      key to start from (inclusive)

    • Optional keyTo: string

      key to end on (exclusive)

    Returns Promise<number>

    number of keys deleted

deleteSync

  • deleteSync(key: string, keyTo?: string): number
  • blocking version of delete()

    see

    delete

    Parameters

    • key: string
    • Optional keyTo: string

    Returns number

get

  • get(key: string, returnType?: "value"): Promise<string>
  • get(key: string, returnType: "json"): Promise<any>
  • get(key: string, returnType: "buffer"): Promise<Buffer>
  • get(key: string, returnType: "raw"): Promise<EtcdKV>
  • get the value of a key from etcd

    Parameters

    • key: string

      key to get

    • Optional returnType: "value"
      • value (default) - return the as a string
      • json - parse as JSON and return the result
      • buffer - return a NodeJS Buffer
      • raw - return the value as it came from etcd

    Returns Promise<string>

    value of the key as defined by returnType

  • get the value of a key from etcd

    Parameters

    • key: string

      key to get

    • returnType: "json"
      • value (default) - return the as a string
      • json - parse as JSON and return the result
      • buffer - return a NodeJS Buffer
      • raw - return the value as it came from etcd

    Returns Promise<any>

    value of the key as defined by returnType

  • get the value of a key from etcd

    Parameters

    • key: string

      key to get

    • returnType: "buffer"
      • value (default) - return the as a string
      • json - parse as JSON and return the result
      • buffer - return a NodeJS Buffer
      • raw - return the value as it came from etcd

    Returns Promise<Buffer>

    value of the key as defined by returnType

  • get the value of a key from etcd

    Parameters

    • key: string

      key to get

    • returnType: "raw"
      • value (default) - return the as a string
      • json - parse as JSON and return the result
      • buffer - return a NodeJS Buffer
      • raw - return the value as it came from etcd

    Returns Promise<EtcdKV>

    value of the key as defined by returnType

Private getBuffer

  • getBuffer(obj: any): Buffer

getClientLease

  • getClientLease(): Promise<string>
  • get the managed client lease. If it isn't created yet, it will be created. The Client lease will be kept alive automatic.

    Returns Promise<string>

    lease ID

getSync

  • getSync(key: string, returnType?: "value"): string
  • getSync(key: string, returnType: "json"): any
  • getSync(key: string, returnType: "buffer"): Buffer
  • getSync(key: string, returnType: "raw"): EtcdKV
  • blocking version of get()

    Parameters

    • key: string
    • Optional returnType: "value"

    Returns string

  • blocking version of get()

    Parameters

    • key: string
    • returnType: "json"

    Returns any

  • blocking version of get()

    Parameters

    • key: string
    • returnType: "buffer"

    Returns Buffer

  • blocking version of get()

    Parameters

    • key: string
    • returnType: "raw"

    Returns EtcdKV

leaseGrant

  • leaseGrant(ttl?: number): Promise<string>
  • request a new lease from etcd

    Parameters

    • Optional ttl: number

      requested TTL of the lease

    Returns Promise<string>

leaseGrantSync

  • leaseGrantSync(ttl: number): string

leaseKeepAlive

  • keep a lease alive

    Parameters

    • lease: string

      lease to keep alive

    • Default value interval: number = 1000

      interval in which to send keep alives

    Returns KeepAliveToken

    KeepAliveToken that was created

range

  • range(fromKey: string, toKey: string, returnType?: "value" | "json" | "buffer" | "raw"): Promise<any>
  • get a range of key from etcd

    Parameters

    • fromKey: string

      key to start from (inclusive)

    • toKey: string

      key to end on (exclusive)

    • Default value returnType: "value" | "json" | "buffer" | "raw" = "value"
      • value (default) - return the as a string
      • json - parse as JSON and return the result
      • buffer - return a NodeJS Buffer
      • raw - return the value as it came from etcd

    Returns Promise<any>

    object with a key for each key returned, value of the key as defined by returnType

rangeSync

  • rangeSync(fromKey: string, toKey: string, returnType?: "value" | "json" | "buffer" | "raw"): any
  • blocking version of range()

    see

    range

    Parameters

    • fromKey: string
    • toKey: string
    • Optional returnType: "value" | "json" | "buffer" | "raw"

    Returns any

set

  • set(key: string, value: any, lease?: number | string): Promise<string>
  • set a key/value to etcd.

    • a Buffer is saved as-is
    • null is saved as an empty string
    • undefined is saved as an empty string
    • strings are saved as-is
    • everything else is tried to JSON.stringify(value)

    if you set "lease" to "client" a lease uniq to the instance of the Client will be used. This lease will be created automatic and will be kept alive automatic.

    Parameters

    • key: string

      etcd key to set

    • value: any

      content to set

    • Optional lease: number | string

      lease ID to use, or client to the client lease

    Returns Promise<string>

    lease ID used if any was used, else null

setSync

  • setSync(key: string, value: any, lease?: number | string): string
  • blocking version of set()

    see

    set

    Parameters

    • key: string
    • value: any
    • Optional lease: number | string

    Returns string

Object literals

Static defaults

defaults: object

appLeaseKeepAlive

appLeaseKeepAlive: null = null

appLeaseTtl

appLeaseTtl: number = 10

Generated using TypeDoc