local-redis
v1.0.0
Published
In-memory development Redis server for Node.js and test environments.
Readme
Absolutely! Here’s a clean, professional README.md tailored for an npm package publication. It emphasizes install/usage via Node, npm/yarn, programmatic usage, and CLI compatibility, targeting developers using your package in projects, tests, and CI.
Mock Redis Server (TypeScript)
A blazing-fast, fully-typed, drop-in Node.js Redis server emulator for development, testing, and CI pipelines.
Works with redis-cli, official clients, and all major Node.js frameworks.
✨ Features
- Plug-and-play, no dependencies required
- Full in-memory Redis server: Strings, Hashes, Lists, Sets, TTL
- Pub/Sub (
PUBLISH,SUBSCRIBE,UNSUBSCRIBE) - Persistence: automatic JSON snapshot on shutdown,
SAVEcommand, or user-config - Compatible with redis-cli and most Redis drivers (
ioredis,node-redis, Python, etc.) - INFO command for monitoring (uptime, memory, keys, stats)
- Minimal, fully-typed, and easy to extend—ideal for integration testing and local development
- Graceful shutdown & recovery
🚀 Quick Start
npm install --save-dev @your-scope/mock-redis-server
# or globally for CLI
npm install -g @your-scope/mock-redis-serverStart the server (CLI)
npx mock-redis-server
# or, if installed globally
mock-redis-serverDefault port: 6380
With options:
PORT=6379 REDIS_PERSISTENCE=false REDIS_SNAPSHOT_FILE=./myfile.json npx mock-redis-serverNode.js API Example
import { createMockRedisServer } from '@your-scope/mock-redis-server';
const server = createMockRedisServer({
port: 6380, // default: 6380
persistence: true, // default: true
snapshotFile: './redis_dump.json', // default: ./redis_dump.json
debug: false, // enable logging (default: false)
});
server.start();Connect with your favorite Redis client
redis-cli -p 6380🛠️ Configuration
| ENV / Option | Default | Description |
|--------------------------|-------------------|------------------------------------|
| PORT | 6380 | Port to listen on |
| REDIS_PERSISTENCE | true | Persist state to a JSON file |
| REDIS_SNAPSHOT_FILE | ./redis_dump.json | Path for snapshot file |
| REDIS_MOCK_DEBUG | false | Enable verbose debug logging |
🗝️ Supported Redis Commands
| Category | Commands |
|--------------|-------------------------------------------------|
| Strings | SET, GET, DEL |
| Expiry | EXPIRE, TTL |
| Hashes | HSET, HGET, HGETALL, HDEL |
| Lists | LPUSH, RPUSH, LPOP, RPOP, LRANGE |
| Sets | SADD, SMEMBERS, SREM |
| Pub/Sub | SUBSCRIBE, UNSUBSCRIBE, PUBLISH |
| Monitoring | INFO |
| Persistence | SAVE |
| Utility | PING |
👩💻 Example Usage
Strings and Expiry
SET hello world
GET hello
EXPIRE hello 5
TTL helloHashes
HSET user:1 name "Jane"
HGET user:1 name
HGETALL user:1Pub/Sub
(In Terminal 1:)
SUBSCRIBE news(In Terminal 2:)
PUBLISH news "Update!"Persistence
SAVEMonitoring
INFO🧪 Ideal for...
- ⚡ Super-fast end-to-end and integration tests—runs locally, no Docker/Redis server needed!
- 🛠️ CI/CD pipelines: remove external dependencies while keeping Redis API contracts
- 👩💻 Demos, prototypes, workshops, and educational purposes
📝 Notes
- Memory usage (
INFO) reports Node.js process memory—actual heap allocation by all keys plus runtime overhead (see docs). - Data is persisted and restored via JSON snapshot at shutdown/startup (unless disabled).
- Compatible with most Redis commands for Strings, Hashes, Lists, Sets, and Pub/Sub.
- Production features like AOF, security, cluster, sorted sets (ZSET) not currently implemented.
🤝 Contributing
PRs, feedback, and issues welcome!
Please open an issue or submit a PR to help make this better for the whole community.
📄 License
MIT © Pranav Bagal
Enjoy zero-hassle Redis server compatibility for your local dev, CI, and tests!
