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

fix ALTER

This commit is contained in:
dovi
2023-07-05 14:18:03 -04:00
parent 935b9cbb60
commit 59e2e6d626
2 changed files with 77 additions and 75 deletions

View File

@@ -1,20 +1,20 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import { TimeSeriesDuplicatePolicies } from '.'; import { TimeSeriesDuplicatePolicies } from '.';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './ALTER'; import ALTER from './ALTER';
describe('ALTER', () => { describe('TS.ALTER', () => {
describe('transformArguments', () => { describe('transformArguments', () => {
it('without options', () => { it('without options', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key'), ALTER.transformArguments('key'),
['TS.ALTER', 'key'] ['TS.ALTER', 'key']
); );
}); });
it('with RETENTION', () => { it('with RETENTION', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key', { ALTER.transformArguments('key', {
RETENTION: 1 RETENTION: 1
}), }),
['TS.ALTER', 'key', 'RETENTION', '1'] ['TS.ALTER', 'key', 'RETENTION', '1']
@@ -23,7 +23,7 @@ describe('ALTER', () => {
it('with CHUNK_SIZE', () => { it('with CHUNK_SIZE', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key', { ALTER.transformArguments('key', {
CHUNK_SIZE: 1 CHUNK_SIZE: 1
}), }),
['TS.ALTER', 'key', 'CHUNK_SIZE', '1'] ['TS.ALTER', 'key', 'CHUNK_SIZE', '1']
@@ -32,7 +32,7 @@ describe('ALTER', () => {
it('with DUPLICATE_POLICY', () => { it('with DUPLICATE_POLICY', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key', { ALTER.transformArguments('key', {
DUPLICATE_POLICY: TimeSeriesDuplicatePolicies.BLOCK DUPLICATE_POLICY: TimeSeriesDuplicatePolicies.BLOCK
}), }),
['TS.ALTER', 'key', 'DUPLICATE_POLICY', 'BLOCK'] ['TS.ALTER', 'key', 'DUPLICATE_POLICY', 'BLOCK']
@@ -41,7 +41,7 @@ describe('ALTER', () => {
it('with LABELS', () => { it('with LABELS', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key', { ALTER.transformArguments('key', {
LABELS: { label: 'value' } LABELS: { label: 'value' }
}), }),
['TS.ALTER', 'key', 'LABELS', 'label', 'value'] ['TS.ALTER', 'key', 'LABELS', 'label', 'value']
@@ -50,7 +50,7 @@ describe('ALTER', () => {
it('with RETENTION, CHUNK_SIZE, DUPLICATE_POLICY, LABELS', () => { it('with RETENTION, CHUNK_SIZE, DUPLICATE_POLICY, LABELS', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key', { ALTER.transformArguments('key', {
RETENTION: 1, RETENTION: 1,
CHUNK_SIZE: 1, CHUNK_SIZE: 1,
DUPLICATE_POLICY: TimeSeriesDuplicatePolicies.BLOCK, DUPLICATE_POLICY: TimeSeriesDuplicatePolicies.BLOCK,

View File

@@ -1,15 +1,17 @@
import { pushRetentionArgument, Labels, pushLabelsArgument, TimeSeriesDuplicatePolicies, pushChunkSizeArgument, pushDuplicatePolicy } from '.'; import { pushRetentionArgument, Labels, pushLabelsArgument, TimeSeriesDuplicatePolicies, pushChunkSizeArgument, pushDuplicatePolicy } from '.';
import { RedisArgument, SimpleStringReply, Command } from '@redis/client/dist/lib/RESP/types';
export const FIRST_KEY_INDEX = 1; export interface TsAlterOptions {
interface AlterOptions {
RETENTION?: number; RETENTION?: number;
CHUNK_SIZE?: number; CHUNK_SIZE?: number;
DUPLICATE_POLICY?: TimeSeriesDuplicatePolicies; DUPLICATE_POLICY?: TimeSeriesDuplicatePolicies;
LABELS?: Labels; LABELS?: Labels;
} }
export function transformArguments(key: string, options?: AlterOptions): Array<string> { export default {
FIRST_KEY_INDEX: 1,
IS_READ_ONLY: false,
transformArguments(key: RedisArgument, options?: TsAlterOptions) {
const args = ['TS.ALTER', key]; const args = ['TS.ALTER', key];
pushRetentionArgument(args, options?.RETENTION); pushRetentionArgument(args, options?.RETENTION);
@@ -21,6 +23,6 @@ export function transformArguments(key: string, options?: AlterOptions): Array<s
pushLabelsArgument(args, options?.LABELS); pushLabelsArgument(args, options?.LABELS);
return args; return args;
} },
transformReply: undefined as unknown as () => SimpleStringReply<'OK'>
export declare function transformReply(): 'OK'; } as const satisfies Command;