Registry / database / keyv
library5.6.0jsnpmunverified

Simple key-value storage with support for multiple backends. Current stable version is 5.6.0. Keyv provides a unified interface for various storage backends like Redis, MongoDB, SQLite, and more. It supports TTL, event-driven invalidation, and adapter-based architecture. Compared to alternatives like `node-cache`, Keyv offers pluggable storage backends while maintaining a consistent API. The package is actively maintained and includes TypeScript definitions.

npm install keyv
INSTALL
IMPORT
SIG · KEYV
K
keyv
databasejavascriptv5.6.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Keyv
import Keyv from 'keyv';
const { Keyv } = require('keyv');
Keyv is a default export. In CommonJS, use `const Keyv = require('keyv');`. Named import (`{ Keyv }`) is incorrect.
KeyvOptions
import type { KeyvOptions } from 'keyv';
interface KeyvOptions { ... }
Type import for TypeScript; not needed at runtime.
StoredData
import type { StoredData } from 'keyv';
type StoredData = { value: any; expires: number | null };
TypeScript type for stored data structure.

Initializes Keyv with a Redis backend, sets and retrieves a value, then deletes it.

import Keyv from 'keyv'; import KeyvRedis from '@keyv/redis'; const keyv = new Keyv({ store: new KeyvRedis('redis://localhost:6379'), ttl: 60000 }); await keyv.set('foo', 'bar'); const value = await keyv.get('foo'); console.log(value); // 'bar' await keyv.delete('foo');
Debug
Known issues
breakingKeyv v5 removed `adapter` export and changed store interface
fix
Use `@keyv/redis` or other adapter packages directly. Previously `KeyvRedis` was exported from Keyv itself.
affects: >=5.0.0
deprecatedKeyv v4 `opts.store` is now `opts.store` but store must implement new interface
fix
Upgrade to v5 and ensure custom stores implement `get`, `set`, `delete`, `clear`, `has` and `iterator` methods returning promises.
affects: >=4.0.0 <5.0.0
gotchaTTL unit is milliseconds, not seconds
fix
Always pass TTL in milliseconds. Use `60000` for 1 minute, not `60`.
affects: *
gotchaKeyv does not preserve object references; values are serialized
fix
Retrieved objects are clones. Mutating them after `get` will not update the stored value.
affects: *
deprecatedKeyv namespace option deprecated in v5
fix
Use separate instances or manually prefix keys. Namespace was removed in v5.
affects: >=5.0.0
Errors
Common errors & fixes
TypeError: Keyv is not a constructor
Default import used incorrectly or CommonJS require().default
fix
Use `import Keyv from 'keyv'` (ESM) or `const Keyv = require('keyv')` (CommonJS).
Error: store must implement `get` method
Custom store object missing required methods or adapter not properly initialized
fix
Ensure store implements `get`, `set`, `delete`, `clear`, `has`, `iterator` methods.
ReferenceError: KeyvRedis is not defined
Trying to use `KeyvRedis` without importing the adapter package
fix
Install and import `@keyv/redis` or other adapter package.
Upgrade
Version history
5.6.0latest on npm
Audit
Dependencies
@keyv/redisoptionalRedis storage backend adapter
@keyv/mongooptionalMongoDB storage backend adapter
@keyv/sqliteoptionalSQLite storage backend adapter
Agent activity
28 hits · last 30 days
node
26
Amazon
1
Resources
packagekeyv
keyv — npm install keyv · libregistry