Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/cluster/ConnectionPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default class ConnectionPool extends EventEmitter {

getNodes(role: NodeRole = "all"): Redis[] {
const nodeRecords = this.nodeRecords[role];
return Object.keys(nodeRecords).map((key) => nodeRecords[key].redis);
return Object.keys(nodeRecords).map((key) => nodeRecords[key]?.redis);
}

getInstanceByKey(key: NodeKey): Redis {
Expand All @@ -39,7 +39,7 @@ export default class ConnectionPool extends EventEmitter {
getSampleInstance(role: NodeRole): Redis {
const keys = Object.keys(this.nodeRecords[role]);
const sampleKey = sample(keys);
return this.nodeRecords[role][sampleKey].redis;
return this.nodeRecords[role][sampleKey]?.redis;
}

/**
Expand Down
12 changes: 12 additions & 0 deletions test/functional/cluster/ConnectionPool.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { expect } from "chai";

import ConnectionPool from "../../../lib/cluster/ConnectionPool";

describe("The cluster connection pool", () => {
describe("when not connected", () => {
it("does not throw when fetching a sample node", () => {
expect(new ConnectionPool({}).getSampleInstance("all")).to.be.undefined;
expect(new ConnectionPool({}).getNodes("all")).to.be.eq([]);
});
});
});
Loading