Skip to content

Commit 7110f23

Browse files
AvitalFineRedisleibale
andauthoredDec 12, 2021
Support RedisTimeSeries (#1757)
* Implement missing commands and add test * Update DECRBY.spec.ts * Small changes * clean code * Update MGET_WITHLABELS.ts Use map in transformReply Co-authored-by: leibale <leibale1998@gmail.com>
1 parent bb75b06 commit 7110f23

30 files changed

+1309
-46
lines changed
 

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe('ALTER', () => {
4141
});
4242

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

4646
assert.equal(
4747
await client.ts.alter('key', { RETENTION: 1 }),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { strict as assert } from 'assert';
2+
import testUtils, { GLOBAL } from '../test-utils';
3+
import { transformArguments } from './DECRBY';
4+
5+
describe('DECRBY', () => {
6+
describe('transformArguments', () => {
7+
it('without options', () => {
8+
assert.deepEqual(
9+
transformArguments('key', 1),
10+
['TS.DECRBY', 'key', '1']
11+
);
12+
});
13+
14+
it('with TIMESTAMP', () => {
15+
assert.deepEqual(
16+
transformArguments('key', 1, {
17+
TIMESTAMP: '*'
18+
}),
19+
['TS.DECRBY', 'key', '1', 'TIMESTAMP', '*']
20+
);
21+
});
22+
23+
it('with RETENTION', () => {
24+
assert.deepEqual(
25+
transformArguments('key', 1, {
26+
RETENTION: 1
27+
}),
28+
['TS.DECRBY', 'key', '1', 'RETENTION', '1']
29+
);
30+
});
31+
32+
it('with UNCOMPRESSED', () => {
33+
assert.deepEqual(
34+
transformArguments('key', 1, {
35+
UNCOMPRESSED: true
36+
}),
37+
['TS.DECRBY', 'key', '1', 'UNCOMPRESSED']
38+
);
39+
});
40+
41+
it('with CHUNK_SIZE', () => {
42+
assert.deepEqual(
43+
transformArguments('key', 1, {
44+
CHUNK_SIZE: 100
45+
}),
46+
['TS.DECRBY', 'key', '1', 'CHUNK_SIZE', '100']
47+
);
48+
});
49+
50+
it('with LABELS', () => {
51+
assert.deepEqual(
52+
transformArguments('key', 1, {
53+
LABELS: { label: 'value' }
54+
}),
55+
['TS.DECRBY', 'key', '1', 'LABELS', 'label', 'value']
56+
);
57+
});
58+
59+
it('with TIMESTAMP, RETENTION, UNCOMPRESSED, CHUNK_SIZE and LABELS', () => {
60+
assert.deepEqual(
61+
transformArguments('key', 1, {
62+
TIMESTAMP: '*',
63+
RETENTION: 1,
64+
UNCOMPRESSED: true,
65+
CHUNK_SIZE: 2,
66+
LABELS: { label: 'value' }
67+
}),
68+
['TS.DECRBY', 'key', '1', 'TIMESTAMP', '*', 'RETENTION', '1', 'UNCOMPRESSED', 'CHUNK_SIZE', '2', 'LABELS', 'label', 'value']
69+
);
70+
});
71+
});
72+
73+
testUtils.testWithClient('client.ts.decrBy', async client => {
74+
assert.equal(
75+
await client.ts.decrBy('key', 1, {
76+
TIMESTAMP: 0
77+
}),
78+
0
79+
);
80+
}, GLOBAL.SERVERS.OPEN);
81+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { strict as assert } from 'assert';
2+
import testUtils, { GLOBAL } from '../test-utils';
3+
import { transformArguments } from './DEL';
4+
5+
describe('DEL', () => {
6+
it('transformArguments', () => {
7+
assert.deepEqual(
8+
transformArguments('key', '-', '+'),
9+
['TS.DEL', 'key', '-', '+']
10+
);
11+
});
12+
13+
testUtils.testWithClient('client.ts.del', async client => {
14+
await client.ts.create('key');
15+
16+
assert.equal(
17+
await client.ts.del('key', '-', '+'),
18+
0
19+
);
20+
}, GLOBAL.SERVERS.OPEN);
21+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { strict as assert } from 'assert';
2+
import { TimeSeriesAggregationType } from '.';
3+
import testUtils, { GLOBAL } from '../test-utils';
4+
import { transformArguments } from './DELETERULE';
5+
6+
describe('DELETERULE', () => {
7+
it('transformArguments', () => {
8+
assert.deepEqual(
9+
transformArguments('source', 'destination'),
10+
['TS.DELETERULE', 'source', 'destination']
11+
);
12+
});
13+
14+
testUtils.testWithClient('client.ts.deleteRule', async client => {
15+
await Promise.all([
16+
client.ts.create('source'),
17+
client.ts.create('destination'),
18+
client.ts.createRule('source', 'destination', TimeSeriesAggregationType.AVARAGE, 1)
19+
]);
20+
21+
assert.equal(
22+
await client.ts.deleteRule('source', 'destination'),
23+
'OK'
24+
);
25+
}, GLOBAL.SERVERS.OPEN);
26+
});

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
export function transformArguments(sourceKey: string,destinationKey: string,): Array<string> {
1+
export const FIRST_KEY_INDEX = 1;
2+
3+
export function transformArguments(sourceKey: string, destinationKey: string): Array<string> {
24
return [
35
'TS.DELETERULE',
46
sourceKey,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { strict as assert } from 'assert';
2+
import testUtils, { GLOBAL } from '../test-utils';
3+
import { transformArguments } from './GET';
4+
5+
describe('GET', () => {
6+
it('transformArguments', () => {
7+
assert.deepEqual(
8+
transformArguments('key'),
9+
['TS.GET', 'key']
10+
);
11+
});
12+
13+
describe('client.ts.get', () => {
14+
testUtils.testWithClient('null', async client => {
15+
await client.ts.create('key');
16+
17+
assert.equal(
18+
await client.ts.get('key'),
19+
null
20+
);
21+
}, GLOBAL.SERVERS.OPEN);
22+
23+
testUtils.testWithClient('with samples', async client => {
24+
await client.ts.add('key', 0, 1);
25+
26+
assert.deepEqual(
27+
await client.ts.get('key'),
28+
{
29+
timestamp: 0,
30+
value: 1
31+
}
32+
);
33+
}, GLOBAL.SERVERS.OPEN);
34+
});
35+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import { strict as assert } from 'assert';
2+
import testUtils, { GLOBAL } from '../test-utils';
3+
import { transformArguments } from './INCRBY';
4+
5+
describe('INCRBY', () => {
6+
describe('transformArguments', () => {
7+
it('without options', () => {
8+
assert.deepEqual(
9+
transformArguments('key', 1),
10+
['TS.INCRBY', 'key', '1']
11+
);
12+
});
13+
14+
it('with TIMESTAMP', () => {
15+
assert.deepEqual(
16+
transformArguments('key', 1, {
17+
TIMESTAMP: '*'
18+
}),
19+
['TS.INCRBY', 'key', '1', 'TIMESTAMP', '*']
20+
);
21+
});
22+
23+
it('with RETENTION', () => {
24+
assert.deepEqual(
25+
transformArguments('key', 1, {
26+
RETENTION: 1
27+
}),
28+
['TS.INCRBY', 'key', '1', 'RETENTION', '1']
29+
);
30+
});
31+
32+
it('with UNCOMPRESSED', () => {
33+
assert.deepEqual(
34+
transformArguments('key', 1, {
35+
UNCOMPRESSED: true
36+
}),
37+
['TS.INCRBY', 'key', '1', 'UNCOMPRESSED']
38+
);
39+
});
40+
41+
it('without UNCOMPRESSED', () => {
42+
assert.deepEqual(
43+
transformArguments('key', 1, {
44+
UNCOMPRESSED: false
45+
}),
46+
['TS.INCRBY', 'key', '1']
47+
);
48+
});
49+
50+
it('with CHUNK_SIZE', () => {
51+
assert.deepEqual(
52+
transformArguments('key', 1, {
53+
CHUNK_SIZE: 1
54+
}),
55+
['TS.INCRBY', 'key', '1', 'CHUNK_SIZE', '1']
56+
);
57+
});
58+
59+
it('with LABELS', () => {
60+
assert.deepEqual(
61+
transformArguments('key', 1, {
62+
LABELS: { label: 'value' }
63+
}),
64+
['TS.INCRBY', 'key', '1', 'LABELS', 'label', 'value']
65+
);
66+
});
67+
68+
it('with TIMESTAMP, RETENTION, UNCOMPRESSED, CHUNK_SIZE and LABELS', () => {
69+
assert.deepEqual(
70+
transformArguments('key', 1, {
71+
TIMESTAMP: '*',
72+
RETENTION: 1,
73+
UNCOMPRESSED: true,
74+
CHUNK_SIZE: 1,
75+
LABELS: { label: 'value' }
76+
}),
77+
['TS.INCRBY', 'key', '1', 'TIMESTAMP', '*', 'RETENTION', '1', 'UNCOMPRESSED',
78+
'CHUNK_SIZE', '1', 'LABELS', 'label', 'value']
79+
);
80+
});
81+
});
82+
83+
testUtils.testWithClient('client.ts.incrBy', async client => {
84+
assert.equal(
85+
await client.ts.incrBy('key', 1, {
86+
TIMESTAMP: 0
87+
}),
88+
0
89+
);
90+
}, GLOBAL.SERVERS.OPEN);
91+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { strict as assert } from 'assert';
2+
import { TimeSeriesAggregationType, TimeSeriesDuplicatePolicies } from '.';
3+
import testUtils, { GLOBAL } from '../test-utils';
4+
import { transformArguments } from './INFO';
5+
6+
describe('INFO', () => {
7+
it('transformArguments', () => {
8+
assert.deepEqual(
9+
transformArguments('key'),
10+
['TS.INFO', 'key']
11+
);
12+
});
13+
14+
testUtils.testWithClient('client.ts.info', async client => {
15+
await Promise.all([
16+
client.ts.create('key', {
17+
LABELS: { id: "2" },
18+
DUPLICATE_POLICY: TimeSeriesDuplicatePolicies.LAST
19+
}),
20+
client.ts.create('key2'),
21+
client.ts.createRule('key', 'key2', TimeSeriesAggregationType.COUNT, 5),
22+
client.ts.add('key', 1, 10)
23+
]);
24+
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+
);
49+
}, GLOBAL.SERVERS.OPEN);
50+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { strict as assert } from 'assert';
2+
import { TimeSeriesAggregationType, TimeSeriesDuplicatePolicies } from '.';
3+
import testUtils, { GLOBAL } from '../test-utils';
4+
import { transformArguments } from './INFO_DEBUG';
5+
6+
describe('INFO_DEBUG', () => {
7+
it('transformArguments', () => {
8+
assert.deepEqual(
9+
transformArguments('key'),
10+
['TS.INFO', 'key', 'DEBUG']
11+
);
12+
});
13+
14+
testUtils.testWithClient('client.ts.get', async client => {
15+
await Promise.all([
16+
client.ts.create('key', {
17+
LABELS: { id: "2" },
18+
DUPLICATE_POLICY: TimeSeriesDuplicatePolicies.LAST
19+
}),
20+
client.ts.create('key2'),
21+
client.ts.createRule('key', 'key2', TimeSeriesAggregationType.COUNT, 5),
22+
client.ts.add('key', 1, 10)
23+
]);
24+
25+
assert.deepEqual(
26+
await client.ts.infoDebug('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+
sourceKey: null,
42+
rules: [{
43+
aggregationType: 'COUNT',
44+
key: 'key2',
45+
timeBucket: 5
46+
}],
47+
chunks: [{
48+
startTimestamp: 1,
49+
endTimestamp: 1,
50+
samples: 1,
51+
size: 4096,
52+
bytesPerSample: '4096'
53+
}]
54+
}
55+
);
56+
}, GLOBAL.SERVERS.OPEN);
57+
});

0 commit comments

Comments
 (0)
Please sign in to comment.