( dockerConfigs: RedisServerDockerOptions, serverArguments: Array<string>, masterPort: number, sentinelName: string, tmpDir: string, password?: string, )
| 708 | |
| 709 | |
| 710 | export async function spawnSentinelNode( |
| 711 | dockerConfigs: RedisServerDockerOptions, |
| 712 | serverArguments: Array<string>, |
| 713 | masterPort: number, |
| 714 | sentinelName: string, |
| 715 | tmpDir: string, |
| 716 | password?: string, |
| 717 | ) { |
| 718 | const port = (await portIterator.next()).value; |
| 719 | |
| 720 | let sentinelConfig = `port ${port} |
| 721 | sentinel monitor ${sentinelName} 127.0.0.1 ${masterPort} 2 |
| 722 | sentinel down-after-milliseconds ${sentinelName} 500 |
| 723 | sentinel failover-timeout ${sentinelName} 1000 |
| 724 | `; |
| 725 | if (password !== undefined) { |
| 726 | sentinelConfig += `requirepass ${password}\n`; |
| 727 | sentinelConfig += `sentinel auth-pass ${sentinelName} ${password}\n`; |
| 728 | } |
| 729 | |
| 730 | const dir = fs.mkdtempSync(tmpDir); |
| 731 | fs.writeFile(`${dir}/redis.conf`, sentinelConfig, err => { |
| 732 | if (err) { |
| 733 | console.error("failed to create temporary config file", err); |
| 734 | } |
| 735 | }); |
| 736 | |
| 737 | return await spawnRedisServerDocker( |
| 738 | { |
| 739 | image: dockerConfigs.image, |
| 740 | version: dockerConfigs.version, |
| 741 | mode: "sentinel", |
| 742 | mounts: [`${dir}/redis.conf:/redis/config/node-sentinel-1/redis.conf`], |
| 743 | port: port, |
| 744 | }, |
| 745 | serverArguments, |
| 746 | ); |
| 747 | } |
no test coverage detected