An in-memory data store that is API-compatible with Redis and Memcached, aiming to be a drop-in replacement for both.
microlinkhq/keyvhq
A Node.js key-value storage library with TTL expiry and pluggable backends such as Redis, MongoDB, SQLite and PostgreSQL.
- Stars
- 446
- Forks
- 20
- Open issues
- 0
- Last commit
- 2 months ago
What is it?
Keyv is a small Node.js library for storing key-value pairs with optional time-to-live expiry. By default it keeps data in an in-memory Map, and you can swap in a storage adapter to persist data to databases such as Redis, MongoDB, MySQL, PostgreSQL, SQLite, or a file. Any object that implements the Map API can also be used as the store.
The API is Promise-based and covers set, get, has, delete, and clear, with namespaces that let several instances share one database without key collisions or clearing each other's data. It serializes all JSON types plus Buffer values, and allows a custom serialize and deserialize pair for other data types. Database errors are handled so that a failing store does not crash the application.
The project also provides decorators such as compression, max-size limits, memoization, multi-store chaining, and metrics collection. Its design makes it easy for other modules to accept a cache option and pass it through to Keyv.
Key features
- 01Stores data in memory by default and supports many database adapters.
- 02Supports per-key and default TTL expiry.
- 03Namespaces isolate keys within a shared backend and allow clearing a single namespace.
- 04Handles all JSON types and Buffer values out of the box.
- 05Accepts custom serialize and deserialize functions.
- 06Works with any object implementing the Map API as a store.
Use cases
- Adding a TTL-based cache to a Node.js application backed by Redis or another database.
- Caching HTTP responses in a client library, as shown with the got example.
- Storing persistent key-value data in SQLite or PostgreSQL without writing a custom data layer.
- Embedding cache support in a reusable npm module that lets users supply their own store.
Quick start
- 1
Install the core package
npm install @keyvhq/core --save - 2
Optionally install a storage adapter, such as Redis
npm install @keyvhq/redis --save - 3
Create a Keyv instance and set, get and delete a key
Things to know
- Several features and adapters depend on external databases or services such as Redis, MongoDB or PostgreSQL that you must run yourself.
Topics
FAQ
- What is keyvhq?
- A Node.js key-value storage library with TTL expiry and pluggable backends such as Redis, MongoDB, SQLite and PostgreSQL. Keyv is a small Node.js library for storing key-value pairs with optional time-to-live expiry. By default it keeps data in an in-memory Map, and you can swap in a storage adapter to persist data to databases such as Redis, MongoDB, MySQL, PostgreSQL, SQLite, or a file. Any object that implements the Map API can also be used as the store.
- Is keyvhq free to use? What license does it have?
- keyvhq is open source under the MIT license. Check the license terms before using it in commercial products.
- Is keyvhq still maintained?
- Updated within 6 months. The last commit to keyvhq was on Aug 27, 2026.
- What can I use keyvhq for?
- Adding a TTL-based cache to a Node.js application backed by Redis or another database. Caching HTTP responses in a client library, as shown with the got example. Storing persistent key-value data in SQLite or PostgreSQL without writing a custom data layer. Embedding cache support in a reusable npm module that lets users supply their own store.
- How do I install keyvhq?
- Install the core package: npm install @keyvhq/core --save Optionally install a storage adapter, such as Redis: npm install @keyvhq/redis --save Create a Keyv instance and set, get and delete a key
- Where can I get keyvhq?
- The source code and installation instructions are on GitHub: https://github.com/microlinkhq/keyvhq
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
A high-performance, Redis-compatible key-value data structure server forked from Redis, aimed at caching and realtime workloads.
Java client for Valkey and Redis that adds distributed collections, locks, queues, and services on top of the base commands.
Node.js forum software with real-time discussions, backed by Redis, MongoDB or PostgreSQL.
An embeddable, persistent key-value database written in pure Go, with ACID transactions and SSD-oriented design.
Hugging Face library for Parameter-Efficient Fine-Tuning (PEFT), adapting large pretrained models by training only a small set of extra parameters.