Skip to content

Commit 5dd7d31

Browse files
authored
close #2192 close #2193 close #2194 close #2195 close #2196 close #2197 close #2198 - support for TimeSeries 1.8 (#2200)
1 parent b10a656 commit 5dd7d31

25 files changed

+369
-181
lines changed

packages/time-series/lib/commands/ALTER.spec.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { strict as assert } from 'assert';
2+
import { TimeSeriesDuplicatePolicies } from '.';
23
import testUtils, { GLOBAL } from '../test-utils';
34
import { transformArguments } from './ALTER';
45

@@ -20,6 +21,24 @@ describe('ALTER', () => {
2021
);
2122
});
2223

24+
it('with CHUNK_SIZE', () => {
25+
assert.deepEqual(
26+
transformArguments('key', {
27+
CHUNK_SIZE: 1
28+
}),
29+
['TS.ALTER', 'key', 'CHUNK_SIZE', '1']
30+
);
31+
});
32+
33+
it('with DUPLICATE_POLICY', () => {
34+
assert.deepEqual(
35+
transformArguments('key', {
36+
DUPLICATE_POLICY: TimeSeriesDuplicatePolicies.BLOCK
37+
}),
38+
['TS.ALTER', 'key', 'DUPLICATE_POLICY', 'BLOCK']
39+
);
40+
});
41+
2342
it('with LABELS', () => {
2443
assert.deepEqual(
2544
transformArguments('key', {
@@ -29,19 +48,21 @@ describe('ALTER', () => {
2948
);
3049
});
3150

32-
it('with RETENTION, LABELS', () => {
51+
it('with RETENTION, CHUNK_SIZE, DUPLICATE_POLICY, LABELS', () => {
3352
assert.deepEqual(
3453
transformArguments('key', {
3554
RETENTION: 1,
55+
CHUNK_SIZE: 1,
56+
DUPLICATE_POLICY: TimeSeriesDuplicatePolicies.BLOCK,
3657
LABELS: { label: 'value' }
3758
}),
38-
['TS.ALTER', 'key', 'RETENTION', '1', 'LABELS', 'label', 'value']
59+
['TS.ALTER', 'key', 'RETENTION', '1', 'CHUNK_SIZE', '1', 'DUPLICATE_POLICY', 'BLOCK', 'LABELS', 'label', 'value']
3960
);
4061
});
4162
});
4263

4364
testUtils.testWithClient('client.ts.alter', async client => {
44-
await client.ts.create('key');
65+
await client.ts.create('key');
4566

4667
assert.equal(
4768
await client.ts.alter('key', { RETENTION: 1 }),

packages/time-series/lib/commands/ALTER.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import { pushRetentionArgument, Labels, pushLabelsArgument } from '.';
1+
import { pushRetentionArgument, Labels, pushLabelsArgument, TimeSeriesDuplicatePolicies, pushChunkSizeArgument, pushDuplicatePolicy } from '.';
22

33
export const FIRST_KEY_INDEX = 1;
44

55
interface AlterOptions {
66
RETENTION?: number;
7+
CHUNK_SIZE?: number;
8+
DUPLICATE_POLICY?: TimeSeriesDuplicatePolicies;
79
LABELS?: Labels;
810
}
911

@@ -12,6 +14,10 @@ export function transformArguments(key: string, options?: AlterOptions): Array<s
1214

1315
pushRetentionArgument(args, options?.RETENTION);
1416

17+
pushChunkSizeArgument(args, options?.CHUNK_SIZE);
18+
19+
pushDuplicatePolicy(args, options?.DUPLICATE_POLICY);
20+
1521
pushLabelsArgument(args, options?.LABELS);
1622

1723
return args;

packages/time-series/lib/commands/CREATE.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import {
55
pushChunkSizeArgument,
66
TimeSeriesDuplicatePolicies,
77
Labels,
8-
pushLabelsArgument
8+
pushLabelsArgument,
9+
pushDuplicatePolicy
910
} from '.';
1011

1112
export const FIRST_KEY_INDEX = 1;
@@ -27,12 +28,7 @@ export function transformArguments(key: string, options?: CreateOptions): Array<
2728

2829
pushChunkSizeArgument(args, options?.CHUNK_SIZE);
2930

30-
if (options?.DUPLICATE_POLICY) {
31-
args.push(
32-
'DUPLICATE_POLICY',
33-
options.DUPLICATE_POLICY
34-
);
35-
}
31+
pushDuplicatePolicy(args, options?.DUPLICATE_POLICY);
3632

3733
pushLabelsArgument(args, options?.LABELS);
3834

packages/time-series/lib/commands/CREATERULE.spec.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,20 @@ import testUtils, { GLOBAL } from '../test-utils';
44
import { transformArguments } from './CREATERULE';
55

66
describe('CREATERULE', () => {
7-
it('transformArguments', () => {
8-
assert.deepEqual(
9-
transformArguments('source', 'destination', TimeSeriesAggregationType.AVERAGE, 1),
10-
['TS.CREATERULE', 'source', 'destination', 'AGGREGATION', 'avg', '1']
11-
);
7+
describe('transformArguments', () => {
8+
it('without options', () => {
9+
assert.deepEqual(
10+
transformArguments('source', 'destination', TimeSeriesAggregationType.AVERAGE, 1),
11+
['TS.CREATERULE', 'source', 'destination', 'AGGREGATION', 'AVG', '1']
12+
);
13+
});
14+
15+
it('with alignTimestamp', () => {
16+
assert.deepEqual(
17+
transformArguments('source', 'destination', TimeSeriesAggregationType.AVERAGE, 1, 1),
18+
['TS.CREATERULE', 'source', 'destination', 'AGGREGATION', 'AVG', '1', '1']
19+
);
20+
});
1221
});
1322

1423
testUtils.testWithClient('client.ts.createRule', async client => {

packages/time-series/lib/commands/CREATERULE.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,23 @@ export function transformArguments(
66
sourceKey: string,
77
destinationKey: string,
88
aggregationType: TimeSeriesAggregationType,
9-
timeBucket: number
9+
bucketDuration: number,
10+
alignTimestamp?: number
1011
): Array<string> {
11-
return [
12+
const args = [
1213
'TS.CREATERULE',
1314
sourceKey,
1415
destinationKey,
1516
'AGGREGATION',
1617
aggregationType,
17-
timeBucket.toString()
18+
bucketDuration.toString()
1819
];
20+
21+
if (alignTimestamp) {
22+
args.push(alignTimestamp.toString());
23+
}
24+
25+
return args;
1926
}
2027

2128
export declare function transformReply(): 'OK';

packages/time-series/lib/commands/DELETERULE.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export function transformArguments(sourceKey: string, destinationKey: string): A
44
return [
55
'TS.DELETERULE',
66
sourceKey,
7-
destinationKey,
7+
destinationKey
88
];
99
}
1010

packages/time-series/lib/commands/GET.spec.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,22 @@ import testUtils, { GLOBAL } from '../test-utils';
33
import { transformArguments } from './GET';
44

55
describe('GET', () => {
6-
it('transformArguments', () => {
7-
assert.deepEqual(
8-
transformArguments('key'),
9-
['TS.GET', 'key']
10-
);
6+
describe('transformArguments', () => {
7+
it('without options', () => {
8+
assert.deepEqual(
9+
transformArguments('key'),
10+
['TS.GET', 'key']
11+
);
12+
});
13+
14+
it('with LATEST', () => {
15+
assert.deepEqual(
16+
transformArguments('key', {
17+
LATEST: true
18+
}),
19+
['TS.GET', 'key', 'LATEST']
20+
);
21+
});
1122
});
1223

1324
describe('client.ts.get', () => {

packages/time-series/lib/commands/GET.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
import { SampleRawReply, SampleReply, transformSampleReply } from '.';
1+
import { RedisCommandArguments } from '@redis/client/dist/lib/commands';
2+
import { pushLatestArgument, SampleRawReply, SampleReply, transformSampleReply } from '.';
23

34
export const FIRST_KEY_INDEX = 1;
45

56
export const IS_READ_ONLY = true;
67

7-
export function transformArguments(key: string): Array<string> {
8-
return ['TS.GET', key];
8+
interface GetOptions {
9+
LATEST?: boolean;
10+
}
11+
12+
export function transformArguments(key: string, options?: GetOptions): RedisCommandArguments {
13+
return pushLatestArgument(['TS.GET', key], options?.LATEST);
914
}
1015

1116
export function transformReply(reply: [] | SampleRawReply): null | SampleReply {
Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { strict as assert } from 'assert';
22
import { TimeSeriesAggregationType, TimeSeriesDuplicatePolicies } from '.';
33
import testUtils, { GLOBAL } from '../test-utils';
4-
import { transformArguments } from './INFO';
4+
import { InfoReply, transformArguments } from './INFO';
55

66
describe('INFO', () => {
77
it('transformArguments', () => {
@@ -14,37 +14,40 @@ describe('INFO', () => {
1414
testUtils.testWithClient('client.ts.info', async client => {
1515
await Promise.all([
1616
client.ts.create('key', {
17-
LABELS: { id: "2" },
17+
LABELS: { id: '1' },
1818
DUPLICATE_POLICY: TimeSeriesDuplicatePolicies.LAST
1919
}),
2020
client.ts.create('key2'),
2121
client.ts.createRule('key', 'key2', TimeSeriesAggregationType.COUNT, 5),
2222
client.ts.add('key', 1, 10)
2323
]);
2424

25-
assert.deepEqual(
26-
await client.ts.info('key'),
27-
{
28-
totalSamples: 1,
29-
memoryUsage: 4261,
30-
firstTimestamp: 1,
31-
lastTimestamp: 1,
32-
retentionTime: 0,
33-
chunkCount: 1,
34-
chunkSize: 4096,
35-
chunkType: 'compressed',
36-
duplicatePolicy: 'last',
37-
labels: [{
38-
name: 'id',
39-
value: '2'
40-
}],
41-
rules: [{
42-
aggregationType: 'COUNT',
43-
key: 'key2',
44-
timeBucket: 5
45-
}],
46-
sourceKey: null
47-
}
48-
);
25+
assertInfo(await client.ts.info('key'));
4926
}, GLOBAL.SERVERS.OPEN);
5027
});
28+
29+
export function assertInfo(info: InfoReply): void {
30+
assert.equal(typeof info.totalSamples, 'number');
31+
assert.equal(typeof info.memoryUsage, 'number');
32+
assert.equal(typeof info.firstTimestamp, 'number');
33+
assert.equal(typeof info.lastTimestamp, 'number');
34+
assert.equal(typeof info.retentionTime, 'number');
35+
assert.equal(typeof info.chunkCount, 'number');
36+
assert.equal(typeof info.chunkSize, 'number');
37+
assert.equal(typeof info.chunkType, 'string');
38+
assert.equal(typeof info.duplicatePolicy, 'string');
39+
assert.ok(Array.isArray(info.labels));
40+
for (const label of info.labels) {
41+
assert.equal(typeof label, 'object');
42+
assert.equal(typeof label.name, 'string');
43+
assert.equal(typeof label.value, 'string');
44+
}
45+
assert.ok(Array.isArray(info.rules));
46+
for (const rule of info.rules) {
47+
assert.equal(typeof rule, 'object');
48+
assert.equal(typeof rule.aggregationType, 'string');
49+
assert.equal(typeof rule.key, 'string');
50+
assert.equal(typeof rule.timeBucket, 'number');
51+
}
52+
assert.ok(info.sourceKey === null || typeof info.sourceKey === 'string');
53+
}

packages/time-series/lib/commands/INFO.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,30 @@ export function transformArguments(key: string): Array<string> {
99
}
1010

1111
export type InfoRawReply = [
12-
_: string,
13-
totalSamples: number,
14-
_: string,
15-
memoryUsage: number,
16-
_: string,
17-
firstTimestamp: number,
18-
_: string,
19-
lastTimestamp: number,
20-
_: string,
21-
retentionTime: number,
22-
_: string,
23-
chunkCount: number,
24-
_: string,
25-
chunkSize: number,
26-
_: string,
27-
chunkType: string,
28-
_: string,
29-
duplicatePolicy: TimeSeriesDuplicatePolicies | null,
30-
_: string,
31-
labels: Array<[name: string, value: string]>,
32-
_: string,
33-
sourceKey: string | null,
34-
_: string,
35-
rules: Array<[key: string, timeBucket: number, aggregationType: TimeSeriesAggregationType]>
12+
'totalSamples',
13+
number,
14+
'memoryUsage',
15+
number,
16+
'firstTimestamp',
17+
number,
18+
'lastTimestamp',
19+
number,
20+
'retentionTime',
21+
number,
22+
'chunkCount',
23+
number,
24+
'chunkSize',
25+
number,
26+
'chunkType',
27+
string,
28+
'duplicatePolicy',
29+
TimeSeriesDuplicatePolicies | null,
30+
'labels',
31+
Array<[name: string, value: string]>,
32+
'sourceKey',
33+
string | null,
34+
'rules',
35+
Array<[key: string, timeBucket: number, aggregationType: TimeSeriesAggregationType]>
3636
];
3737

3838
export interface InfoReply {

0 commit comments

Comments
 (0)