1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-04 15:02:09 +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,96 +1,122 @@
import { strict as assert } from 'assert';
import { strict as assert } from 'node:assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './GETEX';
import GETEX from './GETEX';
describe('GETEX', () => {
testUtils.isVersionGreaterThanHook([6, 2]);
testUtils.isVersionGreaterThanHook([6, 2]);
describe('transformArguments', () => {
it('EX', () => {
assert.deepEqual(
transformArguments('key', {
EX: 1
}),
['GETEX', 'key', 'EX', '1']
);
});
it('PX', () => {
assert.deepEqual(
transformArguments('key', {
PX: 1
}),
['GETEX', 'key', 'PX', '1']
);
});
describe('EXAT', () => {
it('number', () => {
assert.deepEqual(
transformArguments('key', {
EXAT: 1
}),
['GETEX', 'key', 'EXAT', '1']
);
});
it('date', () => {
const d = new Date();
assert.deepEqual(
transformArguments('key', {
EXAT: d
}),
['GETEX', 'key', 'EXAT', Math.floor(d.getTime() / 1000).toString()]
);
});
});
describe('PXAT', () => {
it('number', () => {
assert.deepEqual(
transformArguments('key', {
PXAT: 1
}),
['GETEX', 'key', 'PXAT', '1']
);
});
it('date', () => {
const d = new Date();
assert.deepEqual(
transformArguments('key', {
PXAT: d
}),
['GETEX', 'key', 'PXAT', d.getTime().toString()]
);
});
});
it('PERSIST', () => {
assert.deepEqual(
transformArguments('key', {
PERSIST: true
}),
['GETEX', 'key', 'PERSIST']
);
});
describe('transformArguments', () => {
it('EX | PX', () => {
assert.deepEqual(
GETEX.transformArguments('key', {
type: 'EX',
value: 1
}),
['GETEX', 'key', 'EX', '1']
);
});
testUtils.testWithClient('client.getEx', async client => {
assert.equal(
await client.getEx('key', {
PERSIST: true
}),
null
);
}, GLOBAL.SERVERS.OPEN);
it('EX (backwards compatibility)', () => {
assert.deepEqual(
GETEX.transformArguments('key', {
EX: 1
}),
['GETEX', 'key', 'EX', '1']
);
});
testUtils.testWithCluster('cluster.getEx', async cluster => {
assert.equal(
await cluster.getEx('key', {
PERSIST: true
}),
null
it('PX (backwards compatibility)', () => {
assert.deepEqual(
GETEX.transformArguments('key', {
PX: 1
}),
['GETEX', 'key', 'PX', '1']
);
});
describe('EXAT | PXAT', () => {
it('number', () => {
assert.deepEqual(
GETEX.transformArguments('key', {
type: 'EXAT',
value: 1
}),
['GETEX', 'key', 'EXAT', '1']
);
}, GLOBAL.CLUSTERS.OPEN);
});
it('date', () => {
const d = new Date();
assert.deepEqual(
GETEX.transformArguments('key', {
EXAT: d
}),
['GETEX', 'key', 'EXAT', Math.floor(d.getTime() / 1000).toString()]
);
});
});
describe('EXAT (backwards compatibility)', () => {
it('number', () => {
assert.deepEqual(
GETEX.transformArguments('key', {
EXAT: 1
}),
['GETEX', 'key', 'EXAT', '1']
);
});
it('date', () => {
const d = new Date();
assert.deepEqual(
GETEX.transformArguments('key', {
EXAT: d
}),
['GETEX', 'key', 'EXAT', Math.floor(d.getTime() / 1000).toString()]
);
});
});
describe('PXAT (backwards compatibility)', () => {
it('number', () => {
assert.deepEqual(
GETEX.transformArguments('key', {
PXAT: 1
}),
['GETEX', 'key', 'PXAT', '1']
);
});
it('date', () => {
const d = new Date();
assert.deepEqual(
GETEX.transformArguments('key', {
PXAT: d
}),
['GETEX', 'key', 'PXAT', d.getTime().toString()]
);
});
});
it('PERSIST (backwards compatibility)', () => {
assert.deepEqual(
GETEX.transformArguments('key', {
PERSIST: true
}),
['GETEX', 'key', 'PERSIST']
);
});
});
testUtils.testAll('getEx', async client => {
assert.equal(
await client.getEx('key', {
type: 'PERSIST'
}),
null
);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
});