Skip to content

Commit

Permalink
feat: 馃幐 stop all clients on cluster stop
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Dec 16, 2023
1 parent 14204ec commit b7d6378
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/__tests__/commands/string/SET.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {RedisCluster} from '../../../cluster/RedisCluster';
import {ClusterTestSetup} from '../../types';
import {run} from './SET';

const host = 'redis-15083.c28691.us-east-1-4.ec2.cloud.rlrcp.com';
const port = 15083;
const user = 'default';
const pwd = '7UAmqOMRcZ0KFZUfzze2KaWW8w0Fe8pP';
const client = new RedisCluster({
seeds: [{host, port}],
connectionConfig: {
user,
pwd,
},
});
client.onError.listen((err) => {
console.error('onError', err);
});
client.start();

const setupCluster: ClusterTestSetup = async () => {
await client.whenRouterReady();
return {client};
};

run(setupCluster);

afterAll(() => {
client.stop();
});
17 changes: 17 additions & 0 deletions src/__tests__/commands/string/SET.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {ClusterTestSetup} from '../../types';

export const run = (setup: ClusterTestSetup) => {
describe('SET', () => {
test('can set a key', async () => {
const {client} = await setup();
const res = await client.cmd(['SET', 'foo', 'bar']);
expect(res).toBe('OK');
});

test('can set a key with partition brackets', async () => {
const {client} = await setup();
const res = await client.cmd(['SET', '{foo}', 'bar']);
expect(res).toBe('OK');
});
});
};
9 changes: 9 additions & 0 deletions src/__tests__/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {RedisCluster} from '../cluster/RedisCluster';

export type TestSetup = ClusterTestSetup;
export type ClusterTestSetup = () => Promise<{
client: ClusterTestClient;
}>;

export type TextClient = ClusterTestClient;
export type ClusterTestClient = Pick<RedisCluster, 'cmd'>;
1 change: 1 addition & 0 deletions src/cluster/RedisCluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export class RedisCluster implements Printable {
this.isRebuildingRouteTable = false;
this.routeTableRebuildRetry = 0;
this.stopped = true;
this.clients.forEach((client) => client.stop());
}

// ---------------------------------------------- Build initial routing table
Expand Down

0 comments on commit b7d6378

Please sign in to comment.