In-memory Redis-compatible server implementation in JavaScript. Useful for testing and development without requiring a real Redis instance.
- Redis-compatible protocol - Works with any Redis client (ioredis, node-redis, etc.)
- Standalone and Cluster modes - Run a single server or a full cluster
- Lua scripting support - Execute Redis Lua scripts via WebAssembly
- No external dependencies - Pure JavaScript, no Redis installation needed
- Dual package - Supports both ESM and CommonJS
npm install js-redis-serverimport { createCustomCommander, Resp2Transport } from 'js-redis-server'
const logger = {
info: console.log,
error: console.error,
}
const factory = await createCustomCommander(logger)
const transport = new Resp2Transport(logger, factory.createCommander())
await transport.listen(6379)
console.log('Redis server listening on port 6379')
// Cleanup
await transport.close()
await factory.shutdown()# Run a single server on default port 6379
npx js-redis-server
# Run on a specific port
npx js-redis-server --port 6380
# Run a cluster with 3 masters
npx js-redis-server --cluster --masters 3
# Run a cluster with replicas
npx js-redis-server --cluster --masters 3 --slaves 1Modes:
--single Run a single Redis server (default)
--cluster Run a Redis cluster
--mode <single|cluster>
Single server options:
--port <number> Port to listen on (default 6379)
Cluster options:
--masters <number> Number of masters (default 3)
--slaves <number> Number of replicas per master (default 0)
--base-port <number> Starting port for cluster nodes (default 30000)
General:
-h, --help Show help
import { ClusterNetwork } from 'js-redis-server'
const logger = { info: console.log, error: console.error }
const cluster = new ClusterNetwork(logger)
await cluster.init({
masters: 3,
slaves: 1,
basePort: 30000,
})
// Get all node addresses
const nodes = cluster.getAll()
console.log(nodes.map(n => `${n.host}:${n.port}`))
// Cleanup
await cluster.shutdown()GET, SET, MGET, MSET, MSETNX, APPEND, STRLEN, GETSET, INCR, INCRBY, INCRBYFLOAT, DECR, DECRBY
HGET, HSET, HMGET, HMSET, HDEL, HEXISTS, HGETALL, HINCRBY, HINCRBYFLOAT, HKEYS, HLEN, HVALS
LPUSH, RPUSH, LPOP, RPOP, LLEN, LRANGE, LINDEX, LSET, LREM, LTRIM
SADD, SREM, SMEMBERS, SISMEMBER, SCARD, SPOP, SRANDMEMBER, SMOVE, SDIFF, SINTER, SUNION
ZADD, ZREM, ZSCORE, ZRANK, ZREVRANK, ZCARD, ZRANGE, ZREVRANGE, ZRANGEBYSCORE, ZREMRANGEBYSCORE, ZINCRBY
DEL, EXISTS, EXPIRE, EXPIREAT, TTL, PTTL, TYPE
PING, QUIT, INFO, DBSIZE, FLUSHDB, FLUSHALL
CLUSTER INFO, CLUSTER NODES, CLUSTER SLOTS, CLUSTER SHARDS
EVAL, EVALSHA, SCRIPT LOAD
CLIENT SETNAME
- Node.js >= 22
# Install dependencies
npm install
# Build
npm run build
# Run tests
npm test
# Run integration tests (mock backend)
npm run test:integration:mock
# Run integration tests (real Redis)
npm run test:integration:real
# Run all tests
npm run test:allContributions are welcome! Please read the contributing guidelines before submitting a pull request.
MIT - see LICENSE for details.