diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8586d344..f490b463 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -207,7 +207,7 @@ jobs: - name: Setting up Redis run: docker run -p 6379:6379 -d --rm redisai/redisai && docker ps -a - name: Running tests - run: npm i && npm run ris-tests + run: npm i && npm run redis-ai-module-tests #Build for 'Redis Interval Sets' module RIS: needs: Setup @@ -222,4 +222,4 @@ jobs: - name: Setting up Redis run: docker run -p 6379:6379 -d --rm danitseitlin/redis-interval-sets && docker ps -a - name: Running tests - run: npm i && npm run ris-tests \ No newline at end of file + run: npm i && npm run ris-module-tests \ No newline at end of file diff --git a/modules/module.base.ts b/modules/module.base.ts index f12b5e86..1ec40a98 100644 --- a/modules/module.base.ts +++ b/modules/module.base.ts @@ -3,19 +3,26 @@ import * as Redis from 'ioredis'; export class Module { public redis: Redis.Redis; + public isHandleError: boolean; + public showDebugLogs: boolean; /** * Initializing the module object - * @param options The options of the Redis database - * @param throwError If to throw an exception on error. + * @param redisOptions The options of the Redis database + * @param moduleOptions The additional module options + * @param moduleOptions.isHandleError If to throw error on error + * @param moduleOptions.showDebugLogs If to print debug logs */ - constructor(public name: string, public options: Redis.RedisOptions, public throwError: boolean) {} + constructor(public name: string, public redisOptions: Redis.RedisOptions, public moduleOptions?: RedisModuleOptions) { + this.isHandleError = moduleOptions && moduleOptions.isHandleError ? moduleOptions.isHandleError: true; + this.showDebugLogs = moduleOptions && moduleOptions.showDebugLogs ? moduleOptions.showDebugLogs: false; + } /** * Connecting to the Redis database with the module */ async connect(): Promise { - this.redis = new Redis(this.options); + this.redis = new Redis(this.redisOptions); } /** @@ -25,6 +32,20 @@ export class Module { await this.redis.quit(); } + /** + * Running a Redis command + * @param command The redis command + * @param args The args of the redis command + */ + async sendCommand(command: string, args: Redis.ValueType | Redis.ValueType[] = []): Promise { + if(this.showDebugLogs) + console.log(`${this.name}: Running command ${command} with arguments: ${args}`); + const response = await this.redis.send_command(command, args); + if(this.showDebugLogs) + console.log(`${this.name}: command ${command} responded with ${response}`); + return response; + } + /** * Handling a error * @param module The name of the module @@ -32,7 +53,7 @@ export class Module { */ handleError(error: string): any { const err = `${this.name}: ${error}` - if(this.throwError) + if(this.isHandleError) throw new Error(err); return err; } @@ -87,4 +108,14 @@ export class Module { }) return newArray; } +} + +/** + * The Redis module class options + * @param isHandleError If to throw exception in case of error + * @param showDebugLogs If to print debug logs + */ +export type RedisModuleOptions = { + isHandleError?: boolean, + showDebugLogs?: boolean } \ No newline at end of file diff --git a/modules/redis-ai.ts b/modules/redis-ai.ts index 0ee28856..43ddd65b 100644 --- a/modules/redis-ai.ts +++ b/modules/redis-ai.ts @@ -1,4 +1,4 @@ -import { Module } from './module.base' +import { Module, RedisModuleOptions } from './module.base' import * as Redis from 'ioredis'; export class RedisAI extends Module { @@ -6,10 +6,12 @@ export class RedisAI extends Module { /** * Initializing the RedisAI object * @param options The options of the Redis database. - * @param throwError If to throw an exception on error. + * @param moduleOptions The additional module options + * @param moduleOptions.isHandleError If to throw error on error + * @param moduleOptions.showDebugLogs If to print debug logs */ - constructor(options: Redis.RedisOptions, throwError = true) { - super(RedisAI.name, options, throwError) + constructor(options: Redis.RedisOptions, public moduleOptions?: RedisModuleOptions) { + super(RedisAI.name, options, moduleOptions) } /** @@ -27,7 +29,7 @@ export class RedisAI extends Module { args.push(data instanceof Buffer ? 'BLOB': 'VALUES'); data.forEach((value: (number | string | Buffer)) => {args.push(value.toString())}); } - return await this.redis.send_command('AI.TENSORSET', args); + return await this.sendCommand('AI.TENSORSET', args); } catch(error) { return this.handleError(error); @@ -47,7 +49,7 @@ export class RedisAI extends Module { args.push('META'); if(format !== undefined) args.push(format); - const response = await this.redis.send_command('AI.TENSORGET', args); + const response = await this.sendCommand('AI.TENSORGET', args); return this.handleResponse(response); } catch(error) { @@ -79,7 +81,7 @@ export class RedisAI extends Module { if(options.outputs !== undefined && options.outputs.length > 0) args = args.concat(['OUTPUTS'].concat(options.outputs)); } - return await this.redis.send_command('AI.MODELSET', args.concat(['BLOB', model])); + return await this.sendCommand('AI.MODELSET', args.concat(['BLOB', model])); } catch(error) { return this.handleError(error); @@ -99,7 +101,7 @@ export class RedisAI extends Module { args.push('META'); if(blob === true) args.push('BLOB'); - const response = await this.redis.send_command('AI.MODELGET', args); + const response = await this.sendCommand('AI.MODELGET', args); return this.handleResponse(response) } catch(error) { @@ -113,7 +115,7 @@ export class RedisAI extends Module { */ async modeldel(key: string): Promise<'OK'> { try { - return await this.redis.send_command('AI.MODELDEL', [key]); + return await this.sendCommand('AI.MODELDEL', [key]); } catch(error) { return this.handleError(error); @@ -129,7 +131,7 @@ export class RedisAI extends Module { async modelrun(key: string, inputs: string[], outputs: string[]): Promise<'OK'> { try { const args = [key, 'INPUTS'].concat(inputs).concat(['OUTPUTS']).concat(outputs); - return await this.redis.send_command('AI.MODELRUN', args); + return await this.sendCommand('AI.MODELRUN', args); } catch(error) { return this.handleError(error); @@ -141,7 +143,7 @@ export class RedisAI extends Module { */ async modelscan(): Promise { try { - return await this.redis.send_command('AI._MODELSCAN', []); + return await this.sendCommand('AI._MODELSCAN', []); } catch(error) { return this.handleError(error); @@ -158,7 +160,7 @@ export class RedisAI extends Module { let args = [key, parameters.device]; if(parameters.tag !== undefined) args = args.concat(['TAG', parameters.tag]) - return await this.redis.send_command('AI.SCRIPTSET', args.concat(['SOURCE', parameters.script])); + return await this.sendCommand('AI.SCRIPTSET', args.concat(['SOURCE', parameters.script])); } catch(error) { return this.handleError(error); @@ -178,7 +180,7 @@ export class RedisAI extends Module { args.push('META'); if(source === true) args.push('SOURCE'); - const response: string[] = await this.redis.send_command('AI.SCRIPTGET', args); + const response: string[] = await this.sendCommand('AI.SCRIPTGET', args); return this.handleResponse(response); } catch(error) { @@ -192,7 +194,7 @@ export class RedisAI extends Module { */ async scriptdel(key: string): Promise<'OK'> { try { - return await this.redis.send_command('AI.SCRIPTDEL', [key]); + return await this.sendCommand('AI.SCRIPTDEL', [key]); } catch(error) { return this.handleError(error); @@ -210,7 +212,7 @@ export class RedisAI extends Module { try { const args = [key, functionName, 'INPUTS'].concat(inputs) args.push('OUTPUTS') - return await this.redis.send_command('AI.SCRIPTRUN', args.concat(outputs)); + return await this.sendCommand('AI.SCRIPTRUN', args.concat(outputs)); } catch(error) { return this.handleError(error); @@ -222,7 +224,7 @@ export class RedisAI extends Module { */ async scriptscan(): Promise { try { - return await this.redis.send_command('AI._SCRIPTSCAN') + return await this.sendCommand('AI._SCRIPTSCAN') } catch(error) { return this.handleError(error); @@ -237,7 +239,7 @@ export class RedisAI extends Module { */ async dagrun(commands: string[], load?: AIDagrunParameters, persist?: AIDagrunParameters): Promise { try { - return await this.redis.send_command('AI.DAGRUN', this.generateDagRunArguments(commands, load, persist)) + return await this.sendCommand('AI.DAGRUN', this.generateDagRunArguments(commands, load, persist)) } catch(error) { return this.handleError(error); @@ -251,7 +253,7 @@ export class RedisAI extends Module { */ async dagrunRO(commands: string[], load?: AIDagrunParameters): Promise { try { - return await this.redis.send_command('AI.DAGRUN_RO', this.generateDagRunArguments(commands, load)) + return await this.sendCommand('AI.DAGRUN_RO', this.generateDagRunArguments(commands, load)) } catch(error) { return this.handleError(error); @@ -287,7 +289,7 @@ export class RedisAI extends Module { try { const args = [key] if(RESETSTAT === true) args.push('RESETSTAT') - const response: string[] = await this.redis.send_command('AI.INFO', args) + const response: string[] = await this.sendCommand('AI.INFO', args) return this.handleResponse(response); } catch(error) { @@ -307,7 +309,7 @@ export class RedisAI extends Module { args = args.concat(['LOADBACKEND', backend, path]) else args = args.concat(['BACKENDSPATH', path]) - return await this.redis.send_command('AI.CONFIG', args) + return await this.sendCommand('AI.CONFIG', args) } catch(error) { return this.handleError(error); diff --git a/modules/redis.ts b/modules/redis.ts index 0d3b5c3e..5f256546 100644 --- a/modules/redis.ts +++ b/modules/redis.ts @@ -1,6 +1,6 @@ import * as IORedis from 'ioredis'; -import { Module } from './module.base'; +import { Module, RedisModuleOptions } from './module.base'; import { RedisAI } from './redis-ai'; import { RedisBloom } from './redisbloom'; import { RedisBloomCMK } from './redisbloom-cmk'; @@ -29,10 +29,12 @@ export class Redis extends Module { /** * Initializing the Redis object * @param options The options of the Redis database. - * @param throwError If to throw an exception on error. + * @param moduleOptions The additional module options + * @param moduleOptions.isHandleError If to throw error on error + * @param moduleOptions.showDebugLogs If to print debug logs */ - constructor(options: IORedis.RedisOptions, throwError = true) { - super('Redis', options, throwError) + constructor(options: IORedis.RedisOptions, public moduleOptions?: RedisModuleOptions) { + super('Redis', options, moduleOptions) this.rts = new RedisTimeSeries(options) this.rejson = new ReJSON(options) this.graph = new RedisGraph(options) diff --git a/modules/redisbloom-cmk.ts b/modules/redisbloom-cmk.ts index d8da63f4..655984a2 100644 --- a/modules/redisbloom-cmk.ts +++ b/modules/redisbloom-cmk.ts @@ -1,15 +1,17 @@ import * as Redis from 'ioredis'; -import { Module } from './module.base'; +import { Module, RedisModuleOptions } from './module.base'; export class RedisBloomCMK extends Module { /** * Initializing the RedisBloom Count-Min Sketch object * @param options The options of the Redis database. - * @param throwError If to throw an exception on error. + * @param moduleOptions The additional module options + * @param moduleOptions.isHandleError If to throw error on error + * @param moduleOptions.showDebugLogs If to print debug logs */ - constructor(options: Redis.RedisOptions, throwError = true) { - super(RedisBloomCMK.name, options, throwError) + constructor(options: Redis.RedisOptions, public moduleOptions?: RedisModuleOptions) { + super(RedisBloomCMK.name, options, moduleOptions) } /** @@ -20,7 +22,7 @@ export class RedisBloomCMK extends Module { */ async initbydim(key: string, width: number, depth: number): Promise<'OK'> { try { - return await this.redis.send_command('CMS.INITBYDIM', [key, width, depth]); + return await this.sendCommand('CMS.INITBYDIM', [key, width, depth]); } catch(error) { return this.handleError(error); @@ -35,7 +37,7 @@ export class RedisBloomCMK extends Module { */ async initbyprob(key: string, errorSize: number, probability: number): Promise<'OK'> { try { - return await this.redis.send_command('CMS.INITBYPROB', [key, errorSize, probability]); + return await this.sendCommand('CMS.INITBYPROB', [key, errorSize, probability]); } catch(error) { return this.handleError(error); @@ -52,7 +54,7 @@ export class RedisBloomCMK extends Module { let args = [key]; for(const item of items) args = args.concat([item.name.toString(), item.increment.toString()]) - return await this.redis.send_command('CMS.INCRBY', args); + return await this.sendCommand('CMS.INCRBY', args); } catch(error) { return this.handleError(error); @@ -66,7 +68,7 @@ export class RedisBloomCMK extends Module { */ async query(key: string, items: string[]): Promise { try { - return await this.redis.send_command('CMS.QUERY', [key].concat(items)); + return await this.sendCommand('CMS.QUERY', [key].concat(items)); } catch(error) { return this.handleError(error); @@ -89,7 +91,7 @@ export class RedisBloomCMK extends Module { for(const weight of weights) args.push(weight.toString()); } - return await this.redis.send_command('CMS.MERGE', args); + return await this.sendCommand('CMS.MERGE', args); } catch(error) { return this.handleError(error); @@ -102,7 +104,7 @@ export class RedisBloomCMK extends Module { */ async info(key: string): Promise { try { - return await this.redis.send_command('CMS.INFO', [key]); + return await this.sendCommand('CMS.INFO', [key]); } catch(error) { return this.handleError(error); diff --git a/modules/redisbloom-cuckoo.ts b/modules/redisbloom-cuckoo.ts index 0a113673..023fafc4 100644 --- a/modules/redisbloom-cuckoo.ts +++ b/modules/redisbloom-cuckoo.ts @@ -1,15 +1,17 @@ import * as Redis from 'ioredis'; -import { Module } from './module.base'; +import { Module, RedisModuleOptions } from './module.base'; export class RedisBloomCuckoo extends Module { /** * Initializing the RedisCuckoo Cuckoo object * @param options The options of the Redis database. - * @param throwError If to throw an exception on error. + * @param moduleOptions The additional module options + * @param moduleOptions.isHandleError If to throw error on error + * @param moduleOptions.showDebugLogs If to print debug logs */ - constructor(options: Redis.RedisOptions, throwError = true) { - super(RedisBloomCuckoo.name, options, throwError) + constructor(options: Redis.RedisOptions, public moduleOptions?: RedisModuleOptions) { + super(RedisBloomCuckoo.name, options, moduleOptions) } /** @@ -19,7 +21,7 @@ export class RedisBloomCuckoo extends Module { */ async add(key: string, item: string): Promise { try { - return await this.redis.send_command('CF.ADD', [key, item]) + return await this.sendCommand('CF.ADD', [key, item]) } catch(error) { return this.handleError(error); @@ -33,7 +35,7 @@ export class RedisBloomCuckoo extends Module { */ async addnx(key: string, item: string): Promise { try { - return await this.redis.send_command('CF.ADDNX', [key, item]) + return await this.sendCommand('CF.ADDNX', [key, item]) } catch(error) { return this.handleError(error); @@ -53,7 +55,7 @@ export class RedisBloomCuckoo extends Module { args = args.concat(['CAPACITY', options.capacity.toString()]); if(options !== undefined && options.nocreate !== undefined) args.push('NOCREATE'); - return await this.redis.send_command('CF.INSERT', args.concat(['ITEMS']).concat(items)); + return await this.sendCommand('CF.INSERT', args.concat(['ITEMS']).concat(items)); } catch(error) { return this.handleError(error); @@ -73,7 +75,7 @@ export class RedisBloomCuckoo extends Module { args = args.concat(['CAPACITY', options.capacity.toString()]); if(options !== undefined && options.nocreate !== undefined) args.push('NOCREATE'); - return await this.redis.send_command('CF.INSERTNX', args.concat(['ITEMS']).concat(items)); + return await this.sendCommand('CF.INSERTNX', args.concat(['ITEMS']).concat(items)); } catch(error) { return this.handleError(error); @@ -87,7 +89,7 @@ export class RedisBloomCuckoo extends Module { */ async exists(key: string, item: string): Promise { try { - return await this.redis.send_command('CF.EXISTS', [key, item]); + return await this.sendCommand('CF.EXISTS', [key, item]); } catch(error) { return this.handleError(error); @@ -101,7 +103,7 @@ export class RedisBloomCuckoo extends Module { */ async del(key: string, item: string): Promise { try { - return await this.redis.send_command('CF.DEL', [key, item]); + return await this.sendCommand('CF.DEL', [key, item]); } catch(error) { return this.handleError(error); @@ -115,7 +117,7 @@ export class RedisBloomCuckoo extends Module { */ async count(key: string, item: string): Promise { try { - return await this.redis.send_command('CF.COUNT', [key, item]); + return await this.sendCommand('CF.COUNT', [key, item]); } catch(error) { return this.handleError(error); @@ -129,7 +131,7 @@ export class RedisBloomCuckoo extends Module { */ async scandump(key: string, iterator: number): Promise { try { - return await this.redis.send_command('CF.SCANDUMP', [key, iterator]) + return await this.sendCommand('CF.SCANDUMP', [key, iterator]) } catch(error) { return this.handleError(error); @@ -144,7 +146,7 @@ export class RedisBloomCuckoo extends Module { */ async loadchunk(key: string, iterator: number, data: string): Promise<'OK'> { try { - return await this.redis.send_command('CF.LOADCHUNK', [key, iterator, data]); + return await this.sendCommand('CF.LOADCHUNK', [key, iterator, data]); } catch(error) { return this.handleError(error); @@ -157,7 +159,7 @@ export class RedisBloomCuckoo extends Module { */ async info(key: string): Promise { try { - return await this.redis.send_command('CF.INFO', [key]); + return await this.sendCommand('CF.INFO', [key]); } catch(error) { return this.handleError(error); diff --git a/modules/redisbloom-topk.ts b/modules/redisbloom-topk.ts index 87a80bf9..2f3d1c77 100644 --- a/modules/redisbloom-topk.ts +++ b/modules/redisbloom-topk.ts @@ -1,15 +1,17 @@ import * as Redis from 'ioredis'; -import { Module } from './module.base'; +import { Module, RedisModuleOptions } from './module.base'; export class RedisBloomTopK extends Module { /** * Initializing the RedisBloom Top-K object * @param options The options of the Redis database. - * @param throwError If to throw an exception on error. + * @param moduleOptions The additional module options + * @param moduleOptions.isHandleError If to throw error on error + * @param moduleOptions.showDebugLogs If to print debug logs */ - constructor(options: Redis.RedisOptions, throwError = true) { - super(RedisBloomTopK.name, options, throwError) + constructor(options: Redis.RedisOptions, public moduleOptions?: RedisModuleOptions) { + super(RedisBloomTopK.name, options, moduleOptions) } /** @@ -22,7 +24,7 @@ export class RedisBloomTopK extends Module { */ async reserve(key: string, topk: number, width: number, depth: number, decay: number): Promise<'OK'> { try { - return await this.redis.send_command('TOPK.RESERVE', [key, topk, width, depth, decay]); + return await this.sendCommand('TOPK.RESERVE', [key, topk, width, depth, decay]); } catch(error) { return this.handleError(error); @@ -36,7 +38,7 @@ export class RedisBloomTopK extends Module { */ async add(key: string, items: (number | string)[]): Promise { try { - return await this.redis.send_command('TOPK.ADD', [key].concat(items as string[])) + return await this.sendCommand('TOPK.ADD', [key].concat(items as string[])) } catch(error) { return this.handleError(error); @@ -54,7 +56,7 @@ export class RedisBloomTopK extends Module { for(const item of items) { args = args.concat([item.name.toString(), item.increment.toString()]) } - return await this.redis.send_command('TOPK.INCRBY', args); + return await this.sendCommand('TOPK.INCRBY', args); } catch(error) { return this.handleError(error); @@ -69,7 +71,7 @@ export class RedisBloomTopK extends Module { */ async query(key: string, items: (string | number)[]): Promise { try { - return await this.redis.send_command('TOPK.QUERY', [key].concat(items as string[])) + return await this.sendCommand('TOPK.QUERY', [key].concat(items as string[])) } catch(error) { return this.handleError(error); @@ -83,7 +85,7 @@ export class RedisBloomTopK extends Module { */ async count(key: string, items: (string | number)[]): Promise { try { - return await this.redis.send_command('TOPK.COUNT', [key].concat(items as string[])); + return await this.sendCommand('TOPK.COUNT', [key].concat(items as string[])); } catch(error) { return this.handleError(error); @@ -96,7 +98,7 @@ export class RedisBloomTopK extends Module { */ async list(key: string): Promise<(string | number)[]> { try { - return await this.redis.send_command('TOPK.LIST', [key]); + return await this.sendCommand('TOPK.LIST', [key]); } catch(error) { return this.handleError(error); @@ -109,7 +111,7 @@ export class RedisBloomTopK extends Module { */ async info(key: string): Promise<(string | number)[]> { try { - return await this.redis.send_command('TOPK.INFO', [key]); + return await this.sendCommand('TOPK.INFO', [key]); } catch(error) { return this.handleError(error); diff --git a/modules/redisbloom.ts b/modules/redisbloom.ts index 712186a0..1675bdd7 100644 --- a/modules/redisbloom.ts +++ b/modules/redisbloom.ts @@ -1,15 +1,17 @@ import * as Redis from 'ioredis'; -import { Module } from './module.base'; +import { Module, RedisModuleOptions } from './module.base'; export class RedisBloom extends Module { /** * Initializing the RedisBloom object * @param options The options of the Redis database. - * @param throwError If to throw an exception on error. + * @param moduleOptions The additional module options + * @param moduleOptions.isHandleError If to throw error on error + * @param moduleOptions.showDebugLogs If to print debug logs */ - constructor(options: Redis.RedisOptions, throwError = true) { - super(RedisBloom.name, options, throwError) + constructor(options: Redis.RedisOptions, public moduleOptions?: RedisModuleOptions) { + super(RedisBloom.name, options, moduleOptions) } /** @@ -26,7 +28,7 @@ export class RedisBloom extends Module { args.push(options.expansion); if(options !== undefined && options.nonscaling === true) args.push('NONSCALING'); - return await this.redis.send_command('BF.RESERVE', args); + return await this.sendCommand('BF.RESERVE', args); } catch(error) { return this.handleError(error); @@ -40,7 +42,7 @@ export class RedisBloom extends Module { */ async add(key: string, item: string): Promise { try { - return await this.redis.send_command('BF.ADD', [key, item]) + return await this.sendCommand('BF.ADD', [key, item]) } catch(error) { return this.handleError(error); @@ -53,7 +55,7 @@ export class RedisBloom extends Module { */ async madd(key: string, items: string[]): Promise { try { - return await this.redis.send_command('BF.MADD', [key].concat(items)) + return await this.sendCommand('BF.MADD', [key].concat(items)) } catch(error) { return this.handleError(error); @@ -80,7 +82,7 @@ export class RedisBloom extends Module { if(options !== undefined && options.noscaling !== undefined) args.push('NOSCALING'); args.push('ITEMS') - return await this.redis.send_command('BF.INSERT', args.concat(items)); + return await this.sendCommand('BF.INSERT', args.concat(items)); } catch(error) { return this.handleError(error); @@ -94,7 +96,7 @@ export class RedisBloom extends Module { */ async exists(key: string, item: string): Promise { try { - return await this.redis.send_command('BF.EXISTS', [key, item]); + return await this.sendCommand('BF.EXISTS', [key, item]); } catch(error) { return this.handleError(error); @@ -108,7 +110,7 @@ export class RedisBloom extends Module { */ async mexists(key: string, items: string[]): Promise { try { - return await this.redis.send_command('BF.MEXISTS', [key].concat(items)) + return await this.sendCommand('BF.MEXISTS', [key].concat(items)) } catch(error) { return this.handleError(error); @@ -122,7 +124,7 @@ export class RedisBloom extends Module { */ async scandump(key: string, iterator: number): Promise { try { - return await this.redis.send_command('BF.SCANDUMP', [key, iterator]) + return await this.sendCommand('BF.SCANDUMP', [key, iterator]) } catch(error) { return this.handleError(error); @@ -137,7 +139,7 @@ export class RedisBloom extends Module { */ async loadchunk(key: string, iterator: number, data: string): Promise<'OK'> { try { - return await this.redis.send_command('BF.LOADCHUNK', [key, iterator, data]); + return await this.sendCommand('BF.LOADCHUNK', [key, iterator, data]); } catch(error) { return this.handleError(error); @@ -150,7 +152,7 @@ export class RedisBloom extends Module { */ async info(key: string): Promise { try { - return await this.redis.send_command('BF.INFO', [key]); + return await this.sendCommand('BF.INFO', [key]); } catch(error) { return this.handleError(error); diff --git a/modules/redisearch.ts b/modules/redisearch.ts index 36dedc9d..7d9ab2e8 100644 --- a/modules/redisearch.ts +++ b/modules/redisearch.ts @@ -1,16 +1,18 @@ import * as Redis from 'ioredis'; -import { Module } from './module.base'; +import { Module, RedisModuleOptions } from './module.base'; export class Redisearch extends Module { /** * Initializing the RediSearch object * @param options The options of the Redis database. - * @param throwError If to throw an exception on error. + * @param moduleOptions The additional module options + * @param moduleOptions.isHandleError If to throw error on error + * @param moduleOptions.showDebugLogs If to print debug logs */ - constructor(options: Redis.RedisOptions, throwError = true) { - super(Redisearch.name, options, throwError) + constructor(options: Redis.RedisOptions, public moduleOptions?: RedisModuleOptions) { + super(Redisearch.name, options, moduleOptions) } /** @@ -68,7 +70,7 @@ export class Redisearch extends Module { if(field.sortable !== undefined) args.push('SORTABLE'); if(field.noindex !== undefined) args.push('NOINDEX'); } - const response = await this.redis.send_command('FT.CREATE', args); + const response = await this.sendCommand('FT.CREATE', args); return this.handleResponse(response); } catch(error) { @@ -165,7 +167,7 @@ export class Redisearch extends Module { if(parameters.limit !== undefined) args = args.concat(['LIMIT', parameters.limit.first.toString(), parameters.limit.num.toString()]) } - const response = await this.redis.send_command('FT.SEARCH', args); + const response = await this.sendCommand('FT.SEARCH', args); return this.handleResponse(response); } catch(error) { @@ -235,7 +237,7 @@ export class Redisearch extends Module { args.push(parameters.limit.numberOfResults.toString()); } } - const response = await this.redis.send_command('FT.AGGREGATE', args); + const response = await this.sendCommand('FT.AGGREGATE', args); return this.handleResponse(response); } catch(error) { @@ -251,7 +253,7 @@ export class Redisearch extends Module { */ async explain(index: string, query: string): Promise { try { - const response = await this.redis.send_command('FT.EXPLAIN', [index, query]); + const response = await this.sendCommand('FT.EXPLAIN', [index, query]); return this.handleResponse(response); } catch(error) { @@ -267,7 +269,7 @@ export class Redisearch extends Module { */ async explainCLI(index: string, query: string): Promise { try { - const response = await this.redis.send_command('FT.EXPLAINCLI', [index, query]); + const response = await this.sendCommand('FT.EXPLAINCLI', [index, query]); return this.handleResponse(response.join('')); } catch(error) { @@ -294,7 +296,7 @@ export class Redisearch extends Module { if(options.seperator !== undefined) args = args.concat(['SEPERATOR', options.seperator]); if(options.weight !== undefined) args = args.concat(['WEIGHT', options.weight.toString()]); } - const response = await this.redis.send_command('FT.ALTER', args); + const response = await this.sendCommand('FT.ALTER', args); return this.handleResponse(response); } catch(error) { @@ -312,7 +314,7 @@ export class Redisearch extends Module { try { const args = [index]; if(deleteHash === true) args.push('DD') - const response = await this.redis.send_command('FT.DROPINDEX', args); + const response = await this.sendCommand('FT.DROPINDEX', args); return this.handleResponse(response); } catch(error) { @@ -328,7 +330,7 @@ export class Redisearch extends Module { */ async aliasadd(name: string, index: string): Promise<'OK'> { try { - const response = await this.redis.send_command('FT.ALIASADD', [name, index]); + const response = await this.sendCommand('FT.ALIASADD', [name, index]); return this.handleResponse(response); } catch(error) { @@ -344,7 +346,7 @@ export class Redisearch extends Module { */ async aliasupdate(name: string, index: string): Promise<'OK'> { try { - const response = await this.redis.send_command('FT.ALIASUPDATE', [name, index]); + const response = await this.sendCommand('FT.ALIASUPDATE', [name, index]); return this.handleResponse(response); } catch(error) { @@ -359,7 +361,7 @@ export class Redisearch extends Module { */ async aliasdel(name: string): Promise<'OK'> { try { - const response = await this.redis.send_command('FT.ALIASDEL', [name]); + const response = await this.sendCommand('FT.ALIASDEL', [name]); return this.handleResponse(response); } catch(error) { @@ -375,7 +377,7 @@ export class Redisearch extends Module { */ async tagvals(index: string, field: string): Promise { try { - const response = await this.redis.send_command('FT.TAGVALS', [index, field]); + const response = await this.sendCommand('FT.TAGVALS', [index, field]); return this.handleResponse(response); } catch(error) { @@ -398,7 +400,7 @@ export class Redisearch extends Module { args.push('INCR'); if(options !== undefined && options.payload !== undefined) args = args.concat(['PAYLOAD', options.payload]); - const response = await this.redis.send_command('FT.SUGADD', args); + const response = await this.sendCommand('FT.SUGADD', args); return this.handleResponse(response); } catch(error) { @@ -424,7 +426,7 @@ export class Redisearch extends Module { args.push('WITHSCORES'); if(options !== undefined && options.withPayloads !== undefined) args.push('WITHPAYLOADS'); - const response = await this.redis.send_command('FT.SUGGET', args); + const response = await this.sendCommand('FT.SUGGET', args); return this.handleResponse(response); } catch(error) { @@ -439,7 +441,7 @@ export class Redisearch extends Module { */ async sugdel(key: string, suggestion: string): Promise { try { - const response = await this.redis.send_command('FT.SUGDEL', [key, suggestion]); + const response = await this.sendCommand('FT.SUGDEL', [key, suggestion]); return this.handleResponse(response); } catch(error) { @@ -453,7 +455,7 @@ export class Redisearch extends Module { */ async suglen(key: string): Promise { try { - const response = await this.redis.send_command('FT.SUGLEN', key); + const response = await this.sendCommand('FT.SUGLEN', key); return this.handleResponse(response); } catch(error) { @@ -474,7 +476,7 @@ export class Redisearch extends Module { const args = [index, groupId].concat(terms); if(skipInitialScan === true) args.push('SKIPINITIALSCAN'); - const response = await this.redis.send_command('FT.SYNUPDATE', args); + const response = await this.sendCommand('FT.SYNUPDATE', args); return this.handleResponse(response); } catch(error) { @@ -489,7 +491,7 @@ export class Redisearch extends Module { */ async syndump(index: string): Promise<{[key: string]: string | number}> { try { - const response = await this.redis.send_command('FT.SYNDUMP', [index]); + const response = await this.sendCommand('FT.SYNDUMP', [index]); return this.handleResponse(response); } catch(error) { @@ -515,7 +517,7 @@ export class Redisearch extends Module { args = args.concat([term.type, term.dict]); } } - const response = await this.redis.send_command('FT.SPELLCHECK', args); + const response = await this.sendCommand('FT.SPELLCHECK', args); return this.handleResponse(response); } catch(error) { @@ -531,7 +533,7 @@ export class Redisearch extends Module { */ async dictadd(dict: string, terms: string[]): Promise { try { - const response = await this.redis.send_command('FT.DICTADD', [dict].concat(terms)); + const response = await this.sendCommand('FT.DICTADD', [dict].concat(terms)); return this.handleResponse(response); } catch(error) { @@ -547,7 +549,7 @@ export class Redisearch extends Module { */ async dictdel(dict: string, terms: string[]): Promise { try { - const response = await this.redis.send_command('FT.DICTDEL', [dict].concat(terms)); + const response = await this.sendCommand('FT.DICTDEL', [dict].concat(terms)); return this.handleResponse(response); } catch(error) { @@ -562,7 +564,7 @@ export class Redisearch extends Module { */ async dictdump(dict: string): Promise { try { - const response = await this.redis.send_command('FT.DICTDUMP', [dict]); + const response = await this.sendCommand('FT.DICTDUMP', [dict]); return this.handleResponse(response); } catch(error) { @@ -577,7 +579,7 @@ export class Redisearch extends Module { */ async info(index: string): Promise { try { - const response = await this.redis.send_command('FT.INFO', [index]); + const response = await this.sendCommand('FT.INFO', [index]); return this.handleResponse(response); } catch(error) { @@ -597,7 +599,7 @@ export class Redisearch extends Module { const args = [command, option]; if(command === 'SET') args.push(value); - const response = await this.redis.send_command('FT.CONFIG', args); + const response = await this.sendCommand('FT.CONFIG', args); return this.handleResponse(response); } catch(error) { diff --git a/modules/redisgears.ts b/modules/redisgears.ts index 7e39c031..6bdb96ef 100644 --- a/modules/redisgears.ts +++ b/modules/redisgears.ts @@ -1,15 +1,17 @@ import * as Redis from 'ioredis'; -import { Module } from './module.base'; +import { Module, RedisModuleOptions } from './module.base'; export class RedisGears extends Module { /** * Initializing the RedisGears object * @param options The options of the Redis database. - * @param throwError If to throw an exception on error. + * @param moduleOptions The additional module options + * @param moduleOptions.isHandleError If to throw error on error + * @param moduleOptions.showDebugLogs If to print debug logs */ - constructor(options: Redis.RedisOptions, throwError = true) { - super(RedisGears.name, options, throwError) + constructor(options: Redis.RedisOptions, public moduleOptions?: RedisModuleOptions) { + super(RedisGears.name, options, moduleOptions) } /** @@ -18,7 +20,7 @@ export class RedisGears extends Module { */ async abortExecution(id: string): Promise<'OK'> { try { - return await this.redis.send_command('RG.ABORTEXECUTION', [id]); + return await this.sendCommand('RG.ABORTEXECUTION', [id]); } catch(error) { return this.handleError(error); @@ -31,7 +33,7 @@ export class RedisGears extends Module { */ async configGet(key: string[]): Promise { try { - return await this.redis.send_command('RG.CONFIGGET', key); + return await this.sendCommand('RG.CONFIGGET', key); } catch(error) { return this.handleError(error); @@ -47,7 +49,7 @@ export class RedisGears extends Module { const args = []; for(const keyvalue of keyvalues) args.concat(keyvalue) - return await this.redis.send_command('RG.CONFIGSET', args); + return await this.sendCommand('RG.CONFIGSET', args); } catch(error) { return this.handleError(error); @@ -60,7 +62,7 @@ export class RedisGears extends Module { */ async dropExecution(id: string): Promise<'OK'> { try { - return await this.redis.send_command('RG.DROPEXECUTION', [id]); + return await this.sendCommand('RG.DROPEXECUTION', [id]); } catch(error) { return this.handleError(error); @@ -72,7 +74,7 @@ export class RedisGears extends Module { */ async dumpExecutions(): Promise { try { - return await this.redis.send_command('RG.DUMPEXECUTIONS'); + return await this.sendCommand('RG.DUMPEXECUTIONS'); } catch(error) { return this.handleError(error); @@ -84,7 +86,7 @@ export class RedisGears extends Module { */ async dumpRegistrations(): Promise { try { - return await this.redis.send_command('RG.DUMPREGISTRATIONS'); + return await this.sendCommand('RG.DUMPREGISTRATIONS'); } catch(error) { return this.handleError(error); @@ -101,7 +103,7 @@ export class RedisGears extends Module { const args = [id.toString()]; if(options !== undefined && options.shard === true) args.push('SHARD'); if(options !== undefined && options.cluster === true) args.push('CLUSTER'); - return await this.redis.send_command('RG.GETEXECUTION', args); + return await this.sendCommand('RG.GETEXECUTION', args); } catch(error) { return this.handleError(error); @@ -114,7 +116,7 @@ export class RedisGears extends Module { */ async getResults(id: string): Promise { try { - return await this.redis.send_command('RG.GETRESULTS', [id]) + return await this.sendCommand('RG.GETRESULTS', [id]) } catch(error) { return this.handleError(error); @@ -127,7 +129,7 @@ export class RedisGears extends Module { */ async getResultsBlocking(id: string): Promise { try { - return await this.redis.send_command('RG.GETRESULTSBLOCKING', [id]) + return await this.sendCommand('RG.GETRESULTSBLOCKING', [id]) } catch(error) { return this.handleError(error); @@ -139,7 +141,7 @@ export class RedisGears extends Module { */ async infocluster(): Promise { try { - return await this.redis.send_command('RG.INFOCLUSTER') + return await this.sendCommand('RG.INFOCLUSTER') } catch(error) { return this.handleError(error); @@ -156,7 +158,7 @@ export class RedisGears extends Module { const args = [func]; if(options !== undefined && options.unblocking === true) args.push('UNBLOCKING'); if(options !== undefined && options.requirements !== undefined) args.concat(['REQUIREMENTS'].concat(options.requirements)); - return await this.redis.send_command('RG.PYEXECUTE', args); + return await this.sendCommand('RG.PYEXECUTE', args); } catch(error) { return this.handleError(error); @@ -168,7 +170,7 @@ export class RedisGears extends Module { */ async pystats(): Promise { try { - return await this.redis.send_command('RG.PYSTATS'); + return await this.sendCommand('RG.PYSTATS'); } catch(error) { return this.handleError(error); @@ -180,7 +182,7 @@ export class RedisGears extends Module { */ async pydumpreqs(): Promise { try { - return await this.redis.send_command('RG.PYDUMPREQS'); + return await this.sendCommand('RG.PYDUMPREQS'); } catch(error) { return this.handleError(error); @@ -192,7 +194,7 @@ export class RedisGears extends Module { */ async refreshCluster(): Promise<'OK'> { try { - return await this.redis.send_command('RG.REFRESHCLUSTER'); + return await this.sendCommand('RG.REFRESHCLUSTER'); } catch(error) { return this.handleError(error); @@ -206,7 +208,7 @@ export class RedisGears extends Module { */ async trigger(trigger: string, args: string[]): Promise { try { - return await this.redis.send_command('RG.TRIGGER', [trigger].concat(args)); + return await this.sendCommand('RG.TRIGGER', [trigger].concat(args)); } catch(error) { return this.handleError(error); @@ -219,7 +221,7 @@ export class RedisGears extends Module { */ async unregister(id: string): Promise<'OK'> { try { - return await this.redis.send_command('RG.UNREGISTER', [id]); + return await this.sendCommand('RG.UNREGISTER', [id]); } catch(error) { return this.handleError(error); diff --git a/modules/redisgraph.ts b/modules/redisgraph.ts index 81149da5..0d5d5845 100644 --- a/modules/redisgraph.ts +++ b/modules/redisgraph.ts @@ -1,15 +1,17 @@ import * as Redis from 'ioredis'; -import { Module } from './module.base'; +import { Module, RedisModuleOptions } from './module.base'; export class RedisGraph extends Module { /** * Initializing the RedisGraph object * @param options The options of the Redis database. - * @param throwError If to throw an exception on error. + * @param moduleOptions The additional module options + * @param moduleOptions.isHandleError If to throw error on error + * @param moduleOptions.showDebugLogs If to print debug logs */ - constructor(options: Redis.RedisOptions, throwError = true) { - super(RedisGraph.name, options, throwError) + constructor(options: Redis.RedisOptions, public moduleOptions?: RedisModuleOptions) { + super(RedisGraph.name, options, moduleOptions) } /** @@ -20,7 +22,7 @@ export class RedisGraph extends Module { */ async query(name: string, query: string): Promise { try { - return await this.redis.send_command('GRAPH.QUERY', [name, query]) + return await this.sendCommand('GRAPH.QUERY', [name, query]) } catch(error) { return this.handleError(error); @@ -35,7 +37,7 @@ export class RedisGraph extends Module { */ async readonlyQuery(name: string, query: string): Promise { try { - return await this.redis.send_command('GRAPH.RO_QUERY', [name, query]) + return await this.sendCommand('GRAPH.RO_QUERY', [name, query]) } catch(error) { return this.handleError(error); @@ -50,7 +52,7 @@ export class RedisGraph extends Module { */ async profile(name: string, query: string): Promise { try { - return await this.redis.send_command('GRAPH.PROFILE', [name, query]) + return await this.sendCommand('GRAPH.PROFILE', [name, query]) } catch(error) { return this.handleError(error); @@ -64,7 +66,7 @@ export class RedisGraph extends Module { */ async delete(name: string): Promise { try { - return await this.redis.send_command('GRAPH.DELETE', [name]) + return await this.sendCommand('GRAPH.DELETE', [name]) } catch(error) { return this.handleError(error); @@ -79,7 +81,7 @@ export class RedisGraph extends Module { */ async explain(name: string, query: string): Promise { try { - return await this.redis.send_command('GRAPH.EXPLAIN', [name, query]) + return await this.sendCommand('GRAPH.EXPLAIN', [name, query]) } catch(error) { return this.handleError(error); @@ -93,7 +95,7 @@ export class RedisGraph extends Module { */ async slowlog(id: number): Promise { try { - return await this.redis.send_command('GRAPH.SLOWLOG', [id]) + return await this.sendCommand('GRAPH.SLOWLOG', [id]) } catch(error) { return this.handleError(error); @@ -112,7 +114,7 @@ export class RedisGraph extends Module { const args = [command, option]; if(command === 'SET') args.push(value); - const response = await this.redis.send_command('GRAPH.CONFIG', args); + const response = await this.sendCommand('GRAPH.CONFIG', args); return this.handleResponse(response); } catch(error) { diff --git a/modules/rejson.ts b/modules/rejson.ts index 57f1da78..69a7ccd4 100644 --- a/modules/rejson.ts +++ b/modules/rejson.ts @@ -1,16 +1,18 @@ import * as Redis from 'ioredis'; -import { Module } from './module.base'; +import { Module, RedisModuleOptions } from './module.base'; export class ReJSON extends Module { /** * Initializing the ReJSON object * @param options The options of the Redis database. - * @param throwError If to throw an exception on error. + * @param moduleOptions The additional module options + * @param moduleOptions.isHandleError If to throw error on error + * @param moduleOptions.showDebugLogs If to print debug logs */ - constructor(options: Redis.RedisOptions, throwError = true) { - super(ReJSON.name, options, throwError) + constructor(options: Redis.RedisOptions, public moduleOptions?: RedisModuleOptions) { + super(ReJSON.name, options, moduleOptions) } /** @@ -23,7 +25,7 @@ export class ReJSON extends Module { try { const parameters = [key]; if(path !== undefined) parameters.push(path) - return await this.redis.send_command('JSON.DEL', parameters) + return await this.sendCommand('JSON.DEL', parameters) } catch(error) { return this.handleError(error); @@ -39,7 +41,7 @@ export class ReJSON extends Module { */ async set(key: string, path: string, json: string): Promise<"OK"> { try { - return await this.redis.send_command('JSON.SET', [key, path, json]) + return await this.sendCommand('JSON.SET', [key, path, json]) } catch(error) { return this.handleError(error); @@ -64,7 +66,7 @@ export class ReJSON extends Module { args.push(value); } if(path !== undefined) args.push(path); - return await this.redis.send_command('JSON.GET', args) + return await this.sendCommand('JSON.GET', args) } catch(error) { return this.handleError(error); @@ -81,7 +83,7 @@ export class ReJSON extends Module { try { const args = keys; if(path !== undefined) args.push(path); - return await this.redis.send_command('JSON.MGET', args) + return await this.sendCommand('JSON.MGET', args) } catch(error) { return this.handleError(error); @@ -98,7 +100,7 @@ export class ReJSON extends Module { try { const args = [key]; if(path !== undefined) args.push(path); - return await this.redis.send_command('JSON.TYPE', args) + return await this.sendCommand('JSON.TYPE', args) } catch(error) { return this.handleError(error); @@ -117,7 +119,7 @@ export class ReJSON extends Module { const args = [key]; if(path !== undefined) args.push(path); args.push(number.toString()) - return await this.redis.send_command('JSON.NUMINCRBY', args) + return await this.sendCommand('JSON.NUMINCRBY', args) } catch(error) { return this.handleError(error); @@ -136,7 +138,7 @@ export class ReJSON extends Module { const args = [key]; if(path !== undefined) args.push(path); args.push(number.toString()) - return await this.redis.send_command('JSON.NUMMULTBY', args) + return await this.sendCommand('JSON.NUMMULTBY', args) } catch(error) { return this.handleError(error); @@ -154,7 +156,7 @@ export class ReJSON extends Module { try { const args = [key]; if(path !== undefined) args.push(path); - return await this.redis.send_command('JSON.STRAPPEND', args.concat(string)); + return await this.sendCommand('JSON.STRAPPEND', args.concat(string)); } catch(error) { return this.handleError(error); @@ -171,7 +173,7 @@ export class ReJSON extends Module { try { const args = [key]; if(path !== undefined) args.push(path); - return await this.redis.send_command('JSON.STRLEN', args); + return await this.sendCommand('JSON.STRLEN', args); } catch(error) { return this.handleError(error); @@ -189,7 +191,7 @@ export class ReJSON extends Module { try { const args = [key]; if(path !== undefined) args.push(path); - return await this.redis.send_command('JSON.ARRAPPEND', args.concat(items)); + return await this.sendCommand('JSON.ARRAPPEND', args.concat(items)); } catch(error) { return this.handleError(error); @@ -208,7 +210,7 @@ export class ReJSON extends Module { const args = [key]; if(path !== undefined) args.push(path); args.push(scalar); - return await this.redis.send_command('JSON.ARRINDEX', args); + return await this.sendCommand('JSON.ARRINDEX', args); } catch(error) { return this.handleError(error); @@ -229,7 +231,7 @@ export class ReJSON extends Module { if(path !== undefined) args.push(path); args.push(index.toString()); args.push(json); - return await this.redis.send_command('JSON.ARRINSERT', args); + return await this.sendCommand('JSON.ARRINSERT', args); } catch(error) { return this.handleError(error); @@ -246,7 +248,7 @@ export class ReJSON extends Module { try { const args = [key]; if(path !== undefined) args.push(path); - return await this.redis.send_command('JSON.ARRLEN', args); + return await this.sendCommand('JSON.ARRLEN', args); } catch(error) { return this.handleError(error); @@ -265,7 +267,7 @@ export class ReJSON extends Module { const args = [key]; if(path !== undefined) args.push(path); args.push(index.toString()); - return await this.redis.send_command('JSON.ARRPOP', args); + return await this.sendCommand('JSON.ARRPOP', args); } catch(error) { return this.handleError(error); @@ -286,7 +288,7 @@ export class ReJSON extends Module { if(path !== undefined) args.push(path); args.push(start.toString()); args.push(end.toString()); - return await this.redis.send_command('JSON.ARRTRIM', args); + return await this.sendCommand('JSON.ARRTRIM', args); } catch(error) { return this.handleError(error); @@ -303,7 +305,7 @@ export class ReJSON extends Module { try { const args = [key]; if(path !== undefined) args.push(path); - return await this.redis.send_command('JSON.OBJKEYS', args); + return await this.sendCommand('JSON.OBJKEYS', args); } catch(error) { return this.handleError(error); @@ -320,7 +322,7 @@ export class ReJSON extends Module { try { const args = [key]; if(path !== undefined) args.push(path); - return await this.redis.send_command('JSON.OBJLEN', args); + return await this.sendCommand('JSON.OBJLEN', args); } catch(error) { return this.handleError(error); @@ -343,7 +345,7 @@ export class ReJSON extends Module { if(key !== undefined) args.push(key); if(path !== undefined) args.push(path); } - return await this.redis.send_command('JSON.DEBUG', args); + return await this.sendCommand('JSON.DEBUG', args); } catch(error) { return this.handleError(error); @@ -360,7 +362,7 @@ export class ReJSON extends Module { try { const parameters = [key]; if(path !== undefined) parameters.push(path) - return await this.redis.send_command('JSON.FORGET', parameters) + return await this.sendCommand('JSON.FORGET', parameters) } catch(error) { return this.handleError(error); @@ -377,7 +379,7 @@ export class ReJSON extends Module { try { const parameters = [key]; if(path !== undefined) parameters.push(path) - return await this.redis.send_command('JSON.RESP', parameters) + return await this.sendCommand('JSON.RESP', parameters) } catch(error) { return this.handleError(error); diff --git a/modules/ris.ts b/modules/ris.ts index 6d227279..cdd584d9 100644 --- a/modules/ris.ts +++ b/modules/ris.ts @@ -1,15 +1,17 @@ import * as Redis from 'ioredis'; -import { Module } from './module.base'; +import { Module, RedisModuleOptions } from './module.base'; export class RedisIntervalSets extends Module { /** * Initializing the RedisIntervalSets object * @param options The options of the Redis database. - * @param throwError If to throw an exception on error. + * @param moduleOptions The additional module options + * @param moduleOptions.isHandleError If to throw error on error + * @param moduleOptions.showDebugLogs If to print debug logs */ - constructor(options: Redis.RedisOptions, throwError = true) { - super(RedisIntervalSets.name, options, throwError) + constructor(options: Redis.RedisOptions, public moduleOptions?: RedisModuleOptions) { + super(RedisIntervalSets.name, options, moduleOptions) } /** @@ -22,7 +24,7 @@ export class RedisIntervalSets extends Module { let args: (number | string)[] = [key]; for(const set of sets) args = args.concat([set.name, set.minimum, set.maximum]) - return await this.redis.send_command('iset.add', args) + return await this.sendCommand('iset.add', args) } catch(error) { return this.handleError(error); @@ -39,7 +41,7 @@ export class RedisIntervalSets extends Module { const args = [key]; if(setName) args.push(setName) - const response = await this.redis.send_command('iset.get', args) + const response = await this.sendCommand('iset.get', args) return this.parseGet(response) } catch(error) { @@ -54,7 +56,7 @@ export class RedisIntervalSets extends Module { */ async del(key: string, setNames?: string[]): Promise<'OK'> { try { - return await this.redis.send_command('iset.del', [key].concat(setNames)) + return await this.sendCommand('iset.del', [key].concat(setNames)) } catch(error) { return this.handleError(error); @@ -68,7 +70,7 @@ export class RedisIntervalSets extends Module { */ async score(key: string, score: number): Promise { try { - return await this.redis.send_command('iset.score', [key, score]) + return await this.sendCommand('iset.score', [key, score]) } catch(error) { return this.handleError(error); @@ -82,7 +84,7 @@ export class RedisIntervalSets extends Module { */ async notScore(key: string, score: number): Promise { try { - return await this.redis.send_command('iset.not_score', [key, score]) + return await this.sendCommand('iset.not_score', [key, score]) } catch(error) { return this.handleError(error); diff --git a/modules/rts.ts b/modules/rts.ts index f0129482..1a0a94bd 100644 --- a/modules/rts.ts +++ b/modules/rts.ts @@ -1,16 +1,18 @@ import * as Redis from 'ioredis'; -import { Module } from './module.base'; +import { Module, RedisModuleOptions } from './module.base'; export class RedisTimeSeries extends Module { /** * Initializing the RTS object. * @param options The options of the Redis database. - * @param throwError If to throw an exception on error. + * @param moduleOptions The additional module options + * @param moduleOptions.isHandleError If to throw error on error + * @param moduleOptions.showDebugLogs If to print debug logs */ - constructor(options: Redis.RedisOptions, throwError = true) { - super(RedisTimeSeries.name, options, throwError) + constructor(options: Redis.RedisOptions, public moduleOptions?: RedisModuleOptions) { + super(RedisTimeSeries.name, options, moduleOptions) } /** @@ -41,7 +43,7 @@ export class RedisTimeSeries extends Module { args = args.concat([label.name, label.value]) } } - return await this.redis.send_command('TS.CREATE', args) + return await this.sendCommand('TS.CREATE', args) } catch(error) { return this.handleError(error); @@ -66,7 +68,7 @@ export class RedisTimeSeries extends Module { args = args.concat([label.name, label.value]); } } - return await this.redis.send_command('TS.ALTER', args) + return await this.sendCommand('TS.ALTER', args) } catch(error) { return this.handleError(error); @@ -102,7 +104,7 @@ export class RedisTimeSeries extends Module { args = args.concat([label.name, label.value]); } } - return await this.redis.send_command('TS.ADD', args); + return await this.sendCommand('TS.ADD', args); } catch(error) { return this.handleError(error); @@ -121,7 +123,7 @@ export class RedisTimeSeries extends Module { let args: string[] = [] for(const keySet of keySets) args = args.concat([keySet.key, keySet.timestamp, keySet.value]); - return await this.redis.send_command('TS.MADD', args); + return await this.sendCommand('TS.MADD', args); } catch(error) { return this.handleError(error); @@ -154,7 +156,7 @@ export class RedisTimeSeries extends Module { args = args.concat([label.name, label.value]); } } - return await this.redis.send_command('TS.INCRBY', args); + return await this.sendCommand('TS.INCRBY', args); } catch(error) { return this.handleError(error); @@ -187,7 +189,7 @@ export class RedisTimeSeries extends Module { args = args.concat([label.name, label.value]); } } - return await this.redis.send_command('TS.DECRBY', args); + return await this.sendCommand('TS.DECRBY', args); } catch(error) { return this.handleError(error); @@ -205,7 +207,7 @@ export class RedisTimeSeries extends Module { async createrule(parameters: TSCreateRule): Promise<'OK'> { try { const args = [parameters.sourceKey, parameters.destKey, 'AGGREGATION', parameters.aggregation, parameters.timeBucket.toString()] - return await this.redis.send_command('TS.CREATERULE', args); + return await this.sendCommand('TS.CREATERULE', args); } catch(error) { return this.handleError(error); @@ -219,7 +221,7 @@ export class RedisTimeSeries extends Module { */ async deleterule(sourceKey: string, destKey: string): Promise<'OK'> { try { - return await this.redis.send_command('TS.DELETERULE', sourceKey, destKey) + return await this.sendCommand('TS.DELETERULE', [sourceKey, destKey]) } catch(error) { return this.handleError(error); @@ -244,7 +246,7 @@ export class RedisTimeSeries extends Module { args = args.concat(['COUNT', options.count.toString()]); if(options !== undefined && options.aggregation !== undefined) args = args.concat(['AGGREGATION', options.aggregation.type, options.aggregation.timeBucket.toString()]); - return await this.redis.send_command('TS.RANGE', args) + return await this.sendCommand('TS.RANGE', args) } catch(error) { return this.handleError(error); @@ -269,7 +271,7 @@ export class RedisTimeSeries extends Module { args = args.concat(['COUNT', options.count.toString()]); if(options !== undefined && options.aggregation !== undefined) args = args.concat(['AGGREGATION', options.aggregation.type, options.aggregation.timeBucket.toString()]); - return await this.redis.send_command('TS.REVRANGE', args) + return await this.sendCommand('TS.REVRANGE', args) } catch(error) { return this.handleError(error); @@ -300,7 +302,7 @@ export class RedisTimeSeries extends Module { if(options !== undefined && options.groupBy) args = args.concat(['GROUPBY', options.groupBy.label, 'REDUCE', options.groupBy.reducer]) args = args.concat(['FILTER', filter]) - return await this.redis.send_command('TS.MRANGE', args) + return await this.sendCommand('TS.MRANGE', args) } catch(error) { return this.handleError(error); @@ -331,7 +333,7 @@ export class RedisTimeSeries extends Module { if(options !== undefined && options.groupBy) args = args.concat(['GROUPBY', options.groupBy.label, 'REDUCE', options.groupBy.reducer]) args = args.concat(['FILTER', filter]) - return await this.redis.send_command('TS.MREVRANGE', args) + return await this.sendCommand('TS.MREVRANGE', args) } catch(error) { return this.handleError(error); @@ -344,7 +346,7 @@ export class RedisTimeSeries extends Module { */ async get(key: string): Promise<(string | number)[]> { try { - return await this.redis.send_command('TS.GET', key); + return await this.sendCommand('TS.GET', key); } catch(error) { return this.handleError(error); @@ -362,7 +364,7 @@ export class RedisTimeSeries extends Module { if(withLabels === true) args.push('WITHLABELS'); args = args.concat(['FILTER', filter]) - return await this.redis.send_command('TS.MGET', args); + return await this.sendCommand('TS.MGET', args); } catch(error) { return this.handleError(error); @@ -375,7 +377,7 @@ export class RedisTimeSeries extends Module { */ async info(key: string): Promise { try { - const response = await this.redis.send_command('TS.INFO', key); + const response = await this.sendCommand('TS.INFO', key); const info: TSInfo = {}; for(let i = 0; i < response.length; i+=2) { info[response[i]] = response[i+1]; @@ -393,7 +395,7 @@ export class RedisTimeSeries extends Module { */ async queryindex(filter: string): Promise { try { - return await this.redis.send_command('TS.QUERYINDEX', filter); + return await this.sendCommand('TS.QUERYINDEX', filter); } catch(error) { return this.handleError(error); diff --git a/package.json b/package.json index 40da3454..ecace156 100644 --- a/package.json +++ b/package.json @@ -17,8 +17,8 @@ "redisbloom-topk-filter-tests": "npm run test tests/redisbloom-topk.ts -- -- --host=127.0.0.1 --port=6379", "redisbloom-cuckoo-filter-tests": "npm run test tests/redisbloom-cuckoo.ts -- -- --host=127.0.0.1 --port=6379", "redisbloom-cmk-filter-tests": "npm run test tests/redisbloom-cmk.ts -- -- --host=127.0.0.1 --port=6379", - "redis-ai-tests": "npm run test tests/redis-ai.ts -- -- --host=127.0.0.1 --port=6379", - "ris-tests": "npm run test tests/ris.ts -- -- --host=127.0.0.1 --port=6379", + "redis-ai-module-tests": "npm run test tests/redis-ai.ts -- -- --host=127.0.0.1 --port=6379", + "ris-module-tests": "npm run test tests/ris.ts -- -- --host=127.0.0.1 --port=6379", "redis-module-base-tests": "npm run test tests/module-base.ts", "tests": "npm run rejson-module-tests && npm run rts-module-tests && npm run redisearch-module-tests && npm run redisgraph-module-tests && npm run redisgears-module-tests && npm run redisbloom-module-tests && npm run redis-ai-tests", "pre-deploy": "npm run build", diff --git a/tests/module-base.ts b/tests/module-base.ts index a39aab5f..2bfbdf40 100644 --- a/tests/module-base.ts +++ b/tests/module-base.ts @@ -8,7 +8,7 @@ describe('AI testing', async function() { client = new Module('Module', { host: cliArguments.host, port: parseInt(cliArguments.port), - }, false); + }, { isHandleError: false }); }) it('handleResponse function', async () => {