You've already forked node-redis
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:
@@ -1,72 +1,72 @@
|
|||||||
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', () => {
|
|
||||||
assert.deepEqual(
|
|
||||||
transformArguments('key', {
|
|
||||||
RETENTION: 1
|
|
||||||
}),
|
|
||||||
['TS.ALTER', 'key', 'RETENTION', '1']
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('with CHUNK_SIZE', () => {
|
|
||||||
assert.deepEqual(
|
|
||||||
transformArguments('key', {
|
|
||||||
CHUNK_SIZE: 1
|
|
||||||
}),
|
|
||||||
['TS.ALTER', 'key', 'CHUNK_SIZE', '1']
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('with DUPLICATE_POLICY', () => {
|
|
||||||
assert.deepEqual(
|
|
||||||
transformArguments('key', {
|
|
||||||
DUPLICATE_POLICY: TimeSeriesDuplicatePolicies.BLOCK
|
|
||||||
}),
|
|
||||||
['TS.ALTER', 'key', 'DUPLICATE_POLICY', 'BLOCK']
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('with LABELS', () => {
|
|
||||||
assert.deepEqual(
|
|
||||||
transformArguments('key', {
|
|
||||||
LABELS: { label: 'value' }
|
|
||||||
}),
|
|
||||||
['TS.ALTER', 'key', 'LABELS', 'label', 'value']
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('with RETENTION, CHUNK_SIZE, DUPLICATE_POLICY, LABELS', () => {
|
|
||||||
assert.deepEqual(
|
|
||||||
transformArguments('key', {
|
|
||||||
RETENTION: 1,
|
|
||||||
CHUNK_SIZE: 1,
|
|
||||||
DUPLICATE_POLICY: TimeSeriesDuplicatePolicies.BLOCK,
|
|
||||||
LABELS: { label: 'value' }
|
|
||||||
}),
|
|
||||||
['TS.ALTER', 'key', 'RETENTION', '1', 'CHUNK_SIZE', '1', 'DUPLICATE_POLICY', 'BLOCK', 'LABELS', 'label', 'value']
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
testUtils.testWithClient('client.ts.alter', async client => {
|
it('with RETENTION', () => {
|
||||||
await client.ts.create('key');
|
assert.deepEqual(
|
||||||
|
ALTER.transformArguments('key', {
|
||||||
|
RETENTION: 1
|
||||||
|
}),
|
||||||
|
['TS.ALTER', 'key', 'RETENTION', '1']
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
assert.equal(
|
it('with CHUNK_SIZE', () => {
|
||||||
await client.ts.alter('key', { RETENTION: 1 }),
|
assert.deepEqual(
|
||||||
'OK'
|
ALTER.transformArguments('key', {
|
||||||
);
|
CHUNK_SIZE: 1
|
||||||
}, GLOBAL.SERVERS.OPEN);
|
}),
|
||||||
|
['TS.ALTER', 'key', 'CHUNK_SIZE', '1']
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('with DUPLICATE_POLICY', () => {
|
||||||
|
assert.deepEqual(
|
||||||
|
ALTER.transformArguments('key', {
|
||||||
|
DUPLICATE_POLICY: TimeSeriesDuplicatePolicies.BLOCK
|
||||||
|
}),
|
||||||
|
['TS.ALTER', 'key', 'DUPLICATE_POLICY', 'BLOCK']
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('with LABELS', () => {
|
||||||
|
assert.deepEqual(
|
||||||
|
ALTER.transformArguments('key', {
|
||||||
|
LABELS: { label: 'value' }
|
||||||
|
}),
|
||||||
|
['TS.ALTER', 'key', 'LABELS', 'label', 'value']
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('with RETENTION, CHUNK_SIZE, DUPLICATE_POLICY, LABELS', () => {
|
||||||
|
assert.deepEqual(
|
||||||
|
ALTER.transformArguments('key', {
|
||||||
|
RETENTION: 1,
|
||||||
|
CHUNK_SIZE: 1,
|
||||||
|
DUPLICATE_POLICY: TimeSeriesDuplicatePolicies.BLOCK,
|
||||||
|
LABELS: { label: 'value' }
|
||||||
|
}),
|
||||||
|
['TS.ALTER', 'key', 'RETENTION', '1', 'CHUNK_SIZE', '1', 'DUPLICATE_POLICY', 'BLOCK', 'LABELS', 'label', 'value']
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
testUtils.testWithClient('client.ts.alter', async client => {
|
||||||
|
await client.ts.create('key');
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
await client.ts.alter('key', { RETENTION: 1 }),
|
||||||
|
'OK'
|
||||||
|
);
|
||||||
|
}, GLOBAL.SERVERS.OPEN);
|
||||||
});
|
});
|
||||||
|
@@ -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 {
|
||||||
|
RETENTION?: number;
|
||||||
interface AlterOptions {
|
CHUNK_SIZE?: number;
|
||||||
RETENTION?: number;
|
DUPLICATE_POLICY?: TimeSeriesDuplicatePolicies;
|
||||||
CHUNK_SIZE?: number;
|
LABELS?: Labels;
|
||||||
DUPLICATE_POLICY?: TimeSeriesDuplicatePolicies;
|
|
||||||
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;
|
||||||
|
Reference in New Issue
Block a user