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

fix CREATE

This commit is contained in:
dovi
2023-07-05 14:40:49 -04:00
parent 7f562bce43
commit cac51e5edb
2 changed files with 94 additions and 92 deletions

View File

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

View File

@@ -8,10 +8,9 @@ import {
pushLabelsArgument, pushLabelsArgument,
pushDuplicatePolicy pushDuplicatePolicy
} from '.'; } from '.';
import { RedisArgument, SimpleStringReply, Command } from '@redis/client/dist/lib/RESP/types';
export const FIRST_KEY_INDEX = 1; export interface TsCreateOptions {
interface CreateOptions {
RETENTION?: number; RETENTION?: number;
ENCODING?: TimeSeriesEncoding; ENCODING?: TimeSeriesEncoding;
CHUNK_SIZE?: number; CHUNK_SIZE?: number;
@@ -19,7 +18,10 @@ interface CreateOptions {
LABELS?: Labels; LABELS?: Labels;
} }
export function transformArguments(key: string, options?: CreateOptions): Array<string> { export default {
FIRST_KEY_INDEX: 1,
IS_READ_ONLY: false,
transformArguments(key: RedisArgument, options?: TsCreateOptions) {
const args = ['TS.CREATE', key]; const args = ['TS.CREATE', key];
pushRetentionArgument(args, options?.RETENTION); pushRetentionArgument(args, options?.RETENTION);
@@ -33,6 +35,6 @@ export function transformArguments(key: string, options?: CreateOptions): Array<
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;