etcd3 API - v2.0.0
    Preparing search index...

    Class Etcd3

    Etcd3 is a high-level interface for interacting and calling etcd endpoints. It also provides several lower-level clients for directly calling methods.

    import { Etcd3 } from 'etcd3';
    const client = new Etcd3();

    await client.put('foo').value('bar');
    console.log('foo is:', await client.get('foo').string());

    const keys = await client.getAll().prefix('f').strings();
    console.log('all keys starting with "f":', keys);

    await client.delete().all();

    Hierarchy (View Summary)

    Index
    • Frees resources associated with the client.

      Returns void

    • Creates a new Election instead. See more information on the Election class documentation.

      Parameters

      • name: string

        Name of the election in the etcd instance.

      • Optionalttl: number

        Lease TTL used in the election. This is the maximum time that a node which goes down can remain the leader before being automatically evicted.

      Returns Election

    • Resolves to an array of roles available in etcd.

      Returns Promise<Role[]>

    • Resolves to an array of users available in etcd.

      Returns Promise<User[]>

    • if() starts a new etcd transaction, which allows you to execute complex statements atomically. See documentation on the ComparatorBuilder for more information.

      Parameters

      • key: string | Buffer<ArrayBufferLike>
      • column: "Lease" | "Version" | "Create" | "Mod" | "Value"
      • cmp: "==" | "===" | ">" | "<" | "!=" | "!=="
      • value: string | number | Buffer<ArrayBufferLike>

      Returns ComparatorBuilder

    • lease() grants and returns a new Lease instance. The Lease is automatically kept alive for you until it is revoked. See the documentation on the Lease class for some examples.

      Parameters

      Returns Lease

    • lock() is a helper to provide distributed locking capability. See the documentation on the Lock class for more information and examples.

      Parameters

      • key: string | Buffer<ArrayBufferLike>

      Returns Lock

    • .mock() allows you to insert an interface that will be called into instead of calling out to the "real" service. unmock should be called after mocking is finished.

      For example:

      import { Etcd3 } from 'etcd3';
      const client = new Etcd3();

      client.mock({
      exec: async (service, method) => {
      if (service === 'KV' && method === 'range') {
      return {
      header: { cluster_id: '0', member_id: '0', revision: '0', raft_term: '0' },
      kvs: [{ key: Buffer.from('foo'), value: Buffer.from('bar') }],
      more: false,
      count: '1',
      };
      }

      throw new Error(`Unexpected call: ${service}.${method}`);
      },
      });

      const output = await client.get('foo').string();
      console.log(output); // 'bar'
      client.unmock();

      Type Parameters

      Parameters

      • callable: T

      Returns T

    • namespace adds a prefix and returns a new Namespace, which is used for operating on keys in a prefixed domain. For example, if the current namespace is the default "" and you call namespace('user1/'), all operations on that new namespace will be automatically prefixed with user1/. See the Namespace class for more details.

      Parameters

      • prefix: string | Buffer<ArrayBufferLike>

      Returns Namespace

    • Returns an object to manipulate the role with the provided name.

      Parameters

      • name: string

      Returns Role

    • Removes any previously-inserted mock.

      Returns void

    • Returns an object to manipulate the user with the provided name.

      Parameters

      • name: string

      Returns User