You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
fix CREATERULE
This commit is contained in:
@@ -1,34 +1,34 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import { TimeSeriesAggregationType } from '.';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import { transformArguments } from './CREATERULE';
|
||||
import CREATERULE from './CREATERULE';
|
||||
|
||||
describe('CREATERULE', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('without options', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('source', 'destination', TimeSeriesAggregationType.AVERAGE, 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']
|
||||
);
|
||||
});
|
||||
describe('transformArguments', () => {
|
||||
it('without options', () => {
|
||||
assert.deepEqual(
|
||||
CREATERULE.transformArguments('source', 'destination', TimeSeriesAggregationType.AVERAGE, 1),
|
||||
['TS.CREATERULE', 'source', 'destination', 'AGGREGATION', 'AVG', '1']
|
||||
);
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.ts.createRule', async client => {
|
||||
await Promise.all([
|
||||
client.ts.create('source'),
|
||||
client.ts.create('destination')
|
||||
]);
|
||||
it('with alignTimestamp', () => {
|
||||
assert.deepEqual(
|
||||
CREATERULE.transformArguments('source', 'destination', TimeSeriesAggregationType.AVERAGE, 1, 1),
|
||||
['TS.CREATERULE', 'source', 'destination', 'AGGREGATION', 'AVG', '1', '1']
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
assert.equal(
|
||||
await client.ts.createRule('source', 'destination', TimeSeriesAggregationType.AVERAGE, 1),
|
||||
'OK'
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
testUtils.testWithClient('client.ts.createRule', async client => {
|
||||
await Promise.all([
|
||||
client.ts.create('source'),
|
||||
client.ts.create('destination')
|
||||
]);
|
||||
|
||||
assert.equal(
|
||||
await client.ts.createRule('source', 'destination', TimeSeriesAggregationType.AVERAGE, 1),
|
||||
'OK'
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
});
|
||||
|
@@ -1,28 +1,30 @@
|
||||
import { TimeSeriesAggregationType } from '.';
|
||||
import { RedisArgument, SimpleStringReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
export function transformArguments(
|
||||
sourceKey: string,
|
||||
destinationKey: string,
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: false,
|
||||
transformArguments(
|
||||
sourceKey: RedisArgument,
|
||||
destinationKey: RedisArgument,
|
||||
aggregationType: TimeSeriesAggregationType,
|
||||
bucketDuration: number,
|
||||
alignTimestamp?: number
|
||||
): Array<string> {
|
||||
) {
|
||||
const args = [
|
||||
'TS.CREATERULE',
|
||||
sourceKey,
|
||||
destinationKey,
|
||||
'AGGREGATION',
|
||||
aggregationType,
|
||||
bucketDuration.toString()
|
||||
'TS.CREATERULE',
|
||||
sourceKey,
|
||||
destinationKey,
|
||||
'AGGREGATION',
|
||||
aggregationType,
|
||||
bucketDuration.toString()
|
||||
];
|
||||
|
||||
if (alignTimestamp) {
|
||||
args.push(alignTimestamp.toString());
|
||||
args.push(alignTimestamp.toString());
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
export declare function transformReply(): 'OK';
|
||||
},
|
||||
transformReply: undefined as unknown as () => SimpleStringReply<'OK'>
|
||||
} as const satisfies Command;
|
||||
|
Reference in New Issue
Block a user