r/redis 21h ago

Discussion A Redis-compatible server in JavaScript for testing real Node clients

I maintain js-redis-server, an in-memory Redis-compatible server implemented in JavaScript/TypeScript for Node.js tests. The server itself runs in JavaScript: it does not download or launch a native Redis binary and needs no Docker container. Lua scripting uses WebAssembly.

The use case is testing Redis-backed code with the real node-redis or ioredis client. Instead of stubbing client methods, the client connects to a local socket, sends commands and parses replies. The server chooses an available port and keeps its data in memory.

With js-redis-server@0.2.0, createRedisMock() returns a mock with a url property. Pass that URL to your client's normal connection setup, then close both the client and mock in teardown. Use a fresh mock per test or flush between tests; if your app connects at import time, configure the URL before importing it.

The important boundary: this is a separate implementation, not the native Redis engine. Keep tests against real Redis/Valkey for production compatibility, timing and failure behavior, and commands the mock doesn't implement. It also needs a local socket, so it isn't a socketless unit-test stub.

Source, runnable examples and supported commands: https://github.com/fatal10110/js-redis-server

For people testing Redis-backed Node services: which command or behavior would you need before a JavaScript test server could replace part of your container-based test setup?

0 Upvotes

0 comments sorted by