Skip to content

Support RedisTimeSeries #1757

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Dec 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/time-series/lib/commands/ALTER.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('ALTER', () => {
});

testUtils.testWithClient('client.ts.alter', async client => {
await client.ts.create('key');
await client.ts.create('key');

assert.equal(
await client.ts.alter('key', { RETENTION: 1 }),
Expand Down
81 changes: 81 additions & 0 deletions packages/time-series/lib/commands/DECRBY.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './DECRBY';

describe('DECRBY', () => {
describe('transformArguments', () => {
it('without options', () => {
assert.deepEqual(
transformArguments('key', 1),
['TS.DECRBY', 'key', '1']
);
});

it('with TIMESTAMP', () => {
assert.deepEqual(
transformArguments('key', 1, {
TIMESTAMP: '*'
}),
['TS.DECRBY', 'key', '1', 'TIMESTAMP', '*']
);
});

it('with RETENTION', () => {
assert.deepEqual(
transformArguments('key', 1, {
RETENTION: 1
}),
['TS.DECRBY', 'key', '1', 'RETENTION', '1']
);
});

it('with UNCOMPRESSED', () => {
assert.deepEqual(
transformArguments('key', 1, {
UNCOMPRESSED: true
}),
['TS.DECRBY', 'key', '1', 'UNCOMPRESSED']
);
});

it('with CHUNK_SIZE', () => {
assert.deepEqual(
transformArguments('key', 1, {
CHUNK_SIZE: 100
}),
['TS.DECRBY', 'key', '1', 'CHUNK_SIZE', '100']
);
});

it('with LABELS', () => {
assert.deepEqual(
transformArguments('key', 1, {
LABELS: { label: 'value' }
}),
['TS.DECRBY', 'key', '1', 'LABELS', 'label', 'value']
);
});

it('with TIMESTAMP, RETENTION, UNCOMPRESSED, CHUNK_SIZE and LABELS', () => {
assert.deepEqual(
transformArguments('key', 1, {
TIMESTAMP: '*',
RETENTION: 1,
UNCOMPRESSED: true,
CHUNK_SIZE: 2,
LABELS: { label: 'value' }
}),
['TS.DECRBY', 'key', '1', 'TIMESTAMP', '*', 'RETENTION', '1', 'UNCOMPRESSED', 'CHUNK_SIZE', '2', 'LABELS', 'label', 'value']
);
});
});

testUtils.testWithClient('client.ts.decrBy', async client => {
assert.equal(
await client.ts.decrBy('key', 1, {
TIMESTAMP: 0
}),
0
);
}, GLOBAL.SERVERS.OPEN);
});
21 changes: 21 additions & 0 deletions packages/time-series/lib/commands/DEL.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './DEL';

describe('DEL', () => {
it('transformArguments', () => {
assert.deepEqual(
transformArguments('key', '-', '+'),
['TS.DEL', 'key', '-', '+']
);
});

testUtils.testWithClient('client.ts.del', async client => {
await client.ts.create('key');

assert.equal(
await client.ts.del('key', '-', '+'),
0
);
}, GLOBAL.SERVERS.OPEN);
});
26 changes: 26 additions & 0 deletions packages/time-series/lib/commands/DELETERULE.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { strict as assert } from 'assert';
import { TimeSeriesAggregationType } from '.';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './DELETERULE';

describe('DELETERULE', () => {
it('transformArguments', () => {
assert.deepEqual(
transformArguments('source', 'destination'),
['TS.DELETERULE', 'source', 'destination']
);
});

testUtils.testWithClient('client.ts.deleteRule', async client => {
await Promise.all([
client.ts.create('source'),
client.ts.create('destination'),
client.ts.createRule('source', 'destination', TimeSeriesAggregationType.AVARAGE, 1)
]);

assert.equal(
await client.ts.deleteRule('source', 'destination'),
'OK'
);
}, GLOBAL.SERVERS.OPEN);
});
4 changes: 3 additions & 1 deletion packages/time-series/lib/commands/DELETERULE.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export function transformArguments(sourceKey: string,destinationKey: string,): Array<string> {
export const FIRST_KEY_INDEX = 1;

export function transformArguments(sourceKey: string, destinationKey: string): Array<string> {
return [
'TS.DELETERULE',
sourceKey,
Expand Down
35 changes: 35 additions & 0 deletions packages/time-series/lib/commands/GET.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './GET';

describe('GET', () => {
it('transformArguments', () => {
assert.deepEqual(
transformArguments('key'),
['TS.GET', 'key']
);
});

describe('client.ts.get', () => {
testUtils.testWithClient('null', async client => {
await client.ts.create('key');

assert.equal(
await client.ts.get('key'),
null
);
}, GLOBAL.SERVERS.OPEN);

testUtils.testWithClient('with samples', async client => {
await client.ts.add('key', 0, 1);

assert.deepEqual(
await client.ts.get('key'),
{
timestamp: 0,
value: 1
}
);
}, GLOBAL.SERVERS.OPEN);
});
});
91 changes: 91 additions & 0 deletions packages/time-series/lib/commands/INCRBY.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './INCRBY';

describe('INCRBY', () => {
describe('transformArguments', () => {
it('without options', () => {
assert.deepEqual(
transformArguments('key', 1),
['TS.INCRBY', 'key', '1']
);
});

it('with TIMESTAMP', () => {
assert.deepEqual(
transformArguments('key', 1, {
TIMESTAMP: '*'
}),
['TS.INCRBY', 'key', '1', 'TIMESTAMP', '*']
);
});

it('with RETENTION', () => {
assert.deepEqual(
transformArguments('key', 1, {
RETENTION: 1
}),
['TS.INCRBY', 'key', '1', 'RETENTION', '1']
);
});

it('with UNCOMPRESSED', () => {
assert.deepEqual(
transformArguments('key', 1, {
UNCOMPRESSED: true
}),
['TS.INCRBY', 'key', '1', 'UNCOMPRESSED']
);
});

it('without UNCOMPRESSED', () => {
assert.deepEqual(
transformArguments('key', 1, {
UNCOMPRESSED: false
}),
['TS.INCRBY', 'key', '1']
);
});

it('with CHUNK_SIZE', () => {
assert.deepEqual(
transformArguments('key', 1, {
CHUNK_SIZE: 1
}),
['TS.INCRBY', 'key', '1', 'CHUNK_SIZE', '1']
);
});

it('with LABELS', () => {
assert.deepEqual(
transformArguments('key', 1, {
LABELS: { label: 'value' }
}),
['TS.INCRBY', 'key', '1', 'LABELS', 'label', 'value']
);
});

it('with TIMESTAMP, RETENTION, UNCOMPRESSED, CHUNK_SIZE and LABELS', () => {
assert.deepEqual(
transformArguments('key', 1, {
TIMESTAMP: '*',
RETENTION: 1,
UNCOMPRESSED: true,
CHUNK_SIZE: 1,
LABELS: { label: 'value' }
}),
['TS.INCRBY', 'key', '1', 'TIMESTAMP', '*', 'RETENTION', '1', 'UNCOMPRESSED',
'CHUNK_SIZE', '1', 'LABELS', 'label', 'value']
);
});
});

testUtils.testWithClient('client.ts.incrBy', async client => {
assert.equal(
await client.ts.incrBy('key', 1, {
TIMESTAMP: 0
}),
0
);
}, GLOBAL.SERVERS.OPEN);
});
50 changes: 50 additions & 0 deletions packages/time-series/lib/commands/INFO.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { strict as assert } from 'assert';
import { TimeSeriesAggregationType, TimeSeriesDuplicatePolicies } from '.';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './INFO';

describe('INFO', () => {
it('transformArguments', () => {
assert.deepEqual(
transformArguments('key'),
['TS.INFO', 'key']
);
});

testUtils.testWithClient('client.ts.info', async client => {
await Promise.all([
client.ts.create('key', {
LABELS: { id: "2" },
DUPLICATE_POLICY: TimeSeriesDuplicatePolicies.LAST
}),
client.ts.create('key2'),
client.ts.createRule('key', 'key2', TimeSeriesAggregationType.COUNT, 5),
client.ts.add('key', 1, 10)
]);

assert.deepEqual(
await client.ts.info('key'),
{
totalSamples: 1,
memoryUsage: 4261,
firstTimestamp: 1,
lastTimestamp: 1,
retentionTime: 0,
chunkCount: 1,
chunkSize: 4096,
chunkType: 'compressed',
duplicatePolicy: 'last',
labels: [{
name: 'id',
value: '2'
}],
rules: [{
aggregationType: 'COUNT',
key: 'key2',
timeBucket: 5
}],
sourceKey: null
}
);
}, GLOBAL.SERVERS.OPEN);
});
57 changes: 57 additions & 0 deletions packages/time-series/lib/commands/INFO_DEBUG.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { strict as assert } from 'assert';
import { TimeSeriesAggregationType, TimeSeriesDuplicatePolicies } from '.';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './INFO_DEBUG';

describe('INFO_DEBUG', () => {
it('transformArguments', () => {
assert.deepEqual(
transformArguments('key'),
['TS.INFO', 'key', 'DEBUG']
);
});

testUtils.testWithClient('client.ts.get', async client => {
await Promise.all([
client.ts.create('key', {
LABELS: { id: "2" },
DUPLICATE_POLICY: TimeSeriesDuplicatePolicies.LAST
}),
client.ts.create('key2'),
client.ts.createRule('key', 'key2', TimeSeriesAggregationType.COUNT, 5),
client.ts.add('key', 1, 10)
]);

assert.deepEqual(
await client.ts.infoDebug('key'),
{
totalSamples: 1,
memoryUsage: 4261,
firstTimestamp: 1,
lastTimestamp: 1,
retentionTime: 0,
chunkCount: 1,
chunkSize: 4096,
chunkType: 'compressed',
duplicatePolicy: 'last',
labels: [{
name: 'id',
value: '2'
}],
sourceKey: null,
rules: [{
aggregationType: 'COUNT',
key: 'key2',
timeBucket: 5
}],
chunks: [{
startTimestamp: 1,
endTimestamp: 1,
samples: 1,
size: 4096,
bytesPerSample: '4096'
}]
}
);
}, GLOBAL.SERVERS.OPEN);
});
Loading