mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-14 05:50:20 +00:00
Merge pull request #33315 from nickroberts/master
Update ioredis cluster types
This commit is contained in:
Vendored
+8
-3
@@ -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 {
|
||||
|
||||
@@ -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));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user