Keyv is a small Node-friendly key-value API with TTL support, defaulting to memory and switching to Redis, Postgres, SQLite, MongoDB, and other adapters.
Overview
Keyv is a compact, promise-based key-value store for JavaScript runtimes. The same application API works whether data lives in memory or in an external database, so you can start with an in-memory cache and later point the store option at a persistent adapter.
Keys are strings; values are JSON-serializable data, with Buffer and BigInt supported by the built-in serializer. Operations include get, set, has, delete, optional TTL on set and default instance TTL, and namespaces to isolate key sets on a shared backend.
Official storage adapters cover Redis, Valkey, MongoDB, SQLite, PostgreSQL, MySQL, Etcd, Memcache, DynamoDB, and Cloudflare KV, plus in-memory Map or LRU wrappers. Optional compression, encryption, superjson or msgpack serialization, sanitization hooks, and before/after hooks extend the core package.
The project notes adoption as the storage layer behind Cacheable, cache-manager, NestJS caching, and HTTP caching in got and cacheable-request. It runs on Node.js, Bun, and in browsers when configured appropriately.
Key features
- Unified get set has delete API
- TTL per key and defaults
- Many official storage adapters
- Built-in JSON serializer
- Namespace key isolation
- Optional encryption adapters
- Hook and event telemetry
- TypeScript generic value typing
Use cases
- Application caching layers
- Session storage abstraction
- NestJS cache integration
- Multi-store cache-manager setups
- HTTP response caching backends