{"library":"redis-memory-server","title":"Redis Memory Server","description":"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.","language":"javascript","status":"active","last_verified":"Tue Apr 21","install":{"commands":["npm install redis-memory-server"],"cli":null},"imports":["import { RedisMemoryServer } from 'redis-memory-server'","import { RedisMemoryServer } from 'redis-memory-server'","import type { RedisMemoryServerOpts } from 'redis-memory-server'"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { RedisMemoryServer } from 'redis-memory-server';\nimport { Redis } from 'ioredis'; // ioredis is a common client, install it separately\n\nlet redisServer: RedisMemoryServer | undefined;\nlet redisClient: Redis | undefined;\n\nasync function runRedisTest() {\n  redisServer = new RedisMemoryServer({\n    binary: {\n      version: '6.2.6', // Specify a fixed version for deterministic builds\n    },\n  });\n\n  try {\n    const host = await redisServer.getHost();\n    const port = await redisServer.getPort();\n\n    console.log(`Redis server started on ${host}:${port}`);\n\n    redisClient = new Redis({\n      host,\n      port,\n    });\n\n    await redisClient.set('mykey', 'myvalue');\n    const value = await redisClient.get('mykey');\n    console.log(`Retrieved value: ${value}`); // Expected: 'myvalue'\n\n    await redisClient.del('mykey');\n    const deleted = await redisClient.get('mykey');\n    console.log(`Value after deletion: ${deleted}`); // Expected: null\n\n  } catch (error) {\n    console.error('An error occurred during the test:', error);\n  } finally {\n    if (redisClient) {\n      await redisClient.quit();\n      console.log('Redis client disconnected.');\n    }\n    if (redisServer) {\n      await redisServer.stop();\n      console.log('Redis memory server stopped.');\n    }\n  }\n}\n\nrunRedisTest();","lang":"typescript","description":"This quickstart demonstrates how to start a RedisMemoryServer instance, connect to it using ioredis, perform basic set/get operations, and ensure proper cleanup.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}