✨ Add get / set and other Cluster properties / methods (#33655)

This commit is contained in:
nickroberts
2019-03-11 11:36:27 -07:00
committed by Wesley Wigham
parent a03ef19102
commit 771847f9bf
2 changed files with 39 additions and 0 deletions
+10
View File
@@ -875,10 +875,20 @@ declare namespace IORedis {
type NodeRole = 'master' | 'slave' | 'all';
type CallbackFunction<T = any> = (err?: NodeJS.ErrnoException | null, result?: T) => void;
interface Cluster extends NodeJS.EventEmitter, Commander {
connect(callback: () => void): Promise<any>;
disconnect(): void;
nodes(role?: NodeRole): Redis[];
quit(callback?: CallbackFunction<'OK'>): Promise<'OK'>;
get(key: KeyType, callback: (err: Error, res: string | null) => void): void;
get(key: KeyType): Promise<string | null>;
set(key: KeyType, value: any, expiryMode?: string | any[], time?: number | string, setMode?: number | string): Promise<string>;
set(key: KeyType, value: any, callback: (err: Error, res: string) => void): void;
set(key: KeyType, value: any, setMode: string | any[], callback: (err: Error, res: string) => void): void;
set(key: KeyType, value: any, expiryMode: string, time: number | string, callback: (err: Error, res: string) => void): void;
set(key: KeyType, value: any, expiryMode: string, time: number | string, setMode: number | string, callback: (err: Error, res: string) => void): void;
}
interface ClusterStatic extends NodeJS.EventEmitter, Commander {
+29
View File
@@ -226,3 +226,32 @@ cluster.nodes().map(node => {
.exec()
.then(result => console.log(result));
});
cluster.set('foo', 'bar');
cluster.get('foo', (err, result) => {
if (err) {
console.error(err);
}
console.log(result);
});
cluster.get('foo')
.then(result => console.log(result))
.catch(reason => console.error(reason));
cluster.connect(() => {
console.log('connect');
})
.then(result => console.log(result))
.then(reason => console.error(reason));
cluster.disconnect();
cluster.quit(result => {
console.log(result);
});
const getBuiltinCommandsResult = cluster.getBuiltinCommands();
console.log(getBuiltinCommandsResult);
const createBuiltinCommandResult = cluster.createBuiltinCommand('createBuiltinCommand');
console.log(createBuiltinCommandResult);
const defineCommandResult = cluster.defineCommand('defineCommand', {
numberOfKeys: 1,
lua: 'lua'
});
console.log(defineCommandResult);
cluster.sendCommand();