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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@sora-soft/etcd-component

v2.2.3

Published

sora system etcd component

Readme

@sora-soft/etcd-component

基于 etcd3 的 etcd 组件,封装了 etcd 客户端连接、Lease 管理、分布式锁和 Leader 选举等功能,作为 sora 框架的基础设施组件使用。

安装

sora add:component @sora-soft/etcd-component

功能说明

  • 封装 etcd3 客户端,提供统一的生命周期管理(loadOptionsstartstop
  • 内置 Lease 管理,支持自动续约和断线重连后重新注册
  • 提供分布式锁(lock),基于 etcd 原生锁实现
  • 提供 persistPut / persistDel 等持久化 KV 操作
  • 提供 EtcdElection 用于基于 etcd 的 Leader 选举
  • 支持可配置的 key 前缀,方便多环境隔离

使用方法

注册并启动组件

import { EtcdComponent } from '@sora-soft/etcd-component';
import { Runtime } from '@sora-soft/framework';

const etcd = new EtcdComponent();
Runtime.registerComponent('etcd', etcd);
etcd.loadOptions({
  etcd: { hosts: 'http://127.0.0.1:2379' },
  ttl: 30,
  prefix: '/myapp',
});
await etcd.start();

KV 操作

await etcd.persistPut('/config/key', 'value');
const value = await etcd.client.get('/myapp/config/key').string();
await etcd.persistDel('/config/key');

使用 Key 前缀

const fullKey = etcd.keys('config', 'database', 'host');
// 结果: /myapp/config/database/host

分布式锁

await etcd.lock('my-lock', async (lock) => {
  // 临界区操作
}, 5000);

Leader 选举

import { EtcdElection } from '@sora-soft/etcd-component';

const election = new EtcdElection(etcd);
await election.campaign('node-1');
const isLeader = election.leader();
election.observer().subscribe((leader) => {
  console.log('当前 Leader:', leader);
});