1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +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 { TimeSeriesDuplicatePolicies, TimeSeriesEncoding } from '.';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './CREATE';
import CREATE from './CREATE';
describe('CREATE', () => {
describe('transformArguments', () => {
it('without options', () => {
assert.deepEqual(
transformArguments('key'),
CREATE.transformArguments('key'),
['TS.CREATE', 'key']
);
});
it('with RETENTION', () => {
assert.deepEqual(
transformArguments('key', {
CREATE.transformArguments('key', {
RETENTION: 1
}),
['TS.CREATE', 'key', 'RETENTION', '1']
@@ -23,7 +23,7 @@ describe('CREATE', () => {
it('with ENCODING', () => {
assert.deepEqual(
transformArguments('key', {
CREATE.transformArguments('key', {
ENCODING: TimeSeriesEncoding.UNCOMPRESSED
}),
['TS.CREATE', 'key', 'ENCODING', 'UNCOMPRESSED']
@@ -32,7 +32,7 @@ describe('CREATE', () => {
it('with CHUNK_SIZE', () => {
assert.deepEqual(
transformArguments('key', {
CREATE.transformArguments('key', {
CHUNK_SIZE: 1
}),
['TS.CREATE', 'key', 'CHUNK_SIZE', '1']
@@ -41,7 +41,7 @@ describe('CREATE', () => {
it('with DUPLICATE_POLICY', () => {
assert.deepEqual(
transformArguments('key', {
CREATE.transformArguments('key', {
DUPLICATE_POLICY: TimeSeriesDuplicatePolicies.BLOCK
}),
['TS.CREATE', 'key', 'DUPLICATE_POLICY', 'BLOCK']
@@ -50,7 +50,7 @@ describe('CREATE', () => {
it('with LABELS', () => {
assert.deepEqual(
transformArguments('key', {
CREATE.transformArguments('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', () => {
assert.deepEqual(
transformArguments('key', {
CREATE.transformArguments('key', {
RETENTION: 1,
ENCODING: TimeSeriesEncoding.UNCOMPRESSED,
CHUNK_SIZE: 1,

View File

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