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

keyv-aerospike

v1.0.1

Published

Aerospike storage adapter for Keyv

Readme

keyv-aerospike

Aerospike storage adapter for Keyv — v1 / keyv-v5 line.

npm version License: MIT

Install

npm install keyv-aerospike aerospike keyv

aerospike and keyv are peer dependencies. The aerospike native addon requires Node 18+ and the system libyaml library (brew install libyaml on macOS, apt install libyaml-dev on Debian/Ubuntu).

Usage

Basic — pass a KeyvAerospike store to Keyv

import Keyv from 'keyv';
import { KeyvAerospike } from 'keyv-aerospike';

const keyv = new Keyv(new KeyvAerospike('aerospike://127.0.0.1:3000'));

await keyv.set('hello', 'world');
console.log(await keyv.get('hello')); // 'world'
await keyv.delete('hello');

Connection string form

The URL format is aerospike://[user:pass@]host:port[,host:port]?namespace=<ns>&set=<set>.

// Default aerospike namespace + set ("keyv"/"keyv"):
new KeyvAerospike('aerospike://127.0.0.1:3000');

// Custom aerospike namespace and set (query-param form):
new KeyvAerospike('aerospike://127.0.0.1:3000?namespace=mynamespace&set=myset');

// Multiple seed hosts with credentials:
new KeyvAerospike('aerospike://user:[email protected]:3000,10.0.0.2:3000?namespace=mynamespace');

Config-object form

import { KeyvAerospike } from 'keyv-aerospike';

const store = new KeyvAerospike({
  hosts: [{ addr: '127.0.0.1', port: 3000 }],
  aerospikeNamespace: 'keyv',
  set: 'keyv',
  namespace: 'myapp',       // keyv prefix namespace
  clearBatchSize: 1000,
});

createKeyv helper

createKeyv builds the Keyv instance in one call:

import { createKeyv } from 'keyv-aerospike';

const keyv = createKeyv(
  { hosts: [{ addr: '127.0.0.1', port: 3000 }] },
  { namespace: 'myapp', throwOnErrors: true }
);

await keyv.set('key', 'value', 60_000); // expires in 60s

Error handling

By default the adapter emits "error" events (Keyv listens to them). To throw instead:

const store = new KeyvAerospike({ hosts: [...], throwOnErrors: true });
store.on('error', (err) => console.error(err));

Options

| Option | Type | Default | Description | |---|---|---|---| | namespace | string | undefined | Keyv key-prefix namespace. Keys from different namespaces do not collide. | | aerospikeNamespace | string | "keyv" | Aerospike database namespace (must be declared in aerospike.conf). | | set | string | "keyv" | Aerospike set name within the namespace. | | clearBatchSize | number | 1000 | Records deleted per batch during clear(). | | noNamespaceAffectsAll | boolean | false | When true, calling clear() on a store with no namespace issues a fast truncate — removes all records in the set. Use with caution. | | throwOnErrors | boolean | false | Throw on Aerospike errors instead of emitting "error" and returning undefined/false. | | throwOnConnectError | boolean | true | Throw when the initial connection to Aerospike fails. | | connectionTimeout | number | — | Connection timeout in milliseconds, mapped to the Aerospike client's connTimeoutMs. |

TTL behavior

  • TTLs are passed as seconds to Aerospike (Math.ceil(ttl / 1000)), minimum 1 s.
  • TTL 0 or no TTL stores the record with NEVER_EXPIRE.
  • Aerospike evicts expired records server-side; no application-side expiry is needed.

Iteration

store.iterator(namespace?) works directly and yields [key, value] pairs filtered to the given namespace.

To iterate the Keyv instance (keyv.iterator() or for await (const [key, value] of keyv)), create it with createKeyv():

import { createKeyv } from 'keyv-aerospike';

const keyv = createKeyv('aerospike://localhost:3000', { namespace: 'app' });
await keyv.set('a', 1);
for await (const [key, value] of keyv.iterator()) {
  console.log(key, value);
}

createKeyv() wires iteration explicitly. Note: keyv core only auto-wires keyv.iterator() for adapters in its built-in iterableAdapters allowlist (which omits aerospike), so a manually-constructed new Keyv(new KeyvAerospike(...)) does not support keyv.iterator() — use createKeyv() or call store.iterator() directly.

Running tests

On the host (requires a running Aerospike server)

# Start Aerospike via Docker Compose
npm run test:services:start

# Full pipeline
npm run build && npm run typecheck && npm run lint && npm test

Entirely in Docker (no local Node or libyaml needed)

docker compose run --rm test

This boots the aerospike service (with this repo's aerospike.conf, which declares the keyv namespace), waits until it is healthy, then runs npm ci && npm run build && npm run lint && npm run typecheck && npm test inside a Node 24 container.

License

MIT — see LICENSE.