Merge pull request #33315 from nickroberts/master

Update ioredis cluster types
This commit is contained in:
Jesse Trinity
2019-02-28 10:36:14 -08:00
committed by GitHub
2 changed files with 27 additions and 3 deletions
+8 -3
View File
@@ -30,7 +30,7 @@ interface RedisStatic {
(port?: number, host?: string, options?: IORedis.RedisOptions): IORedis.Redis;
(host?: string, options?: IORedis.RedisOptions): IORedis.Redis;
(options?: IORedis.RedisOptions): IORedis.Redis;
Cluster: IORedis.Cluster;
Cluster: IORedis.ClusterStatic;
Command: IORedis.Command;
}
@@ -873,11 +873,16 @@ declare namespace IORedis {
type ClusterNode = string | number | NodeConfiguration;
type NodeRole = 'master' | 'slave' | 'all';
interface Cluster extends NodeJS.EventEmitter, Commander {
new(nodes: ClusterNode[], options?: ClusterOptions): Redis;
connect(callback: () => void): Promise<any>;
disconnect(): void;
nodes(role: string): Redis[];
nodes(role?: NodeRole): Redis[];
}
interface ClusterStatic extends NodeJS.EventEmitter, Commander {
new (nodes: ClusterNode[], options?: ClusterOptions): Cluster;
}
interface RedisOptions {
+19
View File
@@ -207,3 +207,22 @@ new Redis.Cluster([], {
new Redis.Cluster([], {
clusterRetryStrategy: (times: number, reason?: Error) => 1
});
// Cluster types
const clusterOptions: Redis.ClusterOptions = {};
const cluster = new Redis.Cluster(
[
{
host: 'localhost',
port: 6379
}
],
clusterOptions
);
cluster.on('end', () => console.log('on end'));
cluster.nodes().map(node => {
node.pipeline()
.flushdb()
.exec()
.then(result => console.log(result));
});