1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00

V5 bringing RESP3, Sentinel and TypeMapping to node-redis

RESP3 Support
   - Some commands responses in RESP3 aren't stable yet and therefore return an "untyped" ReplyUnion.
 
Sentinel

TypeMapping

Correctly types Multi commands

Note: some API changes to be further documented in v4-to-v5.md
This commit is contained in:
Shaya Potter
2024-10-15 17:46:52 +03:00
committed by GitHub
parent 2fc79bdfb3
commit b2d35c5286
1174 changed files with 45931 additions and 36274 deletions

View File

@@ -1,90 +1,93 @@
import { strict as assert } from 'assert';
import { TimeSeriesDuplicatePolicies, TimeSeriesEncoding } from '.';
import { strict as assert } from 'node:assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './CREATE';
import CREATE from './CREATE';
import { TIME_SERIES_ENCODING, TIME_SERIES_DUPLICATE_POLICIES } from '.';
describe('CREATE', () => {
describe('transformArguments', () => {
it('without options', () => {
assert.deepEqual(
transformArguments('key'),
['TS.CREATE', 'key']
);
});
it('with RETENTION', () => {
assert.deepEqual(
transformArguments('key', {
RETENTION: 1
}),
['TS.CREATE', 'key', 'RETENTION', '1']
);
});
it('with ENCODING', () => {
assert.deepEqual(
transformArguments('key', {
ENCODING: TimeSeriesEncoding.UNCOMPRESSED
}),
['TS.CREATE', 'key', 'ENCODING', 'UNCOMPRESSED']
);
});
it('with CHUNK_SIZE', () => {
assert.deepEqual(
transformArguments('key', {
CHUNK_SIZE: 1
}),
['TS.CREATE', 'key', 'CHUNK_SIZE', '1']
);
});
it('with DUPLICATE_POLICY', () => {
assert.deepEqual(
transformArguments('key', {
DUPLICATE_POLICY: TimeSeriesDuplicatePolicies.BLOCK
}),
['TS.CREATE', 'key', 'DUPLICATE_POLICY', 'BLOCK']
);
});
it('with LABELS', () => {
assert.deepEqual(
transformArguments('key', {
LABELS: { label: 'value' }
}),
['TS.CREATE', 'key', 'LABELS', 'label', 'value']
);
});
it('with IGNORE with MAX_TIME_DIFF', () => {
assert.deepEqual(
transformArguments('key', {
IGNORE: { MAX_TIME_DIFF: 1, MAX_VAL_DIFF: 1}
}),
['TS.CREATE', 'key', 'IGNORE', '1', '1']
)
});
it('with RETENTION, ENCODING, CHUNK_SIZE, DUPLICATE_POLICY, LABELS, IGNORE', () => {
assert.deepEqual(
transformArguments('key', {
RETENTION: 1,
ENCODING: TimeSeriesEncoding.UNCOMPRESSED,
CHUNK_SIZE: 1,
DUPLICATE_POLICY: TimeSeriesDuplicatePolicies.BLOCK,
LABELS: { label: 'value' },
IGNORE: { MAX_TIME_DIFF: 1, MAX_VAL_DIFF: 1}
}),
['TS.CREATE', 'key', 'RETENTION', '1', 'ENCODING', 'UNCOMPRESSED', 'CHUNK_SIZE', '1', 'DUPLICATE_POLICY', 'BLOCK', 'LABELS', 'label', 'value', 'IGNORE', '1', '1']
);
});
describe('TS.CREATE', () => {
describe('transformArguments', () => {
it('without options', () => {
assert.deepEqual(
CREATE.transformArguments('key'),
['TS.CREATE', 'key']
);
});
testUtils.testWithClient('client.ts.create', async client => {
assert.equal(
await client.ts.create('key'),
'OK'
);
}, GLOBAL.SERVERS.OPEN);
it('with RETENTION', () => {
assert.deepEqual(
CREATE.transformArguments('key', {
RETENTION: 1
}),
['TS.CREATE', 'key', 'RETENTION', '1']
);
});
it('with ENCODING', () => {
assert.deepEqual(
CREATE.transformArguments('key', {
ENCODING: TIME_SERIES_ENCODING.UNCOMPRESSED
}),
['TS.CREATE', 'key', 'ENCODING', 'UNCOMPRESSED']
);
});
it('with CHUNK_SIZE', () => {
assert.deepEqual(
CREATE.transformArguments('key', {
CHUNK_SIZE: 1
}),
['TS.CREATE', 'key', 'CHUNK_SIZE', '1']
);
});
it('with DUPLICATE_POLICY', () => {
assert.deepEqual(
CREATE.transformArguments('key', {
DUPLICATE_POLICY: TIME_SERIES_DUPLICATE_POLICIES.BLOCK
}),
['TS.CREATE', 'key', 'DUPLICATE_POLICY', 'BLOCK']
);
});
it('with LABELS', () => {
assert.deepEqual(
CREATE.transformArguments('key', {
LABELS: { label: 'value' }
}),
['TS.CREATE', 'key', 'LABELS', 'label', 'value']
);
});
it('with IGNORE with MAX_TIME_DIFF', () => {
assert.deepEqual(
CREATE.transformArguments('key', {
IGNORE: {
maxTimeDiff: 1,
maxValDiff: 1
}
}),
['TS.CREATE', 'key', 'IGNORE', '1', '1']
)
});
it('with RETENTION, ENCODING, CHUNK_SIZE, DUPLICATE_POLICY, LABELS, IGNORE', () => {
assert.deepEqual(
CREATE.transformArguments('key', {
RETENTION: 1,
ENCODING: TIME_SERIES_ENCODING.UNCOMPRESSED,
CHUNK_SIZE: 1,
DUPLICATE_POLICY: TIME_SERIES_DUPLICATE_POLICIES.BLOCK,
LABELS: { label: 'value' },
IGNORE: { maxTimeDiff: 1, maxValDiff: 1}
}),
['TS.CREATE', 'key', 'RETENTION', '1', 'ENCODING', 'UNCOMPRESSED', 'CHUNK_SIZE', '1', 'DUPLICATE_POLICY', 'BLOCK', 'LABELS', 'label', 'value', 'IGNORE', '1', '1']
);
});
});
testUtils.testWithClient('client.ts.create', async client => {
assert.equal(
await client.ts.create('key'),
'OK'
);
}, GLOBAL.SERVERS.OPEN);
});