Skip to content

Commit f648f37

Browse files
committed
init time series
1 parent bc1bf7e commit f648f37

29 files changed

+1226
-0
lines changed

packages/time-series/.nycrc.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "@istanbuljs/nyc-config-typescript",
3+
"exclude": ["**/*.spec.ts", "lib/test-utils.ts"]
4+
}

packages/time-series/.release-it.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"git": {
3+
"tagName": "search@${version}",
4+
"commitMessage": "Release ${tagName}",
5+
"tagAnnotation": "Release ${tagName}"
6+
},
7+
"npm": {
8+
"publishArgs": ["--access", "public"]
9+
}
10+
}

packages/time-series/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# @node-redis/search
2+
The sources and docs for this package are in the main [node-redis](https://github.com/redis/node-redis) repo.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { strict as assert } from 'assert';
2+
import testUtils, { GLOBAL } from '../test-utils';
3+
import { transformArguments } from './ADD';
4+
import { TimeSeriesDuplicatePolicies, TimeSeriesEncoding } from '.';
5+
6+
describe('ADD', () => {
7+
describe('transformArguments', () => {
8+
it('without options', () => {
9+
assert.deepEqual(
10+
transformArguments('key', '*', 1),
11+
['TS.ADD', 'key', '*', '1']
12+
);
13+
});
14+
15+
it('with RETENTION', () => {
16+
assert.deepEqual(
17+
transformArguments('key', '*', 1, {
18+
RETENTION: 1
19+
}),
20+
['TS.ADD', 'key', '*', '1', 'RETENTION', '1']
21+
);
22+
});
23+
24+
it('with ENCODING', () => {
25+
assert.deepEqual(
26+
transformArguments('key', '*', 1, {
27+
ENCODING: TimeSeriesEncoding.UNCOMPRESSED
28+
}),
29+
['TS.ADD', 'key', '*', '1', 'ENCODING', 'UNCOMPRESSED']
30+
);
31+
});
32+
33+
it('with CHUNK_SIZE', () => {
34+
assert.deepEqual(
35+
transformArguments('key', '*', 1, {
36+
CHUNK_SIZE: 1
37+
}),
38+
['TS.ADD', 'key', '*', '1', 'CHUNK_SIZE', '1']
39+
);
40+
});
41+
42+
it('with ON_DUPLICATE', () => {
43+
assert.deepEqual(
44+
transformArguments('key', '*', 1, {
45+
ON_DUPLICATE: TimeSeriesDuplicatePolicies.BLOCK
46+
}),
47+
['TS.ADD', 'key', '*', '1', 'ON_DUPLICATE', 'BLOCK']
48+
);
49+
});
50+
51+
it('with LABELS', () => {
52+
assert.deepEqual(
53+
transformArguments('key', '*', 1, {
54+
LABELS: { label: 'value' }
55+
}),
56+
['TS.ADD', 'key', '*', '1', 'LABELS', 'label', 'value']
57+
);
58+
});
59+
60+
it('with RETENTION, ENCODING, CHUNK_SIZE, ON_DUPLICATE, LABELS', () => {
61+
assert.deepEqual(
62+
transformArguments('key', '*', 1, {
63+
RETENTION: 1,
64+
ENCODING: TimeSeriesEncoding.UNCOMPRESSED,
65+
CHUNK_SIZE: 1,
66+
ON_DUPLICATE: TimeSeriesDuplicatePolicies.BLOCK,
67+
LABELS: { label: 'value' }
68+
}),
69+
['TS.ADD', 'key', '*', '1', 'RETENTION', '1', 'ENCODING', 'UNCOMPRESSED', 'CHUNK_SIZE', '1', 'ON_DUPLICATE', 'BLOCK', 'LABELS', 'label', 'value']
70+
);
71+
});
72+
});
73+
74+
testUtils.testWithClient('client.ts.add', async client => {
75+
assert.equal(
76+
await client.ts.add('key', 0, 1),
77+
0
78+
);
79+
}, GLOBAL.SERVERS.OPEN);
80+
});
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import {
2+
transformTimestampArgument,
3+
pushRetentionArgument,
4+
TimeSeriesEncoding,
5+
pushEncodingArgument,
6+
pushChunkSizeArgument,
7+
TimeSeriesDuplicatePolicies,
8+
Labels,
9+
pushLabelsArgument,
10+
Timestamp,
11+
} from '.';
12+
13+
interface AddOptions {
14+
RETENTION?: number;
15+
ENCODING?: TimeSeriesEncoding;
16+
CHUNK_SIZE?: number;
17+
ON_DUPLICATE?: TimeSeriesDuplicatePolicies;
18+
LABELS?: Labels;
19+
}
20+
21+
export const FIRST_KEY_INDEX = 1;
22+
23+
export function transformArguments(key: string, timestamp: Timestamp, value: number, options?: AddOptions): Array<string> {
24+
const args = [
25+
'TS.ADD',
26+
key,
27+
transformTimestampArgument(timestamp),
28+
value.toString()
29+
];
30+
31+
pushRetentionArgument(args, options?.RETENTION);
32+
33+
pushEncodingArgument(args, options?.ENCODING);
34+
35+
pushChunkSizeArgument(args, options?.CHUNK_SIZE);
36+
37+
if (options?.ON_DUPLICATE) {
38+
args.push('ON_DUPLICATE', options.ON_DUPLICATE);
39+
}
40+
41+
pushLabelsArgument(args, options?.LABELS);
42+
43+
return args;
44+
}
45+
46+
export declare function transformReply(): number;
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { strict as assert } from 'assert';
2+
import testUtils, { GLOBAL } from '../test-utils';
3+
import { transformArguments } from './ALTER';
4+
5+
describe('ALTER', () => {
6+
describe('transformArguments', () => {
7+
it('without options', () => {
8+
assert.deepEqual(
9+
transformArguments('key'),
10+
['TS.ALTER', 'key']
11+
);
12+
});
13+
14+
it('with RETENTION', () => {
15+
assert.deepEqual(
16+
transformArguments('key', {
17+
RETENTION: 1
18+
}),
19+
['TS.ALTER', 'key', 'RETENTION', '1']
20+
);
21+
});
22+
23+
it('with LABELS', () => {
24+
assert.deepEqual(
25+
transformArguments('key', {
26+
LABELS: { label: 'value' }
27+
}),
28+
['TS.ALTER', 'key', 'LABELS', 'label', 'value']
29+
);
30+
});
31+
32+
it('with RETENTION, LABELS', () => {
33+
assert.deepEqual(
34+
transformArguments('key', {
35+
RETENTION: 1,
36+
LABELS: { label: 'value' }
37+
}),
38+
['TS.ALTER', 'key', 'RETENTION', '1', 'LABELS', 'label', 'value']
39+
);
40+
});
41+
});
42+
43+
testUtils.testWithClient('client.ts.alter', async client => {
44+
await client.ts.create('key');
45+
46+
assert.equal(
47+
await client.ts.alter('key', { RETENTION: 1 }),
48+
'OK'
49+
);
50+
}, GLOBAL.SERVERS.OPEN);
51+
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { pushRetentionArgument, Labels, pushLabelsArgument } from '.';
2+
3+
export const FIRST_KEY_INDEX = 1;
4+
5+
interface AlterOptions {
6+
RETENTION?: number;
7+
LABELS?: Labels;
8+
}
9+
10+
export function transformArguments(key: string, options?: AlterOptions): Array<string> {
11+
const args = ['TS.ALTER', key];
12+
13+
pushRetentionArgument(args, options?.RETENTION);
14+
15+
pushLabelsArgument(args, options?.LABELS);
16+
17+
return args;
18+
}
19+
20+
export declare function transformReply(): 'OK';
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { strict as assert } from 'assert';
2+
import { TimeSeriesDuplicatePolicies, TimeSeriesEncoding } from '.';
3+
import testUtils, { GLOBAL } from '../test-utils';
4+
import { transformArguments } from './CREATE';
5+
6+
describe('CREATE', () => {
7+
describe('transformArguments', () => {
8+
it('without options', () => {
9+
assert.deepEqual(
10+
transformArguments('key'),
11+
['TS.CREATE', 'key']
12+
);
13+
});
14+
15+
it('with RETENTION', () => {
16+
assert.deepEqual(
17+
transformArguments('key', {
18+
RETENTION: 1
19+
}),
20+
['TS.CREATE', 'key', 'RETENTION', '1']
21+
);
22+
});
23+
24+
it('with ENCODING', () => {
25+
assert.deepEqual(
26+
transformArguments('key', {
27+
ENCODING: TimeSeriesEncoding.UNCOMPRESSED
28+
}),
29+
['TS.CREATE', 'key', 'ENCODING', 'UNCOMPRESSED']
30+
);
31+
});
32+
33+
it('with CHUNK_SIZE', () => {
34+
assert.deepEqual(
35+
transformArguments('key', {
36+
CHUNK_SIZE: 1
37+
}),
38+
['TS.CREATE', 'key', 'CHUNK_SIZE', '1']
39+
);
40+
});
41+
42+
it('with DUPLICATE_POLICY', () => {
43+
assert.deepEqual(
44+
transformArguments('key', {
45+
DUPLICATE_POLICY: TimeSeriesDuplicatePolicies.BLOCK
46+
}),
47+
['TS.CREATE', 'key', 'DUPLICATE_POLICY', 'BLOCK']
48+
);
49+
});
50+
51+
it('with LABELS', () => {
52+
assert.deepEqual(
53+
transformArguments('key', {
54+
LABELS: { label: 'value' }
55+
}),
56+
['TS.CREATE', 'key', 'LABELS', 'label', 'value']
57+
);
58+
});
59+
60+
it('with RETENTION, ENCODING, CHUNK_SIZE, DUPLICATE_POLICY, LABELS', () => {
61+
assert.deepEqual(
62+
transformArguments('key', {
63+
RETENTION: 1,
64+
ENCODING: TimeSeriesEncoding.UNCOMPRESSED,
65+
CHUNK_SIZE: 1,
66+
DUPLICATE_POLICY: TimeSeriesDuplicatePolicies.BLOCK,
67+
LABELS: { label: 'value' }
68+
}),
69+
['TS.CREATE', 'key', 'RETENTION', '1', 'ENCODING', 'UNCOMPRESSED', 'CHUNK_SIZE', '1', 'DUPLICATE_POLICY', 'BLOCK', 'LABELS', 'label', 'value']
70+
);
71+
});
72+
});
73+
74+
testUtils.testWithClient('client.ts.create', async client => {
75+
assert.equal(
76+
await client.ts.create('key'),
77+
'OK'
78+
);
79+
}, GLOBAL.SERVERS.OPEN);
80+
});
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import {
2+
pushRetentionArgument,
3+
TimeSeriesEncoding,
4+
pushEncodingArgument,
5+
pushChunkSizeArgument,
6+
TimeSeriesDuplicatePolicies,
7+
Labels,
8+
pushLabelsArgument
9+
} from '.';
10+
11+
export const FIRST_KEY_INDEX = 1;
12+
13+
interface CreateOptions {
14+
RETENTION?: number;
15+
ENCODING?: TimeSeriesEncoding;
16+
CHUNK_SIZE?: number;
17+
DUPLICATE_POLICY?: TimeSeriesDuplicatePolicies;
18+
LABELS?: Labels;
19+
}
20+
21+
export function transformArguments(key: string, options?: CreateOptions): Array<string> {
22+
const args = ['TS.CREATE', key];
23+
24+
pushRetentionArgument(args, options?.RETENTION);
25+
26+
pushEncodingArgument(args, options?.ENCODING);
27+
28+
pushChunkSizeArgument(args, options?.CHUNK_SIZE);
29+
30+
if (options?.DUPLICATE_POLICY) {
31+
args.push(
32+
'DUPLICATE_POLICY',
33+
options.DUPLICATE_POLICY
34+
);
35+
}
36+
37+
pushLabelsArgument(args, options?.LABELS);
38+
39+
return args;
40+
}
41+
42+
export declare function transformReply(): 'OK';
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { strict as assert } from 'assert';
2+
import { TimeSeriesAggregationType } from '.';
3+
import testUtils, { GLOBAL } from '../test-utils';
4+
import { transformArguments } from './CREATERULE';
5+
6+
describe('CREATERULE', () => {
7+
it('transformArguments', () => {
8+
assert.deepEqual(
9+
transformArguments('source', 'destination', TimeSeriesAggregationType.AVARAGE, 1),
10+
['TS.CREATERULE', 'source', 'destination', 'avg', 1]
11+
);
12+
});
13+
14+
testUtils.testWithClient('client.ts.createRule', async client => {
15+
await Promise.all([
16+
client.ts.create('source'),
17+
client.ts.create('destination')
18+
]);
19+
20+
assert.equal(
21+
await client.ts.createRule('source', 'destination', TimeSeriesAggregationType.AVARAGE, 1),
22+
'OK'
23+
);
24+
}, GLOBAL.SERVERS.OPEN);
25+
});

0 commit comments

Comments
 (0)