Skip to content
This repository was archived by the owner on Jul 6, 2024. It is now read-only.

Commit 192ca9c

Browse files
author
mjm2312
authored
RTS client updates and bug fixes(#213)
* Enhancement: Adds support to update duplicatePolicy, chunkSize in TS.ALTER calls: [TS.ALTER](https://redis.io/commands/ts.alter/) * Bug Fix: Changes duplicate policy from boolean | undefined to string | undefined: [TS.INFO](https://redis.io/commands/ts.alter/) * Bug Fix: Allows a list of args for TS.QUERYINDEX [TS.QUERYINDEX](https://redis.io/commands/ts.queryindex/)
1 parent 4765656 commit 192ca9c

File tree

4 files changed

+40
-14
lines changed

4 files changed

+40
-14
lines changed

modules/rts/rts.commander.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { CommandData } from "../module.base";
2-
import { TSAddOptions, TSCreateOptions, TSCreateRule, TSIncrbyDecrbyOptions, TSKeySet, TSLabel, TSMRangeOptions, TSRangeOptions } from "./rts.types";
2+
import { TSAddOptions, TSCreateOptions, TSCreateRule, TSIncrbyDecrbyOptions, TSKeySet, TSLabel, TSMRangeOptions, TSRangeOptions, TSAlterOptions } from "./rts.types";
33

44
export class RedisTimeSeriesCommander {
55

@@ -39,12 +39,16 @@ export class RedisTimeSeriesCommander {
3939
/**
4040
* Altering an existing TS key
4141
* @param key Required. The key
42-
* @param retention Optional. The retention time
43-
* @param labels Optional. The labels to update
42+
* @param options.retention Optional. The retention time
43+
* @param options.labels Optional. The labels to update
44+
* @param options.duplicatePolicy Optional. An update to the duplicate policy
45+
* @param options.chunkSize Optional. An update to the chunk size
4446
*
4547
*/
46-
alter(key: string, retention?: number, labels?: TSLabel[]): CommandData {
48+
alter(key: string, options?: TSAlterOptions): CommandData {
4749
let args = [key];
50+
const {retention, labels, duplicatePolicy, chunkSize} = options;
51+
4852
if(retention !== undefined)
4953
args = args.concat(['RETENTION', retention.toString()]);
5054
if(labels !== undefined && labels.length > 0) {
@@ -53,6 +57,12 @@ export class RedisTimeSeriesCommander {
5357
args = args.concat([label.name, label.value]);
5458
}
5559
}
60+
if(duplicatePolicy !== undefined) {
61+
args = args.concat(['DUPLICATE_POLICY', duplicatePolicy])
62+
}
63+
if(chunkSize !== undefined) {
64+
args = args.concat(['CHUNK_SIZE', `${chunkSize}`])
65+
}
5666
return {
5767
command: 'TS.ALTER',
5868
args: args
@@ -386,7 +396,7 @@ export class RedisTimeSeriesCommander {
386396
queryindex(filter: string): CommandData {
387397
return {
388398
command: 'TS.QUERYINDEX',
389-
args: [filter]
399+
args: filter.split(' ')
390400
}
391401
}
392402

modules/rts/rts.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as Redis from 'ioredis';
22
import { Module, RedisModuleOptions } from '../module.base';
33
import { RedisTimeSeriesCommander } from './rts.commander';
44
import {
5-
TSAddOptions, TSCreateOptions, TSCreateRule, TSIncrbyDecrbyOptions, TSInfo, TSKeySet, TSLabel,
5+
TSAddOptions, TSAlterOptions, TSCreateOptions, TSCreateRule, TSIncrbyDecrbyOptions, TSInfo, TSKeySet,
66
TSMRangeOptions, TSRangeOptions
77
} from './rts.types';
88

@@ -51,12 +51,14 @@ export class RedisTimeSeries extends Module {
5151
/**
5252
* Altering an existing TS key
5353
* @param key Required. The key
54-
* @param retention Optional. The retention time
55-
* @param labels Optional. The labels to update
54+
* @param options.onDuplicate The 'ON_DUPLICATE' optional parameter
55+
* @param options.retention The 'RETENTION' optional parameter
56+
* @param options.chunkSize The 'CHUNK_SIZE' optional parameter
57+
* @param options.labels A list of 'LABELS' optional parameter
5658
*
5759
*/
58-
async alter(key: string, retention?: number, labels?: TSLabel[]): Promise<'OK'> {
59-
const command = this.rtsCommander.alter(key, retention, labels);
60+
async alter(key: string, options?: TSAlterOptions): Promise<'OK'> {
61+
const command = this.rtsCommander.alter(key, options);
6062
return await this.sendCommand(command);
6163
}
6264

modules/rts/rts.types.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export type TSInfo = {
2020
retentionTime?: number,
2121
chunkCount?: number,
2222
chunkSize?: number,
23-
duplicatePolicy?: boolean | null,
23+
duplicatePolicy?: TSDuplicatePolicyType,
2424
labels?: Array<string[]>,
2525
sourceKey?: string | null,
2626
rules?: Array<string[]>,
@@ -35,9 +35,8 @@ export type TSInfo = {
3535
* @param duplicatePolicy The 'DUPLICATE_POLICY' optional parameter
3636
*/
3737
export interface TSCreateOptions extends TSOptions {
38-
duplicatePolicy?: string
38+
duplicatePolicy?: TSDuplicatePolicyType
3939
}
40-
4140
/**
4241
* The label object
4342
* @param name The name of the label
@@ -60,6 +59,20 @@ export interface TSAddOptions extends TSOptions {
6059
onDuplicate?: TSDuplicatePolicyType
6160
}
6261

62+
/**
63+
* The 'TS.ALTER' command optional parameters
64+
* @param retention The 'RETENTION' optional parameter
65+
* @param chunkSize The 'CHUNK_SIZE' optional parameter
66+
* @param duplicatePolicy The DUPLICATE_POLICY optional parameter
67+
* @param labels A list of 'LABELS' optional parameter
68+
*/
69+
export type TSAlterOptions = {
70+
retention?: number,
71+
chunkSize?: number,
72+
duplicatePolicy?: TSDuplicatePolicyType,
73+
labels?: TSLabel[]
74+
}
75+
6376
/**
6477
* The available Duplicate policy types. Policy that will define handling of duplicate samples.
6578
* @param BLOCK an error will occur for any out of order sample
@@ -102,6 +115,7 @@ export interface TSIncrbyDecrbyOptions extends TSOptions {
102115
* @param chunkSize The 'CHUNK_SIZE' optional parameter
103116
* @param labels A list of 'LABELS' optional parameter
104117
*/
118+
105119
export type TSOptions = {
106120
retention?: number,
107121
uncompressed?: boolean,

tests/rts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe('RTS Module testing', async function() {
3535
});
3636

3737
it('alter function', async () => {
38-
const response = await redis.rts_module_alter(key1, 1);
38+
const response = await redis.rts_module_alter(key1,{retention: 1});
3939
expect(response).to.equal('OK', 'The response of the alter command');
4040
});
4141
it('add function', async () => {

0 commit comments

Comments
 (0)