1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00

time-series

This commit is contained in:
Leibale
2023-07-11 13:11:13 -04:00
parent c515bc9571
commit 54c3a66c72
32 changed files with 879 additions and 933 deletions

View File

@@ -1,7 +1,7 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import ADD from './ADD';
import { TimeSeriesDuplicatePolicies, TimeSeriesEncoding } from '.';
import { TIME_SERIES_ENCODING, TIME_SERIES_DUPLICATE_POLICIES } from '.';
describe('TS.ADD', () => {
describe('transformArguments', () => {
@@ -24,7 +24,7 @@ describe('TS.ADD', () => {
it('with ENCODING', () => {
assert.deepEqual(
ADD.transformArguments('key', '*', 1, {
ENCODING: TimeSeriesEncoding.UNCOMPRESSED
ENCODING: TIME_SERIES_ENCODING.UNCOMPRESSED
}),
['TS.ADD', 'key', '*', '1', 'ENCODING', 'UNCOMPRESSED']
);
@@ -42,7 +42,7 @@ describe('TS.ADD', () => {
it('with ON_DUPLICATE', () => {
assert.deepEqual(
ADD.transformArguments('key', '*', 1, {
ON_DUPLICATE: TimeSeriesDuplicatePolicies.BLOCK
ON_DUPLICATE: TIME_SERIES_DUPLICATE_POLICIES.BLOCK
}),
['TS.ADD', 'key', '*', '1', 'ON_DUPLICATE', 'BLOCK']
);
@@ -61,9 +61,9 @@ describe('TS.ADD', () => {
assert.deepEqual(
ADD.transformArguments('key', '*', 1, {
RETENTION: 1,
ENCODING: TimeSeriesEncoding.UNCOMPRESSED,
ENCODING: TIME_SERIES_ENCODING.UNCOMPRESSED,
CHUNK_SIZE: 1,
ON_DUPLICATE: TimeSeriesDuplicatePolicies.BLOCK,
ON_DUPLICATE: TIME_SERIES_DUPLICATE_POLICIES.BLOCK,
LABELS: { label: 'value' }
}),
['TS.ADD', 'key', '*', '1', 'RETENTION', '1', 'ENCODING', 'UNCOMPRESSED', 'CHUNK_SIZE', '1', 'ON_DUPLICATE', 'BLOCK', 'LABELS', 'label', 'value']

View File

@@ -1,7 +1,7 @@
import { strict as assert } from 'assert';
import { TimeSeriesDuplicatePolicies } from '.';
import testUtils, { GLOBAL } from '../test-utils';
import ALTER from './ALTER';
import { TIME_SERIES_DUPLICATE_POLICIES } from '.';
describe('TS.ALTER', () => {
describe('transformArguments', () => {
@@ -33,7 +33,7 @@ describe('TS.ALTER', () => {
it('with DUPLICATE_POLICY', () => {
assert.deepEqual(
ALTER.transformArguments('key', {
DUPLICATE_POLICY: TimeSeriesDuplicatePolicies.BLOCK
DUPLICATE_POLICY: TIME_SERIES_DUPLICATE_POLICIES.BLOCK
}),
['TS.ALTER', 'key', 'DUPLICATE_POLICY', 'BLOCK']
);
@@ -53,7 +53,7 @@ describe('TS.ALTER', () => {
ALTER.transformArguments('key', {
RETENTION: 1,
CHUNK_SIZE: 1,
DUPLICATE_POLICY: TimeSeriesDuplicatePolicies.BLOCK,
DUPLICATE_POLICY: TIME_SERIES_DUPLICATE_POLICIES.BLOCK,
LABELS: { label: 'value' }
}),
['TS.ALTER', 'key', 'RETENTION', '1', 'CHUNK_SIZE', '1', 'DUPLICATE_POLICY', 'BLOCK', 'LABELS', 'label', 'value']
@@ -62,11 +62,11 @@ describe('TS.ALTER', () => {
});
testUtils.testWithClient('client.ts.alter', async client => {
await client.ts.create('key');
const [, reply] = await Promise.all([
client.ts.create('key'),
client.ts.alter('key', { RETENTION: 1 })
]);
assert.equal(
await client.ts.alter('key', { RETENTION: 1 }),
'OK'
);
assert.equal(reply, 'OK');
}, GLOBAL.SERVERS.OPEN);
});

View File

@@ -1,12 +1,8 @@
import { pushRetentionArgument, Labels, pushLabelsArgument, TimeSeriesDuplicatePolicies, pushChunkSizeArgument, pushDuplicatePolicy } from '.';
import { RedisArgument, SimpleStringReply, Command } from '@redis/client/dist/lib/RESP/types';
import { TsCreateOptions } from './CREATE';
import { pushRetentionArgument, pushChunkSizeArgument, pushDuplicatePolicy, pushLabelsArgument } from '.';
export interface TsAlterOptions {
RETENTION?: number;
CHUNK_SIZE?: number;
DUPLICATE_POLICY?: TimeSeriesDuplicatePolicies;
LABELS?: Labels;
}
export type TsAlterOptions = Pick<TsCreateOptions, 'RETENTION' | 'CHUNK_SIZE' | 'DUPLICATE_POLICY' | 'LABELS'>;
export default {
FIRST_KEY_INDEX: 1,

View File

@@ -1,9 +1,9 @@
import { strict as assert } from 'assert';
import { TimeSeriesDuplicatePolicies, TimeSeriesEncoding } from '.';
import testUtils, { GLOBAL } from '../test-utils';
import CREATE from './CREATE';
import { TIME_SERIES_ENCODING, TIME_SERIES_DUPLICATE_POLICIES } from '.';
describe('CREATE', () => {
describe('TS.CREATE', () => {
describe('transformArguments', () => {
it('without options', () => {
assert.deepEqual(
@@ -24,7 +24,7 @@ describe('CREATE', () => {
it('with ENCODING', () => {
assert.deepEqual(
CREATE.transformArguments('key', {
ENCODING: TimeSeriesEncoding.UNCOMPRESSED
ENCODING: TIME_SERIES_ENCODING.UNCOMPRESSED
}),
['TS.CREATE', 'key', 'ENCODING', 'UNCOMPRESSED']
);
@@ -42,7 +42,7 @@ describe('CREATE', () => {
it('with DUPLICATE_POLICY', () => {
assert.deepEqual(
CREATE.transformArguments('key', {
DUPLICATE_POLICY: TimeSeriesDuplicatePolicies.BLOCK
DUPLICATE_POLICY: TIME_SERIES_DUPLICATE_POLICIES.BLOCK
}),
['TS.CREATE', 'key', 'DUPLICATE_POLICY', 'BLOCK']
);
@@ -61,9 +61,9 @@ describe('CREATE', () => {
assert.deepEqual(
CREATE.transformArguments('key', {
RETENTION: 1,
ENCODING: TimeSeriesEncoding.UNCOMPRESSED,
ENCODING: TIME_SERIES_ENCODING.UNCOMPRESSED,
CHUNK_SIZE: 1,
DUPLICATE_POLICY: TimeSeriesDuplicatePolicies.BLOCK,
DUPLICATE_POLICY: TIME_SERIES_DUPLICATE_POLICIES.BLOCK,
LABELS: { label: 'value' }
}),
['TS.CREATE', 'key', 'RETENTION', '1', 'ENCODING', 'UNCOMPRESSED', 'CHUNK_SIZE', '1', 'DUPLICATE_POLICY', 'BLOCK', 'LABELS', 'label', 'value']

View File

@@ -1,14 +1,14 @@
import { RedisArgument, SimpleStringReply, Command } from '@redis/client/dist/lib/RESP/types';
import {
pushRetentionArgument,
TimeSeriesEncoding,
pushEncodingArgument,
pushChunkSizeArgument,
TimeSeriesDuplicatePolicies,
pushDuplicatePolicy,
Labels,
pushLabelsArgument,
pushDuplicatePolicy
pushLabelsArgument
} from '.';
import { RedisArgument, SimpleStringReply, Command } from '@redis/client/dist/lib/RESP/types';
export interface TsCreateOptions {
RETENTION?: number;

View File

@@ -1,34 +1,31 @@
import { strict as assert } from 'assert';
import { TimeSeriesAggregationType } from '.';
import testUtils, { GLOBAL } from '../test-utils';
import CREATERULE from './CREATERULE';
import CREATERULE, { TIME_SERIES_AGGREGATION_TYPE } from './CREATERULE';
describe('CREATERULE', () => {
describe('TS.CREATERULE', () => {
describe('transformArguments', () => {
it('without options', () => {
assert.deepEqual(
CREATERULE.transformArguments('source', 'destination', TimeSeriesAggregationType.AVERAGE, 1),
CREATERULE.transformArguments('source', 'destination', TIME_SERIES_AGGREGATION_TYPE.AVG, 1),
['TS.CREATERULE', 'source', 'destination', 'AGGREGATION', 'AVG', '1']
);
});
it('with alignTimestamp', () => {
assert.deepEqual(
CREATERULE.transformArguments('source', 'destination', TimeSeriesAggregationType.AVERAGE, 1, 1),
CREATERULE.transformArguments('source', 'destination', TIME_SERIES_AGGREGATION_TYPE.AVG, 1, 1),
['TS.CREATERULE', 'source', 'destination', 'AGGREGATION', 'AVG', '1', '1']
);
});
});
testUtils.testWithClient('client.ts.createRule', async client => {
await Promise.all([
const [, , reply] = await Promise.all([
client.ts.create('source'),
client.ts.create('destination')
client.ts.create('destination'),
client.ts.createRule('source', 'destination', TIME_SERIES_AGGREGATION_TYPE.AVG, 1)
]);
assert.equal(
await client.ts.createRule('source', 'destination', TimeSeriesAggregationType.AVERAGE, 1),
'OK'
);
assert.equal(reply, 'OK');
}, GLOBAL.SERVERS.OPEN);
});

View File

@@ -1,6 +1,23 @@
import { TimeSeriesAggregationType } from '.';
import { RedisArgument, SimpleStringReply, Command } from '@redis/client/dist/lib/RESP/types';
export const TIME_SERIES_AGGREGATION_TYPE = {
AVG: 'AVG',
FIRST: 'FIRST',
LAST: 'LAST',
MIN: 'MIN',
MAX: 'MAX',
SUM: 'SUM',
RANGE: 'RANGE',
COUNT: 'COUNT',
STD_P: 'STD.P',
STD_S: 'STD.S',
VAR_P: 'VAR.P',
VAR_S: 'VAR.S',
TWA: 'TWA'
} as const;
export type TimeSeriesAggregationType = typeof TIME_SERIES_AGGREGATION_TYPE[keyof typeof TIME_SERIES_AGGREGATION_TYPE];
export default {
FIRST_KEY_INDEX: 1,
IS_READ_ONLY: false,
@@ -20,7 +37,7 @@ export default {
bucketDuration.toString()
];
if (alignTimestamp) {
if (alignTimestamp !== undefined) {
args.push(alignTimestamp.toString());
}

View File

@@ -2,7 +2,7 @@ import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import DECRBY from './DECRBY';
describe('DECRBY', () => {
describe('TS.DECRBY', () => {
describe('transformArguments', () => {
it('without options', () => {
assert.deepEqual(
@@ -72,10 +72,8 @@ describe('DECRBY', () => {
testUtils.testWithClient('client.ts.decrBy', async client => {
assert.equal(
await client.ts.decrBy('key', 1, {
TIMESTAMP: 0
}),
0
typeof await client.ts.decrBy('key', 1),
'number'
);
}, GLOBAL.SERVERS.OPEN);
});

View File

@@ -1,11 +1,9 @@
import { IncrDecrOptions, transformIncrDecrArguments } from '.';
import { RedisArgument, Command, NumberReply } from '@redis/client/dist/lib/RESP/types';
import { Command } from '@redis/client/dist/lib/RESP/types';
import INCRBY, { transformIncrByArguments } from './INCRBY';
export default {
FIRST_KEY_INDEX: 1,
IS_READ_ONLY: false,
transformArguments(key: RedisArgument, value: number, options?: IncrDecrOptions) {
return transformIncrDecrArguments('TS.DECRBY', key, value, options);
},
transformReply: undefined as unknown as () => NumberReply
FIRST_KEY_INDEX: INCRBY.FIRST_KEY_INDEX,
IS_READ_ONLY: INCRBY.IS_READ_ONLY,
transformArguments: transformIncrByArguments.bind(undefined, 'TS.DECRBY'),
transformReply: INCRBY.transformReply
} as const satisfies Command;

View File

@@ -2,7 +2,7 @@ import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import DEL from './DEL';
describe('DEL', () => {
describe('TS.DEL', () => {
it('transformArguments', () => {
assert.deepEqual(
DEL.transformArguments('key', '-', '+'),
@@ -11,11 +11,11 @@ describe('DEL', () => {
});
testUtils.testWithClient('client.ts.del', async client => {
await client.ts.create('key');
const [, reply] = await Promise.all([
client.ts.create('key'),
client.ts.del('key', '-', '+')
]);
assert.equal(
await client.ts.del('key', '-', '+'),
0
);
assert.equal(reply, 0);
}, GLOBAL.SERVERS.OPEN);
});

View File

@@ -1,9 +1,9 @@
import { strict as assert } from 'assert';
import { TimeSeriesAggregationType } from '.';
import testUtils, { GLOBAL } from '../test-utils';
import DELETERULE from './DELETERULE';
import { TIME_SERIES_AGGREGATION_TYPE } from './CREATERULE';
describe('DELETERULE', () => {
describe('TS.DELETERULE', () => {
it('transformArguments', () => {
assert.deepEqual(
DELETERULE.transformArguments('source', 'destination'),
@@ -12,15 +12,13 @@ describe('DELETERULE', () => {
});
testUtils.testWithClient('client.ts.deleteRule', async client => {
await Promise.all([
const [, , , reply] = await Promise.all([
client.ts.create('source'),
client.ts.create('destination'),
client.ts.createRule('source', 'destination', TimeSeriesAggregationType.AVERAGE, 1)
client.ts.createRule('source', 'destination', TIME_SERIES_AGGREGATION_TYPE.AVG, 1),
client.ts.deleteRule('source', 'destination')
]);
assert.equal(
await client.ts.deleteRule('source', 'destination'),
'OK'
);
assert.equal(reply, 'OK');
}, GLOBAL.SERVERS.OPEN);
});

View File

@@ -2,7 +2,7 @@ import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import GET from './GET';
describe('GET', () => {
describe('TS.GET', () => {
describe('transformArguments', () => {
it('without options', () => {
assert.deepEqual(
@@ -23,24 +23,24 @@ describe('GET', () => {
describe('client.ts.get', () => {
testUtils.testWithClient('null', async client => {
await client.ts.create('key');
const [, reply] = await Promise.all([
client.ts.create('key'),
client.ts.get('key')
]);
assert.equal(
await client.ts.get('key'),
null
);
assert.equal(reply, null);
}, GLOBAL.SERVERS.OPEN);
testUtils.testWithClient('with samples', async client => {
await client.ts.add('key', 0, 1);
testUtils.testWithClient('with sample', async client => {
const [, reply] = await Promise.all([
client.ts.add('key', 0, 1),
client.ts.get('key')
]);
assert.deepEqual(
await client.ts.get('key'),
{
timestamp: 0,
value: 1
}
);
assert.deepEqual(reply, {
timestamp: 0,
value: 1
});
}, GLOBAL.SERVERS.OPEN);
});
});

View File

@@ -1,5 +1,4 @@
import { RedisArgument, TuplesReply, NumberReply, DoubleReply, Resp2Reply, Command } from '@redis/client/dist/lib/RESP/types';
import { pushLatestArgument } from '.';
export interface TsGetOptions {
LATEST?: boolean;
@@ -11,7 +10,13 @@ export default {
FIRST_KEY_INDEX: 1,
IS_READ_ONLY: true,
transformArguments(key: RedisArgument, options?: TsGetOptions) {
return pushLatestArgument(['TS.GET', key], options?.LATEST);
const args = ['TS.GET', key];
if (options?.LATEST) {
args.push('LATEST');
}
return args;
},
transformReply: {
2(reply: Resp2Reply<TsGetReply>) {

View File

@@ -2,7 +2,7 @@ import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import INCRBY from './INCRBY';
describe('INCRBY', () => {
describe('TS.INCRBY', () => {
describe('transformArguments', () => {
it('without options', () => {
assert.deepEqual(
@@ -82,10 +82,8 @@ describe('INCRBY', () => {
testUtils.testWithClient('client.ts.incrBy', async client => {
assert.equal(
await client.ts.incrBy('key', 1, {
TIMESTAMP: 0
}),
0
typeof await client.ts.incrBy('key', 1),
'number'
);
}, GLOBAL.SERVERS.OPEN);
});

View File

@@ -1,11 +1,46 @@
import { IncrDecrOptions, transformIncrDecrArguments } from '.';
import { RedisArgument, NumberReply, Command } from '@redis/client/dist/lib/RESP/types';
import { Timestamp, transformTimestampArgument, pushRetentionArgument, pushChunkSizeArgument, Labels, pushLabelsArgument } from '.';
export interface TsIncrByOptions {
TIMESTAMP?: Timestamp;
RETENTION?: number;
UNCOMPRESSED?: boolean;
CHUNK_SIZE?: number;
LABELS?: Labels;
}
export function transformIncrByArguments(
command: RedisArgument,
key: RedisArgument,
value: number,
options?: TsIncrByOptions
) {
const args = [
command,
key,
value.toString()
];
if (options?.TIMESTAMP !== undefined && options?.TIMESTAMP !== null) {
args.push('TIMESTAMP', transformTimestampArgument(options.TIMESTAMP));
}
pushRetentionArgument(args, options?.RETENTION);
if (options?.UNCOMPRESSED) {
args.push('UNCOMPRESSED');
}
pushChunkSizeArgument(args, options?.CHUNK_SIZE);
pushLabelsArgument(args, options?.LABELS);
return args;
}
export default {
FIRST_KEY_INDEX: 1,
IS_READ_ONLY: false,
transformArguments(key: RedisArgument, value: number, options?: IncrDecrOptions) {
return transformIncrDecrArguments('TS.INCRBY', key, value, options);
},
transformArguments: transformIncrByArguments.bind(undefined, 'TS.INCRBY'),
transformReply: undefined as unknown as () => NumberReply
} as const satisfies Command;

View File

@@ -3,7 +3,7 @@ import { TimeSeriesAggregationType, TimeSeriesDuplicatePolicies } from '.';
import testUtils, { GLOBAL } from '../test-utils';
import { InfoReply, transformArguments } from './INFO';
describe('INFO', () => {
describe('TS.INFO', () => {
it('transformArguments', () => {
assert.deepEqual(
transformArguments('key'),

View File

@@ -4,7 +4,7 @@ import testUtils, { GLOBAL } from '../test-utils';
import { assertInfo } from './INFO.spec';
import { transformArguments } from './INFO_DEBUG';
describe('INFO_DEBUG', () => {
describe('TS.INFO_DEBUG', () => {
it('transformArguments', () => {
assert.deepEqual(
transformArguments('key'),

View File

@@ -1,8 +1,9 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import MADD from './MADD';
import { SimpleError } from '@redis/client/lib/errors';
describe('MADD', () => {
describe.only('TS.MADD', () => {
it('transformArguments', () => {
assert.deepEqual(
MADD.transformArguments([{
@@ -18,22 +19,23 @@ describe('MADD', () => {
);
});
// Should we check empty array?
testUtils.testWithClient('client.ts.mAdd', async client => {
await client.ts.create('key');
assert.deepEqual(
await client.ts.mAdd([{
const [, reply] = await Promise.all([
client.ts.create('key'),
client.ts.mAdd([{
key: 'key',
timestamp: 0,
value: 0
value: 1
}, {
key: 'key',
timestamp: 1,
timestamp: 0,
value: 1
}]),
[0, 1]
);
}])
]);
assert.ok(Array.isArray(reply));
assert.equal(reply.length, 2);
assert.equal(reply[0], 0);
assert.ok(reply[1] instanceof SimpleError);
}, GLOBAL.SERVERS.OPEN);
});

View File

@@ -1,5 +1,5 @@
import { Timestamp, transformTimestampArgument } from '.';
import { ArrayReply, NumberReply, Command } from '@redis/client/dist/lib/RESP/types';
import { ArrayReply, NumberReply, SimpleErrorReply, Command } from '@redis/client/dist/lib/RESP/types';
export interface TsMAddSample {
key: string;
@@ -23,5 +23,5 @@ export default {
return args;
},
transformReply: undefined as unknown as () => ArrayReply<NumberReply>
transformReply: undefined as unknown as () => ArrayReply<NumberReply | SimpleErrorReply>
} as const satisfies Command;

View File

@@ -2,7 +2,7 @@ import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './MGET';
describe('MGET', () => {
describe('TS.MGET', () => {
describe('transformArguments', () => {
it('without options', () => {
assert.deepEqual(

View File

@@ -2,7 +2,7 @@ import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './MGET_WITHLABELS';
describe('MGET_WITHLABELS', () => {
describe('TS.MGET_WITHLABELS', () => {
describe('transformArguments', () => {
it('without options', () => {
assert.deepEqual(

View File

@@ -3,7 +3,7 @@ import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './MRANGE';
import { TimeSeriesAggregationType, TimeSeriesReducers } from '.';
describe('MRANGE', () => {
describe('TS.MRANGE', () => {
it('transformArguments', () => {
assert.deepEqual(
transformArguments('-', '+', 'label=value', {

View File

@@ -3,7 +3,7 @@ import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './MRANGE_WITHLABELS';
import { TimeSeriesAggregationType, TimeSeriesReducers } from '.';
describe('MRANGE_WITHLABELS', () => {
describe('TS.MRANGE_WITHLABELS', () => {
it('transformArguments', () => {
assert.deepEqual(
transformArguments('-', '+', 'label=value', {

View File

@@ -3,7 +3,7 @@ import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './MREVRANGE';
import { TimeSeriesAggregationType, TimeSeriesReducers } from '.';
describe('MREVRANGE', () => {
describe('TS.MREVRANGE', () => {
it('transformArguments', () => {
assert.deepEqual(
transformArguments('-', '+', 'label=value', {

View File

@@ -3,7 +3,7 @@ import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './MREVRANGE_WITHLABELS';
import { TimeSeriesAggregationType, TimeSeriesReducers } from '.';
describe('MREVRANGE_WITHLABELS', () => {
describe('TS.MREVRANGE_WITHLABELS', () => {
it('transformArguments', () => {
assert.deepEqual(
transformArguments('-', '+', 'label=value', {

View File

@@ -2,7 +2,7 @@ import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './QUERYINDEX';
describe('QUERYINDEX', () => {
describe('TS.QUERYINDEX', () => {
describe('transformArguments', () => {
it('single filter', () => {
assert.deepEqual(

View File

@@ -3,7 +3,7 @@ import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './RANGE';
import { TimeSeriesAggregationType } from '.';
describe('RANGE', () => {
describe('TS.RANGE', () => {
it('transformArguments', () => {
assert.deepEqual(
transformArguments('key', '-', '+', {

View File

@@ -3,7 +3,7 @@ import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './REVRANGE';
import { TimeSeriesAggregationType } from '.';
describe('REVRANGE', () => {
describe('TS.REVRANGE', () => {
describe('transformArguments', () => {
it('without options', () => {
assert.deepEqual(

View File

@@ -1,439 +1,439 @@
import { RedisCommandArguments } from '@redis/client/dist/lib/commands';
import { strict as assert } from 'assert';
import {
transformTimestampArgument,
pushRetentionArgument,
TimeSeriesEncoding,
pushEncodingArgument,
pushChunkSizeArgument,
pushDuplicatePolicy,
pushLabelsArgument,
transformIncrDecrArguments,
transformSampleReply,
TimeSeriesAggregationType,
pushRangeArguments,
pushMRangeGroupByArguments,
TimeSeriesReducers,
pushFilterArgument,
pushMRangeArguments,
pushWithLabelsArgument,
pushMRangeWithLabelsArguments,
transformRangeReply,
transformMRangeReply,
transformMRangeWithLabelsReply,
TimeSeriesDuplicatePolicies,
pushLatestArgument,
TimeSeriesBucketTimestamp
} from '.';
// import { RedisCommandArguments } from '@redis/client/dist/lib/commands';
// import { strict as assert } from 'assert';
// import {
// transformTimestampArgument,
// pushRetentionArgument,
// TimeSeriesEncoding,
// pushEncodingArgument,
// pushChunkSizeArgument,
// pushDuplicatePolicy,
// pushLabelsArgument,
// transformIncrDecrArguments,
// transformSampleReply,
// TimeSeriesAggregationType,
// pushRangeArguments,
// pushMRangeGroupByArguments,
// TimeSeriesReducers,
// pushFilterArgument,
// pushMRangeArguments,
// pushWithLabelsArgument,
// pushMRangeWithLabelsArguments,
// transformRangeReply,
// transformMRangeReply,
// transformMRangeWithLabelsReply,
// TimeSeriesDuplicatePolicies,
// pushLatestArgument,
// TimeSeriesBucketTimestamp
// } from '.';
describe('transformTimestampArgument', () => {
it('number', () => {
assert.equal(
transformTimestampArgument(0),
'0'
);
});
// describe('transformTimestampArgument', () => {
// it('number', () => {
// assert.equal(
// transformTimestampArgument(0),
// '0'
// );
// });
it('Date', () => {
assert.equal(
transformTimestampArgument(new Date(0)),
'0'
);
});
// it('Date', () => {
// assert.equal(
// transformTimestampArgument(new Date(0)),
// '0'
// );
// });
it('string', () => {
assert.equal(
transformTimestampArgument('*'),
'*'
);
});
});
// it('string', () => {
// assert.equal(
// transformTimestampArgument('*'),
// '*'
// );
// });
// });
function testOptionalArgument(fn: (args: RedisCommandArguments) => unknown): void {
it('undefined', () => {
assert.deepEqual(
fn([]),
[]
);
});
}
// function testOptionalArgument(fn: (args: RedisCommandArguments) => unknown): void {
// it('undefined', () => {
// assert.deepEqual(
// fn([]),
// []
// );
// });
// }
describe('pushRetentionArgument', () => {
testOptionalArgument(pushRetentionArgument);
// describe('pushRetentionArgument', () => {
// testOptionalArgument(pushRetentionArgument);
it('number', () => {
assert.deepEqual(
pushRetentionArgument([], 1),
['RETENTION', '1']
);
});
});
// it('number', () => {
// assert.deepEqual(
// pushRetentionArgument([], 1),
// ['RETENTION', '1']
// );
// });
// });
describe('pushEncodingArgument', () => {
testOptionalArgument(pushEncodingArgument);
// describe('pushEncodingArgument', () => {
// testOptionalArgument(pushEncodingArgument);
it('UNCOMPRESSED', () => {
assert.deepEqual(
pushEncodingArgument([], TimeSeriesEncoding.UNCOMPRESSED),
['ENCODING', 'UNCOMPRESSED']
);
});
});
// it('UNCOMPRESSED', () => {
// assert.deepEqual(
// pushEncodingArgument([], TimeSeriesEncoding.UNCOMPRESSED),
// ['ENCODING', 'UNCOMPRESSED']
// );
// });
// });
describe('pushChunkSizeArgument', () => {
testOptionalArgument(pushChunkSizeArgument);
// describe('pushChunkSizeArgument', () => {
// testOptionalArgument(pushChunkSizeArgument);
it('number', () => {
assert.deepEqual(
pushChunkSizeArgument([], 1),
['CHUNK_SIZE', '1']
);
});
});
// it('number', () => {
// assert.deepEqual(
// pushChunkSizeArgument([], 1),
// ['CHUNK_SIZE', '1']
// );
// });
// });
describe('pushDuplicatePolicy', () => {
testOptionalArgument(pushDuplicatePolicy);
// describe('pushDuplicatePolicy', () => {
// testOptionalArgument(pushDuplicatePolicy);
it('BLOCK', () => {
assert.deepEqual(
pushDuplicatePolicy([], TimeSeriesDuplicatePolicies.BLOCK),
['DUPLICATE_POLICY', 'BLOCK']
);
});
});
// it('BLOCK', () => {
// assert.deepEqual(
// pushDuplicatePolicy([], TimeSeriesDuplicatePolicies.BLOCK),
// ['DUPLICATE_POLICY', 'BLOCK']
// );
// });
// });
describe('pushLabelsArgument', () => {
testOptionalArgument(pushLabelsArgument);
// describe('pushLabelsArgument', () => {
// testOptionalArgument(pushLabelsArgument);
it("{ label: 'value' }", () => {
assert.deepEqual(
pushLabelsArgument([], { label: 'value' }),
['LABELS', 'label', 'value']
);
});
});
// it("{ label: 'value' }", () => {
// assert.deepEqual(
// pushLabelsArgument([], { label: 'value' }),
// ['LABELS', 'label', 'value']
// );
// });
// });
describe('transformIncrDecrArguments', () => {
it('without options', () => {
assert.deepEqual(
transformIncrDecrArguments('TS.INCRBY', 'key', 1),
['TS.INCRBY', 'key', '1']
);
});
// describe('transformIncrDecrArguments', () => {
// it('without options', () => {
// assert.deepEqual(
// transformIncrDecrArguments('TS.INCRBY', 'key', 1),
// ['TS.INCRBY', 'key', '1']
// );
// });
it('with TIMESTAMP', () => {
assert.deepEqual(
transformIncrDecrArguments('TS.INCRBY', 'key', 1, {
TIMESTAMP: '*'
}),
['TS.INCRBY', 'key', '1', 'TIMESTAMP', '*']
);
});
// it('with TIMESTAMP', () => {
// assert.deepEqual(
// transformIncrDecrArguments('TS.INCRBY', 'key', 1, {
// TIMESTAMP: '*'
// }),
// ['TS.INCRBY', 'key', '1', 'TIMESTAMP', '*']
// );
// });
it('with UNCOMPRESSED', () => {
assert.deepEqual(
transformIncrDecrArguments('TS.INCRBY', 'key', 1, {
UNCOMPRESSED: true
}),
['TS.INCRBY', 'key', '1', 'UNCOMPRESSED']
);
});
// it('with UNCOMPRESSED', () => {
// assert.deepEqual(
// transformIncrDecrArguments('TS.INCRBY', 'key', 1, {
// UNCOMPRESSED: true
// }),
// ['TS.INCRBY', 'key', '1', 'UNCOMPRESSED']
// );
// });
it('with UNCOMPRESSED false', () => {
assert.deepEqual(
transformIncrDecrArguments('TS.INCRBY', 'key', 1, {
UNCOMPRESSED: false
}),
['TS.INCRBY', 'key', '1']
);
});
});
// it('with UNCOMPRESSED false', () => {
// assert.deepEqual(
// transformIncrDecrArguments('TS.INCRBY', 'key', 1, {
// UNCOMPRESSED: false
// }),
// ['TS.INCRBY', 'key', '1']
// );
// });
// });
it('transformSampleReply', () => {
assert.deepEqual(
transformSampleReply([1, '1.1']),
{
timestamp: 1,
value: 1.1
}
);
});
// it('transformSampleReply', () => {
// assert.deepEqual(
// transformSampleReply([1, '1.1']),
// {
// timestamp: 1,
// value: 1.1
// }
// );
// });
describe('pushRangeArguments', () => {
it('without options', () => {
assert.deepEqual(
pushRangeArguments([], '-', '+'),
['-', '+']
);
});
// describe('pushRangeArguments', () => {
// it('without options', () => {
// assert.deepEqual(
// pushRangeArguments([], '-', '+'),
// ['-', '+']
// );
// });
describe('with FILTER_BY_TS', () => {
it('string', () => {
assert.deepEqual(
pushRangeArguments([], '-', '+', {
FILTER_BY_TS: ['ts']
}),
['-', '+', 'FILTER_BY_TS', 'ts']
);
});
// describe('with FILTER_BY_TS', () => {
// it('string', () => {
// assert.deepEqual(
// pushRangeArguments([], '-', '+', {
// FILTER_BY_TS: ['ts']
// }),
// ['-', '+', 'FILTER_BY_TS', 'ts']
// );
// });
it('Array', () => {
assert.deepEqual(
pushRangeArguments([], '-', '+', {
FILTER_BY_TS: ['1', '2']
}),
['-', '+', 'FILTER_BY_TS', '1', '2']
);
});
});
// it('Array', () => {
// assert.deepEqual(
// pushRangeArguments([], '-', '+', {
// FILTER_BY_TS: ['1', '2']
// }),
// ['-', '+', 'FILTER_BY_TS', '1', '2']
// );
// });
// });
it('with FILTER_BY_VALUE', () => {
assert.deepEqual(
pushRangeArguments([], '-', '+', {
FILTER_BY_VALUE: {
min: 1,
max: 2
}
}),
['-', '+', 'FILTER_BY_VALUE', '1', '2']
);
});
// it('with FILTER_BY_VALUE', () => {
// assert.deepEqual(
// pushRangeArguments([], '-', '+', {
// FILTER_BY_VALUE: {
// min: 1,
// max: 2
// }
// }),
// ['-', '+', 'FILTER_BY_VALUE', '1', '2']
// );
// });
it('with COUNT', () => {
assert.deepEqual(
pushRangeArguments([], '-', '+', {
COUNT: 1
}),
['-', '+', 'COUNT', '1']
);
});
// it('with COUNT', () => {
// assert.deepEqual(
// pushRangeArguments([], '-', '+', {
// COUNT: 1
// }),
// ['-', '+', 'COUNT', '1']
// );
// });
it('with ALIGN', () => {
assert.deepEqual(
pushRangeArguments([], '-', '+', {
ALIGN: 1
}),
['-', '+', 'ALIGN', '1']
);
});
// it('with ALIGN', () => {
// assert.deepEqual(
// pushRangeArguments([], '-', '+', {
// ALIGN: 1
// }),
// ['-', '+', 'ALIGN', '1']
// );
// });
describe('with AGGREGATION', () => {
it('without options', () => {
assert.deepEqual(
pushRangeArguments([], '-', '+', {
AGGREGATION: {
type: TimeSeriesAggregationType.FIRST,
timeBucket: 1
}
}),
['-', '+', 'AGGREGATION', 'FIRST', '1']
);
});
// describe('with AGGREGATION', () => {
// it('without options', () => {
// assert.deepEqual(
// pushRangeArguments([], '-', '+', {
// AGGREGATION: {
// type: TimeSeriesAggregationType.FIRST,
// timeBucket: 1
// }
// }),
// ['-', '+', 'AGGREGATION', 'FIRST', '1']
// );
// });
it('with BUCKETTIMESTAMP', () => {
assert.deepEqual(
pushRangeArguments([], '-', '+', {
AGGREGATION: {
type: TimeSeriesAggregationType.FIRST,
timeBucket: 1,
BUCKETTIMESTAMP: TimeSeriesBucketTimestamp.LOW
}
}),
['-', '+', 'AGGREGATION', 'FIRST', '1', 'BUCKETTIMESTAMP', '-']
);
});
// it('with BUCKETTIMESTAMP', () => {
// assert.deepEqual(
// pushRangeArguments([], '-', '+', {
// AGGREGATION: {
// type: TimeSeriesAggregationType.FIRST,
// timeBucket: 1,
// BUCKETTIMESTAMP: TimeSeriesBucketTimestamp.LOW
// }
// }),
// ['-', '+', 'AGGREGATION', 'FIRST', '1', 'BUCKETTIMESTAMP', '-']
// );
// });
it('with BUCKETTIMESTAMP', () => {
assert.deepEqual(
pushRangeArguments([], '-', '+', {
AGGREGATION: {
type: TimeSeriesAggregationType.FIRST,
timeBucket: 1,
EMPTY: true
}
}),
['-', '+', 'AGGREGATION', 'FIRST', '1', 'EMPTY']
);
});
});
// it('with BUCKETTIMESTAMP', () => {
// assert.deepEqual(
// pushRangeArguments([], '-', '+', {
// AGGREGATION: {
// type: TimeSeriesAggregationType.FIRST,
// timeBucket: 1,
// EMPTY: true
// }
// }),
// ['-', '+', 'AGGREGATION', 'FIRST', '1', 'EMPTY']
// );
// });
// });
it('with FILTER_BY_TS, FILTER_BY_VALUE, COUNT, ALIGN, AGGREGATION', () => {
assert.deepEqual(
pushRangeArguments([], '-', '+', {
FILTER_BY_TS: ['ts'],
FILTER_BY_VALUE: {
min: 1,
max: 2
},
COUNT: 1,
ALIGN: 1,
AGGREGATION: {
type: TimeSeriesAggregationType.FIRST,
timeBucket: 1,
BUCKETTIMESTAMP: TimeSeriesBucketTimestamp.LOW,
EMPTY: true
}
}),
['-', '+', 'FILTER_BY_TS', 'ts', 'FILTER_BY_VALUE', '1', '2',
'COUNT', '1', 'ALIGN', '1', 'AGGREGATION', 'FIRST', '1', 'BUCKETTIMESTAMP', '-', 'EMPTY']
);
});
});
// it('with FILTER_BY_TS, FILTER_BY_VALUE, COUNT, ALIGN, AGGREGATION', () => {
// assert.deepEqual(
// pushRangeArguments([], '-', '+', {
// FILTER_BY_TS: ['ts'],
// FILTER_BY_VALUE: {
// min: 1,
// max: 2
// },
// COUNT: 1,
// ALIGN: 1,
// AGGREGATION: {
// type: TimeSeriesAggregationType.FIRST,
// timeBucket: 1,
// BUCKETTIMESTAMP: TimeSeriesBucketTimestamp.LOW,
// EMPTY: true
// }
// }),
// ['-', '+', 'FILTER_BY_TS', 'ts', 'FILTER_BY_VALUE', '1', '2',
// 'COUNT', '1', 'ALIGN', '1', 'AGGREGATION', 'FIRST', '1', 'BUCKETTIMESTAMP', '-', 'EMPTY']
// );
// });
// });
describe('pushMRangeGroupByArguments', () => {
it('undefined', () => {
assert.deepEqual(
pushMRangeGroupByArguments([]),
[]
);
});
// describe('pushMRangeGroupByArguments', () => {
// it('undefined', () => {
// assert.deepEqual(
// pushMRangeGroupByArguments([]),
// []
// );
// });
it('with GROUPBY', () => {
assert.deepEqual(
pushMRangeGroupByArguments([], {
label: 'label',
reducer: TimeSeriesReducers.MAXIMUM
}),
['GROUPBY', 'label', 'REDUCE', 'MAX']
);
});
});
// it('with GROUPBY', () => {
// assert.deepEqual(
// pushMRangeGroupByArguments([], {
// label: 'label',
// reducer: TimeSeriesReducers.MAXIMUM
// }),
// ['GROUPBY', 'label', 'REDUCE', 'MAX']
// );
// });
// });
describe('pushFilterArgument', () => {
it('string', () => {
assert.deepEqual(
pushFilterArgument([], 'label=value'),
['FILTER', 'label=value']
);
});
// describe('pushFilterArgument', () => {
// it('string', () => {
// assert.deepEqual(
// pushFilterArgument([], 'label=value'),
// ['FILTER', 'label=value']
// );
// });
it('Array', () => {
assert.deepEqual(
pushFilterArgument([], ['1=1', '2=2']),
['FILTER', '1=1', '2=2']
);
});
});
// it('Array', () => {
// assert.deepEqual(
// pushFilterArgument([], ['1=1', '2=2']),
// ['FILTER', '1=1', '2=2']
// );
// });
// });
describe('pushMRangeArguments', () => {
it('without options', () => {
assert.deepEqual(
pushMRangeArguments([], '-', '+', 'label=value'),
['-', '+', 'FILTER', 'label=value']
);
});
// describe('pushMRangeArguments', () => {
// it('without options', () => {
// assert.deepEqual(
// pushMRangeArguments([], '-', '+', 'label=value'),
// ['-', '+', 'FILTER', 'label=value']
// );
// });
it('with GROUPBY', () => {
assert.deepEqual(
pushMRangeArguments([], '-', '+', 'label=value', {
GROUPBY: {
label: 'label',
reducer: TimeSeriesReducers.MAXIMUM
}
}),
['-', '+', 'FILTER', 'label=value', 'GROUPBY', 'label', 'REDUCE', 'MAX']
);
});
});
// it('with GROUPBY', () => {
// assert.deepEqual(
// pushMRangeArguments([], '-', '+', 'label=value', {
// GROUPBY: {
// label: 'label',
// reducer: TimeSeriesReducers.MAXIMUM
// }
// }),
// ['-', '+', 'FILTER', 'label=value', 'GROUPBY', 'label', 'REDUCE', 'MAX']
// );
// });
// });
describe('pushWithLabelsArgument', () => {
it('without selected labels', () => {
assert.deepEqual(
pushWithLabelsArgument([]),
['WITHLABELS']
);
});
// describe('pushWithLabelsArgument', () => {
// it('without selected labels', () => {
// assert.deepEqual(
// pushWithLabelsArgument([]),
// ['WITHLABELS']
// );
// });
it('with selected labels', () => {
assert.deepEqual(
pushWithLabelsArgument([], ['label']),
['SELECTED_LABELS', 'label']
);
});
});
// it('with selected labels', () => {
// assert.deepEqual(
// pushWithLabelsArgument([], ['label']),
// ['SELECTED_LABELS', 'label']
// );
// });
// });
it('pushMRangeWithLabelsArguments', () => {
assert.deepEqual(
pushMRangeWithLabelsArguments([], '-', '+', 'label=value'),
['-', '+', 'WITHLABELS', 'FILTER', 'label=value']
);
});
// it('pushMRangeWithLabelsArguments', () => {
// assert.deepEqual(
// pushMRangeWithLabelsArguments([], '-', '+', 'label=value'),
// ['-', '+', 'WITHLABELS', 'FILTER', 'label=value']
// );
// });
it('transformRangeReply', () => {
assert.deepEqual(
transformRangeReply([[1, '1.1'], [2, '2.2']]),
[{
timestamp: 1,
value: 1.1
}, {
timestamp: 2,
value: 2.2
}]
);
});
// it('transformRangeReply', () => {
// assert.deepEqual(
// transformRangeReply([[1, '1.1'], [2, '2.2']]),
// [{
// timestamp: 1,
// value: 1.1
// }, {
// timestamp: 2,
// value: 2.2
// }]
// );
// });
describe('transformMRangeReply', () => {
assert.deepEqual(
transformMRangeReply([[
'key',
[],
[[1, '1.1'], [2, '2.2']]
]]),
[{
key: 'key',
samples: [{
timestamp: 1,
value: 1.1
}, {
timestamp: 2,
value: 2.2
}]
}]
);
});
// describe('transformMRangeReply', () => {
// assert.deepEqual(
// transformMRangeReply([[
// 'key',
// [],
// [[1, '1.1'], [2, '2.2']]
// ]]),
// [{
// key: 'key',
// samples: [{
// timestamp: 1,
// value: 1.1
// }, {
// timestamp: 2,
// value: 2.2
// }]
// }]
// );
// });
describe('transformMRangeWithLabelsReply', () => {
assert.deepEqual(
transformMRangeWithLabelsReply([[
'key',
[['label', 'value']],
[[1, '1.1'], [2, '2.2']]
]]),
[{
key: 'key',
labels: {
label: 'value'
},
samples: [{
timestamp: 1,
value: 1.1
}, {
timestamp: 2,
value: 2.2
}]
}]
);
});
// describe('transformMRangeWithLabelsReply', () => {
// assert.deepEqual(
// transformMRangeWithLabelsReply([[
// 'key',
// [['label', 'value']],
// [[1, '1.1'], [2, '2.2']]
// ]]),
// [{
// key: 'key',
// labels: {
// label: 'value'
// },
// samples: [{
// timestamp: 1,
// value: 1.1
// }, {
// timestamp: 2,
// value: 2.2
// }]
// }]
// );
// });
describe('pushLatestArgument', () => {
it('undefined', () => {
assert.deepEqual(
pushLatestArgument([]),
[]
);
});
// describe('pushLatestArgument', () => {
// it('undefined', () => {
// assert.deepEqual(
// pushLatestArgument([]),
// []
// );
// });
it('false', () => {
assert.deepEqual(
pushLatestArgument([], false),
[]
);
});
// it('false', () => {
// assert.deepEqual(
// pushLatestArgument([], false),
// []
// );
// });
it('true', () => {
assert.deepEqual(
pushLatestArgument([], true),
['LATEST']
);
});
})
// it('true', () => {
// assert.deepEqual(
// pushLatestArgument([], true),
// ['LATEST']
// );
// });
// })

View File

@@ -1,467 +1,367 @@
import * as ADD from './ADD';
import * as ALTER from './ALTER';
import * as CREATE from './CREATE';
import * as CREATERULE from './CREATERULE';
import * as DECRBY from './DECRBY';
import * as DEL from './DEL';
import * as DELETERULE from './DELETERULE';
import * as GET from './GET';
import * as INCRBY from './INCRBY';
import * as INFO_DEBUG from './INFO_DEBUG';
import * as INFO from './INFO';
import * as MADD from './MADD';
import * as MGET from './MGET';
import * as MGET_WITHLABELS from './MGET_WITHLABELS';
import * as QUERYINDEX from './QUERYINDEX';
import * as RANGE from './RANGE';
import * as REVRANGE from './REVRANGE';
import * as MRANGE from './MRANGE';
import * as MRANGE_WITHLABELS from './MRANGE_WITHLABELS';
import * as MREVRANGE from './MREVRANGE';
import * as MREVRANGE_WITHLABELS from './MREVRANGE_WITHLABELS';
import { RedisCommandArguments } from '@redis/client/dist/lib/commands';
import { pushVariadicArguments } from '@redis/client/dist/lib/commands/generic-transformers';
import type { RedisArgument, RedisCommands } from '@redis/client/dist/lib/RESP/types';
import ADD from './ADD';
import ALTER from './ALTER';
import CREATE from './CREATE';
import CREATERULE from './CREATERULE';
import DECRBY from './DECRBY';
import DEL from './DEL';
import DELETERULE from './DELETERULE';
import GET from './GET';
import INCRBY from './INCRBY';
// import INFO_DEBUG from './INFO_DEBUG';
// import INFO from './INFO';
import MADD from './MADD';
// import MGET from './MGET';
// import MGET_WITHLABELS from './MGET_WITHLABELS';
// import QUERYINDEX from './QUERYINDEX';
// import RANGE from './RANGE';
// import REVRANGE from './REVRANGE';
// import MRANGE from './MRANGE';
// import MRANGE_WITHLABELS from './MRANGE_WITHLABELS';
// import MREVRANGE from './MREVRANGE';
// import MREVRANGE_WITHLABELS from './MREVRANGE_WITHLABELS';
export default {
ADD,
add: ADD,
ALTER,
alter: ALTER,
CREATE,
create: CREATE,
CREATERULE,
createRule: CREATERULE,
DECRBY,
decrBy: DECRBY,
DEL,
del: DEL,
DELETERULE,
deleteRule: DELETERULE,
GET,
get: GET,
INCRBY,
incrBy: INCRBY,
INFO_DEBUG,
infoDebug: INFO_DEBUG,
INFO,
info: INFO,
MADD,
mAdd: MADD,
MGET,
mGet: MGET,
MGET_WITHLABELS,
mGetWithLabels: MGET_WITHLABELS,
QUERYINDEX,
queryIndex: QUERYINDEX,
RANGE,
range: RANGE,
REVRANGE,
revRange: REVRANGE,
MRANGE,
mRange: MRANGE,
MRANGE_WITHLABELS,
mRangeWithLabels: MRANGE_WITHLABELS,
MREVRANGE,
mRevRange: MREVRANGE,
MREVRANGE_WITHLABELS,
mRevRangeWithLabels: MREVRANGE_WITHLABELS
};
ADD,
add: ADD,
ALTER,
alter: ALTER,
CREATE,
create: CREATE,
CREATERULE,
createRule: CREATERULE,
DECRBY,
decrBy: DECRBY,
DEL,
del: DEL,
DELETERULE,
deleteRule: DELETERULE,
GET,
get: GET,
INCRBY,
incrBy: INCRBY,
// INFO_DEBUG,
// infoDebug: INFO_DEBUG,
// INFO,
// info: INFO,
MADD,
mAdd: MADD,
// MGET,
// mGet: MGET,
// MGET_WITHLABELS,
// mGetWithLabels: MGET_WITHLABELS,
// QUERYINDEX,
// queryIndex: QUERYINDEX,
// RANGE,
// range: RANGE,
// REVRANGE,
// revRange: REVRANGE,
// MRANGE,
// mRange: MRANGE,
// MRANGE_WITHLABELS,
// mRangeWithLabels: MRANGE_WITHLABELS,
// MREVRANGE,
// mRevRange: MREVRANGE,
// MREVRANGE_WITHLABELS,
// mRevRangeWithLabels: MREVRANGE_WITHLABELS
} as const satisfies RedisCommands;
export enum TimeSeriesAggregationType {
AVG = 'AVG',
// @deprecated
AVERAGE = 'AVG',
FIRST = 'FIRST',
LAST = 'LAST',
MIN = 'MIN',
// @deprecated
MINIMUM = 'MIN',
MAX = 'MAX',
// @deprecated
MAXIMUM = 'MAX',
SUM = 'SUM',
RANGE = 'RANGE',
COUNT = 'COUNT',
STD_P = 'STD.P',
STD_S = 'STD.S',
VAR_P = 'VAR.P',
VAR_S = 'VAR.S',
TWA = 'TWA'
export function pushRetentionArgument(args: Array<RedisArgument>, retention?: number) {
if (retention !== undefined) {
args.push('RETENTION', retention.toString());
}
}
export enum TimeSeriesDuplicatePolicies {
BLOCK = 'BLOCK',
FIRST = 'FIRST',
LAST = 'LAST',
MIN = 'MIN',
MAX = 'MAX',
SUM = 'SUM'
export const TIME_SERIES_ENCODING = {
COMPRESSED: 'COMPRESSED',
UNCOMPRESSED: 'UNCOMPRESSED'
} as const;
export type TimeSeriesEncoding = typeof TIME_SERIES_ENCODING[keyof typeof TIME_SERIES_ENCODING];
export function pushEncodingArgument(args: Array<RedisArgument>, encoding?: TimeSeriesEncoding) {
if (encoding !== undefined) {
args.push('ENCODING', encoding);
}
}
export enum TimeSeriesReducers {
AVG = 'AVG',
SUM = 'SUM',
MIN = 'MIN',
// @deprecated
MINIMUM = 'MIN',
MAX = 'MAX',
// @deprecated
MAXIMUM = 'MAX',
RANGE = 'range',
COUNT = 'COUNT',
STD_P = 'STD.P',
STD_S = 'STD.S',
VAR_P = 'VAR.P',
VAR_S = 'VAR.S',
export function pushChunkSizeArgument(args: Array<RedisArgument>, chunkSize?: number) {
if (chunkSize !== undefined) {
args.push('CHUNK_SIZE', chunkSize.toString());
}
}
export const TIME_SERIES_DUPLICATE_POLICIES = {
BLOCK: 'BLOCK',
FIRST: 'FIRST',
LAST: 'LAST',
MIN: 'MIN',
MAX: 'MAX',
SUM: 'SUM'
} as const;
export type TimeSeriesDuplicatePolicies = typeof TIME_SERIES_DUPLICATE_POLICIES[keyof typeof TIME_SERIES_DUPLICATE_POLICIES];
export function pushDuplicatePolicy(args: Array<RedisArgument>, duplicatePolicy?: TimeSeriesDuplicatePolicies) {
if (duplicatePolicy !== undefined) {
args.push('DUPLICATE_POLICY', duplicatePolicy);
}
}
export type Timestamp = number | Date | string;
export function transformTimestampArgument(timestamp: Timestamp): string {
if (typeof timestamp === 'string') return timestamp;
if (typeof timestamp === 'string') return timestamp;
return (
typeof timestamp === 'number' ?
timestamp :
timestamp.getTime()
).toString();
return (
typeof timestamp === 'number' ?
timestamp :
timestamp.getTime()
).toString();
}
export function pushRetentionArgument(args: RedisCommandArguments, retention?: number): RedisCommandArguments {
if (retention !== undefined) {
args.push(
'RETENTION',
retention.toString()
);
}
return args;
}
export enum TimeSeriesEncoding {
COMPRESSED = 'COMPRESSED',
UNCOMPRESSED = 'UNCOMPRESSED'
}
export function pushEncodingArgument(args: RedisCommandArguments, encoding?: TimeSeriesEncoding): RedisCommandArguments {
if (encoding !== undefined) {
args.push(
'ENCODING',
encoding
);
}
return args;
}
export function pushChunkSizeArgument(args: RedisCommandArguments, chunkSize?: number): RedisCommandArguments {
if (chunkSize !== undefined) {
args.push(
'CHUNK_SIZE',
chunkSize.toString()
);
}
return args;
}
export function pushDuplicatePolicy(args: RedisCommandArguments, duplicatePolicy?: TimeSeriesDuplicatePolicies): RedisCommandArguments {
if (duplicatePolicy !== undefined) {
args.push(
'DUPLICATE_POLICY',
duplicatePolicy
);
}
return args;
}
export type RawLabels = Array<[label: string, value: string]>;
export type Labels = {
[label: string]: string;
[label: string]: string;
};
export function transformLablesReply(reply: RawLabels): Labels {
const labels: Labels = {};
export function pushLabelsArgument(args: Array<RedisArgument>, labels?: Labels) {
if (labels) {
args.push('LABELS');
for (const [key, value] of reply) {
labels[key] = value;
for (const [label, value] of Object.entries(labels)) {
args.push(label, value);
}
}
return labels
return args;
}
export function pushLabelsArgument(args: RedisCommandArguments, labels?: Labels): RedisCommandArguments {
if (labels) {
args.push('LABELS');
// export type RawLabelsReply = ArrayReply<TuplesReply<[BlobStringReply, BlobStringReply]>>;
for (const [label, value] of Object.entries(labels)) {
args.push(label, value);
}
}
// export function transformLablesReply(reply: RawLabelsReply) {
// const labels: Record<string, BlobStringReply> = {};
return args;
}
// for (const [key, value] of reply) {
// labels[key.toString()] = value;
// }
export interface IncrDecrOptions {
TIMESTAMP?: Timestamp;
RETENTION?: number;
UNCOMPRESSED?: boolean;
CHUNK_SIZE?: number;
LABELS?: Labels;
}
// return labels
// }
export function transformIncrDecrArguments(
command: 'TS.INCRBY' | 'TS.DECRBY',
key: string,
value: number,
options?: IncrDecrOptions
): RedisCommandArguments {
const args = [
command,
key,
value.toString()
];
if (options?.TIMESTAMP !== undefined && options?.TIMESTAMP !== null) {
args.push('TIMESTAMP', transformTimestampArgument(options.TIMESTAMP));
}
// export type SampleRawReply = [timestamp: number, value: string];
pushRetentionArgument(args, options?.RETENTION);
// export interface SampleReply {
// timestamp: number;
// value: number;
// }
if (options?.UNCOMPRESSED) {
args.push('UNCOMPRESSED');
}
// export function transformSampleReply(reply: SampleRawReply): SampleReply {
// return {
// timestamp: reply[0],
// value: Number(reply[1])
// };
// }
pushChunkSizeArgument(args, options?.CHUNK_SIZE);
// export enum TimeSeriesBucketTimestamp {
// LOW = '-',
// HIGH = '+',
// MID = '~'
// }
pushLabelsArgument(args, options?.LABELS);
// export interface RangeOptions {
// LATEST?: boolean;
// FILTER_BY_TS?: Array<Timestamp>;
// FILTER_BY_VALUE?: {
// min: number;
// max: number;
// };
// COUNT?: number;
// ALIGN?: Timestamp;
// AGGREGATION?: {
// type: TimeSeriesAggregationType;
// timeBucket: Timestamp;
// BUCKETTIMESTAMP?: TimeSeriesBucketTimestamp;
// EMPTY?: boolean;
// };
// }
return args;
}
// export function pushRangeArguments(
// args: RedisCommandArguments,
// fromTimestamp: Timestamp,
// toTimestamp: Timestamp,
// options?: RangeOptions
// ): RedisCommandArguments {
// args.push(
// transformTimestampArgument(fromTimestamp),
// transformTimestampArgument(toTimestamp)
// );
export type SampleRawReply = [timestamp: number, value: string];
// pushLatestArgument(args, options?.LATEST);
export interface SampleReply {
timestamp: number;
value: number;
}
// if (options?.FILTER_BY_TS) {
// args.push('FILTER_BY_TS');
// for (const ts of options.FILTER_BY_TS) {
// args.push(transformTimestampArgument(ts));
// }
// }
export function transformSampleReply(reply: SampleRawReply): SampleReply {
return {
timestamp: reply[0],
value: Number(reply[1])
};
}
// if (options?.FILTER_BY_VALUE) {
// args.push(
// 'FILTER_BY_VALUE',
// options.FILTER_BY_VALUE.min.toString(),
// options.FILTER_BY_VALUE.max.toString()
// );
// }
export enum TimeSeriesBucketTimestamp {
LOW = '-',
HIGH = '+',
MID = '~'
}
// if (options?.COUNT) {
// args.push(
// 'COUNT',
// options.COUNT.toString()
// );
// }
export interface RangeOptions {
LATEST?: boolean;
FILTER_BY_TS?: Array<Timestamp>;
FILTER_BY_VALUE?: {
min: number;
max: number;
};
COUNT?: number;
ALIGN?: Timestamp;
AGGREGATION?: {
type: TimeSeriesAggregationType;
timeBucket: Timestamp;
BUCKETTIMESTAMP?: TimeSeriesBucketTimestamp;
EMPTY?: boolean;
};
}
// if (options?.ALIGN) {
// args.push(
// 'ALIGN',
// transformTimestampArgument(options.ALIGN)
// );
// }
export function pushRangeArguments(
args: RedisCommandArguments,
fromTimestamp: Timestamp,
toTimestamp: Timestamp,
options?: RangeOptions
): RedisCommandArguments {
args.push(
transformTimestampArgument(fromTimestamp),
transformTimestampArgument(toTimestamp)
);
// if (options?.AGGREGATION) {
// args.push(
// 'AGGREGATION',
// options.AGGREGATION.type,
// transformTimestampArgument(options.AGGREGATION.timeBucket)
// );
pushLatestArgument(args, options?.LATEST);
// if (options.AGGREGATION.BUCKETTIMESTAMP) {
// args.push(
// 'BUCKETTIMESTAMP',
// options.AGGREGATION.BUCKETTIMESTAMP
// );
// }
if (options?.FILTER_BY_TS) {
args.push('FILTER_BY_TS');
for (const ts of options.FILTER_BY_TS) {
args.push(transformTimestampArgument(ts));
}
}
// if (options.AGGREGATION.EMPTY) {
// args.push('EMPTY');
// }
// }
if (options?.FILTER_BY_VALUE) {
args.push(
'FILTER_BY_VALUE',
options.FILTER_BY_VALUE.min.toString(),
options.FILTER_BY_VALUE.max.toString()
);
}
// return args;
// }
if (options?.COUNT) {
args.push(
'COUNT',
options.COUNT.toString()
);
}
// interface MRangeGroupBy {
// label: string;
// reducer: TimeSeriesReducers;
// }
if (options?.ALIGN) {
args.push(
'ALIGN',
transformTimestampArgument(options.ALIGN)
);
}
// export function pushMRangeGroupByArguments(args: RedisCommandArguments, groupBy?: MRangeGroupBy): RedisCommandArguments {
// if (groupBy) {
// args.push(
// 'GROUPBY',
// groupBy.label,
// 'REDUCE',
// groupBy.reducer
// );
// }
if (options?.AGGREGATION) {
args.push(
'AGGREGATION',
options.AGGREGATION.type,
transformTimestampArgument(options.AGGREGATION.timeBucket)
);
// return args;
// }
if (options.AGGREGATION.BUCKETTIMESTAMP) {
args.push(
'BUCKETTIMESTAMP',
options.AGGREGATION.BUCKETTIMESTAMP
);
}
// export type Filter = string | Array<string>;
if (options.AGGREGATION.EMPTY) {
args.push('EMPTY');
}
}
// export function pushFilterArgument(args: RedisCommandArguments, filter: string | Array<string>): RedisCommandArguments {
// args.push('FILTER');
// return pushVariadicArguments(args, filter);
// }
return args;
}
// export interface MRangeOptions extends RangeOptions {
// GROUPBY?: MRangeGroupBy;
// }
interface MRangeGroupBy {
label: string;
reducer: TimeSeriesReducers;
}
// export function pushMRangeArguments(
// args: RedisCommandArguments,
// fromTimestamp: Timestamp,
// toTimestamp: Timestamp,
// filter: Filter,
// options?: MRangeOptions
// ): RedisCommandArguments {
// args = pushRangeArguments(args, fromTimestamp, toTimestamp, options);
// args = pushFilterArgument(args, filter);
// return pushMRangeGroupByArguments(args, options?.GROUPBY);
// }
export function pushMRangeGroupByArguments(args: RedisCommandArguments, groupBy?: MRangeGroupBy): RedisCommandArguments {
if (groupBy) {
args.push(
'GROUPBY',
groupBy.label,
'REDUCE',
groupBy.reducer
);
}
// export type SelectedLabels = string | Array<string>;
return args;
}
// export function pushWithLabelsArgument(args: RedisCommandArguments, selectedLabels?: SelectedLabels): RedisCommandArguments {
// if (!selectedLabels) {
// args.push('WITHLABELS');
// } else {
// args.push('SELECTED_LABELS');
// args = pushVariadicArguments(args, selectedLabels);
// }
export type Filter = string | Array<string>;
// return args;
// }
export function pushFilterArgument(args: RedisCommandArguments, filter: string | Array<string>): RedisCommandArguments {
args.push('FILTER');
return pushVariadicArguments(args, filter);
}
// export interface MRangeWithLabelsOptions extends MRangeOptions {
// SELECTED_LABELS?: SelectedLabels;
// }
export interface MRangeOptions extends RangeOptions {
GROUPBY?: MRangeGroupBy;
}
// export function pushMRangeWithLabelsArguments(
// args: RedisCommandArguments,
// fromTimestamp: Timestamp,
// toTimestamp: Timestamp,
// filter: Filter,
// options?: MRangeWithLabelsOptions
// ): RedisCommandArguments {
// args = pushRangeArguments(args, fromTimestamp, toTimestamp, options);
// args = pushWithLabelsArgument(args, options?.SELECTED_LABELS);
// args = pushFilterArgument(args, filter);
// return pushMRangeGroupByArguments(args, options?.GROUPBY);
// }
export function pushMRangeArguments(
args: RedisCommandArguments,
fromTimestamp: Timestamp,
toTimestamp: Timestamp,
filter: Filter,
options?: MRangeOptions
): RedisCommandArguments {
args = pushRangeArguments(args, fromTimestamp, toTimestamp, options);
args = pushFilterArgument(args, filter);
return pushMRangeGroupByArguments(args, options?.GROUPBY);
}
// export function transformRangeReply(reply: Array<SampleRawReply>): Array<SampleReply> {
// return reply.map(transformSampleReply);
// }
export type SelectedLabels = string | Array<string>;
// type MRangeRawReply = Array<[
// key: string,
// labels: RawLabels,
// samples: Array<SampleRawReply>
// ]>;
export function pushWithLabelsArgument(args: RedisCommandArguments, selectedLabels?: SelectedLabels): RedisCommandArguments {
if (!selectedLabels) {
args.push('WITHLABELS');
} else {
args.push('SELECTED_LABELS');
args = pushVariadicArguments(args, selectedLabels);
}
// interface MRangeReplyItem {
// key: string;
// samples: Array<SampleReply>;
// }
return args;
}
// export function transformMRangeReply(reply: MRangeRawReply): Array<MRangeReplyItem> {
// const args = [];
export interface MRangeWithLabelsOptions extends MRangeOptions {
SELECTED_LABELS?: SelectedLabels;
}
// for (const [key, _, sample] of reply) {
// args.push({
// key,
// samples: sample.map(transformSampleReply)
// });
// }
export function pushMRangeWithLabelsArguments(
args: RedisCommandArguments,
fromTimestamp: Timestamp,
toTimestamp: Timestamp,
filter: Filter,
options?: MRangeWithLabelsOptions
): RedisCommandArguments {
args = pushRangeArguments(args, fromTimestamp, toTimestamp, options);
args = pushWithLabelsArgument(args, options?.SELECTED_LABELS);
args = pushFilterArgument(args, filter);
return pushMRangeGroupByArguments(args, options?.GROUPBY);
}
// return args;
// }
// export interface MRangeWithLabelsReplyItem extends MRangeReplyItem {
// labels: Labels;
// }
export function transformRangeReply(reply: Array<SampleRawReply>): Array<SampleReply> {
return reply.map(transformSampleReply);
}
// export function transformMRangeWithLabelsReply(reply: MRangeRawReply): Array<MRangeWithLabelsReplyItem> {
// const args = [];
type MRangeRawReply = Array<[
key: string,
labels: RawLabels,
samples: Array<SampleRawReply>
]>;
// for (const [key, labels, samples] of reply) {
// args.push({
// key,
// labels: transformLablesReply(labels),
// samples: samples.map(transformSampleReply)
// });
// }
interface MRangeReplyItem {
key: string;
samples: Array<SampleReply>;
}
export function transformMRangeReply(reply: MRangeRawReply): Array<MRangeReplyItem> {
const args = [];
for (const [key, _, sample] of reply) {
args.push({
key,
samples: sample.map(transformSampleReply)
});
}
return args;
}
export interface MRangeWithLabelsReplyItem extends MRangeReplyItem {
labels: Labels;
}
export function transformMRangeWithLabelsReply(reply: MRangeRawReply): Array<MRangeWithLabelsReplyItem> {
const args = [];
for (const [key, labels, samples] of reply) {
args.push({
key,
labels: transformLablesReply(labels),
samples: samples.map(transformSampleReply)
});
}
return args;
}
export function pushLatestArgument(args: RedisCommandArguments, latest?: boolean): RedisCommandArguments {
if (latest) {
args.push('LATEST');
}
return args;
}
// return args;
// }