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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@mediar-ai/kv

v0.23.36

Published

State sharing and KV store for Terminator workflows

Downloads

2,265

Readme

@mediar-ai/kv

A lightweight, pluggable Key-Value store for Terminator workflows. This package enables state sharing between concurrent workflow executions, allowing for coordination, locking, and progress tracking.

Features

  • Pluggable Backends: Switch between Redis (production), File-system (local persistence), and Memory (testing) without changing code.
  • Unified API: Simple get, set, del API inspired by Vercel KV / Redis.
  • Atomic Operations: Supports NX (Not Exists) and XX (Already Exists) for locking.
  • Zero Config: Defaults to a local file-based store if no configuration is provided.

Installation

npm install @mediar-ai/kv

Usage

Basic Example

import { kv } from '@mediar-ai/kv';

async function main() {
  // Set a value
  await kv.set('user:123', 'Alice');

  // Get a value
  const user = await kv.get('user:123');
  console.log(user); // 'Alice'

  // Atomic Lock (useful for preventing race conditions)
  const acquired = await kv.set('lock:resource:A', 'locked', { nx: true, ex: 60 });
  
  if (acquired) {
    try {
      console.log('Lock acquired, doing work...');
    } finally {
      await kv.del('lock:resource:A');
    }
  } else {
    console.log('Could not acquire lock.');
  }
}

List Operations (Queues)

await kv.lpush('queue:invoices', 'inv_001', 'inv_002');
const nextItem = await kv.rpop('queue:invoices');

Hash Operations

await kv.hset('invoice:inv_001', {
  status: 'processing',
  amount: 100.50,
  vendor: 'Acme Corp'
});

const status = await kv.hget('invoice:inv_001', 'status');
const allData = await kv.hgetall('invoice:inv_001');

Configuration

The client automatically detects the configuration based on environment variables or defaults.

Environment Variables

Set KV_URL or REDIS_URL to configure the backend.

  • Redis: redis://localhost:6379
  • File: file://./my-db.json
  • Memory: memory://

Manual Initialization

You can also create a custom client instance:

import { createClient } from '@mediar-ai/kv';

// Redis
const redisKv = createClient({ url: 'redis://user:pass@host:6379' });

// File (Persistent local JSON file)
const fileKv = createClient({ url: 'file://./data/workflow-state.json' });

// Memory (Ephemeral, good for tests)
const memKv = createClient({ backend: 'memory' });

API Reference

  • set(key, value, { ex?, nx?, xx? }): Set value with optional TTL (seconds) and conditions.
  • get(key): Get string value.
  • del(key): Delete key.
  • expire(key, seconds): Set expiry on existing key.
  • incr(key): Increment integer value.
  • lpush(key, ...elements): Prepend to list.
  • rpush(key, ...elements): Append to list.
  • lpop(key): Remove and return first element.
  • rpop(key): Remove and return last element.
  • hset(key, field, value) or hset(key, object): Set hash fields.
  • hget(key, field): Get hash field.
  • hgetall(key): Get all fields in hash.
  • hincrby(key, field, increment): Increment hash field.

License

MIT