nope-redis
v2.1.0
Published
Simple & Fast Node.JS memory caching
Downloads
413
Maintainers
Readme
nope-redis
Simple & Fast Node.js in-memory caching — Redis-like functionality without a Redis server.
- 🚀 Fast: 1M+ SET, 2M+ GET ops/sec with a flat heap under sustained load
- ⏰ TTL: automatic key expiration with eager cleanup on read
- 🔄 Eviction: LRU, LFU and TTL policies with a configurable memory limit (MB)
- 🎯 Batch operations, 📈 statistics, 🛡️ self-recovery, 📘 TypeScript types
- 🔌 Works with both ESM (
import) and CommonJS (require) — one shared cache instance - 🔧 Zero runtime dependencies — single file, Node.js ≥ 18
Install
npm install nope-redisQuick Start
Works with both CommonJS and ESM — both entry points share the same cache instance.
// CommonJS
const nopeRedis = require('nope-redis');
nopeRedis.setItem('user:1', { name: 'John', age: 30 }, 10); // TTL: 10s
const user = nopeRedis.getItem('user:1'); // { name: 'John', age: 30 } — null if missing/expired
nopeRedis.deleteItem('user:1');
// Optional runtime configuration
nopeRedis.config({ defaultTtl: 60, maxMemorySize: 100, evictionPolicy: 'lru' });// ESM — default and named imports are both supported
import nopeRedis, { setItem, getItem } from 'nope-redis';
setItem('user:1', { name: 'John', age: 30 }, 10);
const user = getItem('user:1');
nopeRedis.deleteItem('user:1'); // same singleton as the named importsTypeScript definitions are included (setItem<T>, getItem<T>, …).
API at a Glance
| Function | Description | Returns |
|----------|-------------|---------|
| setItem(key, value, ttl?) | Store any JS value (default TTL: 30s) | boolean |
| getItem(key) | Read a value | T \| null \| false |
| deleteItem(key) | Remove a key | boolean |
| itemStats(key) | Per-key expires_at, remaining_seconds, hit | ItemStats \| null \| false |
| setItems(items) | Bulk set [{ key, value, ttl? }] | boolean[] \| false |
| getItems(keys) | Bulk read | Record<string, T \| null> \| false |
| deleteItems(keys) | Bulk remove | boolean |
| stats(options?) | Cache-wide statistics (showSize for memory usage) | Stats \| false |
| config(options) | defaultTtl, maxMemorySize (MB), evictionPolicy, maxChecksPerCycle, isMemoryStatsEnabled | boolean |
| flushAll() | Clear all data, keep service running | boolean |
| SERVICE_KILL() / SERVICE_START() | Stop / restart the background service | Promise<boolean> |
All functions return false when the service is stopped. Full reference with examples: docs/README.md.
Performance
Node v24.18.0 · AMD EPYC 7763 64-Core Processor · linux x64 · 2026-07-15 — refreshed automatically by the Update README benchmarks workflow.
| Operation | ops/sec | ns/op | |-----------|--------:|------:| | SET (fresh string keys) | 2,281,928 | 438 | | SET (nested JSON, ~30 nodes) | 643,008 | 1,555 | | SET (overwrite existing keys) | 4,311,185 | 232 | | GET hit (100k keyspace) | 3,036,232 | 329 | | GET miss | 44,887,845 | 22 | | DELETE | 4,325,878 | 231 | | Mixed (70% get / 20% set / 10% delete) | 2,789,967 | 358 | | BATCH setItems (100 items/call) | 4,212,197 | 237 | | BATCH getItems (100 keys/call) | 1,354,869 | 738 |
No memory leaks: expired entries are freed eagerly and byte accounting returns to exactly zero when
the cache empties — see the detailed performance notes
for methodology and more details. Reproduce locally with npm run bench.
Documentation
Detailed docs live in docs/README.md:
- API Reference
- Configuration
- Memory Management & Eviction Policies
- Performance & Benchmarks
- Limitations
- Testing & Contributing
Good to know: single-process only (not distributed), no persistence, values are stored by reference, keys must be strings, TTL is whole seconds.
