npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@yunflyjs/yunfly-plugin-etcd

v0.0.2

Published

yunfly etcd plugin.

Downloads

3

Readme

@yunflyjs/yunfly-plugin-etcd

yunfly etcd plugin.

Usage

  1. install
yarn add @yunflyjs/yunfly-plugin-etcd
  1. declare plugins in config/config.plugin.ts
/**
 * yunfly plugin
 */
const plugins: {[key:string]: string}[] = [
  {
    name: 'etcd',
    package: '@yunflyjs/yunfly-plugin-etcd'
  }
];
// 
export default plugins;
  1. enable plugins in config/config.default.ts
config.etcd = {
  enable: true,
  url: '127.0.0.1:4001', // etcd server urls 
  // refresh: false,        // refresh the interval host list automatically
  // timeout: 60 * 1000,    // default timeout for ops
}
  • if you have more than run instance of etcd running you can pass an array to load balance.
config.etcd = {
  url: '127.0.0.1:4001, 127.0.0.1:4002, 127.0.0.1:4003', // etcd server urls 
}
  • you can also set urls through environment variables
// set env
process.env.ETCDV3_SERVER_URLS = '127.0.0.1:4001';
// cluster
process.env.ETCDV3_SERVER_URLS = '127.0.0.1:4001, 127.0.0.1:4002, 127.0.0.1:4003';

// etcd config
config.etcd = {
  enable: true,
  // refresh: false,        // refresh the interval host list automatically
  // timeout: 60 * 1000,    // default timeout for ops
}

API

import { etcd } from '@yunflyjs/yunfly-plugin-etcd';

etcd.getAllConfig

get all etcd config

import { etcd } from '@yunflyjs/yunfly-plugin-etcd';

const allConfig = await etcd.getAllConfig();

etcd.get(key, [opts])

get a etcd key.

  • option
{
  "json": boolean; // parse value as JSON for this request
}
  • example
// async/await
const result = await etcd.get('hello');

// use promise
etcd.get('hello').then( data => console.log('ge hello value',data));

// example result
'{"name": "zhangsan" ,"age" : 25 }'
  • return json
// async/await
const result = await etcd.get('hello',{ json: true });

// example result
{
  name: "zhangsan",
  age: 25
}

etcd.set(key, value, [opts])

set a etcd key.

  • option
{
  "json": boolean;
}
  • example
// async/await
const result = await etcd.set('hello','{"name": "zhangsan" ,"age" : 25 }');
  • set a JSON value
// async/await
const json = {"name": "zhangsan" ,"age" : 25 }
const result = await etcd.set('hello', json, { json: true });

etcd.update(key, value, [opts])

Set a key if it already exists. Same as set(key, value, {prevExists: true})

etcd.del(key, [opts])

Delete a key

const result = await etcd.del('hello');

etcd.wait(key, [cb])

Wait a key to change. Same as get(key, {wait: true}) except the callback is called with a third argument next that will wait for the next change.

etcd.wait('hello', function onchange (err: any, result: any, next: any) {
  console.log('change!', result);
  next(onchange); // next will set waitIndex so we do not miss events
});

etcd.mkdir(key, [cb])

Create a directory. Same as set(key, null, {dir: true})

etcd.rmdir(key, [cb])

Remove a directory. Same as del(key, {dir: true})

More Apis

use @npmcorp/etcdjs apis

  • example
etcd.store.destroy();
etcd.store.push(key, value, [opts], [cb])
etcd.store.compareAndSwap(key, value, prevValue, [opts], [cb])
......

中文文档

https://yunke-yunfly.github.io/doc.github.io/document/technology/etcd