redis-memory-server is a utility that programmatically starts a real Redis server instance from Node.js, primarily designed for testing and development mocking. As of version 0.16.0, it provides an isolated, in-memory Redis environment for integration tests, allowing multiple instances to run concurrently on different ports. The package automatically handles downloading and compiling the `redis-server` binary, caching it for subsequent runs to improve performance. It is inspired by `mongodb-memory-server` and differentiates itself by providing a genuine Redis instance rather than a mock, ensuring high fidelity for integration testing. It supports Node.js environments version 18 and above, ships with TypeScript types, and abstracts away the complexities of managing Redis processes for testing workflows. Its release cadence appears active, with consistent updates for features and bug fixes.
npm install redis-memory-serverVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to start a RedisMemoryServer instance, connect to it using ioredis, perform basic set/get operations, and ensure proper cleanup.
Ensure `make` is installed in your development and CI/CD environments. For faster CI, consider caching `node_modules/.cache/redis-binaries`.
Explicitly specify a fixed `version` in the `RedisMemoryServer` options (e.g., `{ binary: { version: '6.2.6' } }`) or use `REDISMS_IGNORE_DOWNLOAD_CACHE=true npm rebuild redis-memory-server` to force an update.Be aware of potential behavioral differences between Memurai and standard Redis. Plan for testing on Linux/macOS if specific Redis version behavior is critical.
Monitor memory usage in your test environment. Ensure `redisServer.stop()` is always called to release resources. Consider limiting parallel test runners in environments with constrained memory.
Install `make` on your operating system. For Debian/Ubuntu: `sudo apt-get install build-essential`. For macOS: `xcode-select --install`.
Run `REDISMS_IGNORE_DOWNLOAD_CACHE=true npm rebuild redis-memory-server` to force a re-download and compilation. Ensure stable internet access and sufficient disk space.
Always `await redisServer.getHost()` and `await redisServer.getPort()` to ensure the server is ready and you have the correct connection details. Ensure `redisServer.stop()` is called in a `finally` block or test teardown.
No dependency data recorded yet.