1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-09 00:22:08 +03:00

fix CREATERULE

This commit is contained in:
dovi
2023-07-05 14:41:55 -04:00
parent a9ec9e2b9b
commit 60d0433810
2 changed files with 43 additions and 41 deletions

View File

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

View File

@@ -1,28 +1,30 @@
import { TimeSeriesAggregationType } from '.'; import { TimeSeriesAggregationType } from '.';
import { RedisArgument, SimpleStringReply, Command } from '@redis/client/dist/lib/RESP/types';
export const FIRST_KEY_INDEX = 1; export default {
FIRST_KEY_INDEX: 1,
export function transformArguments( IS_READ_ONLY: false,
sourceKey: string, transformArguments(
destinationKey: string, sourceKey: RedisArgument,
destinationKey: RedisArgument,
aggregationType: TimeSeriesAggregationType, aggregationType: TimeSeriesAggregationType,
bucketDuration: number, bucketDuration: number,
alignTimestamp?: number alignTimestamp?: number
): Array<string> { ) {
const args = [ const args = [
'TS.CREATERULE', 'TS.CREATERULE',
sourceKey, sourceKey,
destinationKey, destinationKey,
'AGGREGATION', 'AGGREGATION',
aggregationType, aggregationType,
bucketDuration.toString() bucketDuration.toString()
]; ];
if (alignTimestamp) { if (alignTimestamp) {
args.push(alignTimestamp.toString()); args.push(alignTimestamp.toString());
} }
return args; return args;
} },
transformReply: undefined as unknown as () => SimpleStringReply<'OK'>
export declare function transformReply(): 'OK'; } as const satisfies Command;