You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-03 04:01:40 +03:00
* [CAE-686] Added hash field expiration commands * [CAE-686] Improve HSETEX return type * [CAE-686] Minor pushTuples change, renamed HSETEX test * [CAE-686] Changed hsetex function signature for better consistency with other commands * [CAE-686] Fixed hsetex test * [CAE-686] Bumped docker version to 8.0-M05-pre, enabled and fixed tests
78 lines
3.1 KiB
TypeScript
78 lines
3.1 KiB
TypeScript
import { strict as assert } from 'node:assert';
|
|
import testUtils,{ GLOBAL } from '../test-utils';
|
|
import { BasicCommandParser } from '../client/parser';
|
|
import HGETEX from './HGETEX';
|
|
import { setTimeout } from 'timers/promises';
|
|
|
|
describe('HGETEX parseCommand', () => {
|
|
it('hGetEx parseCommand base', () => {
|
|
const parser = new BasicCommandParser;
|
|
HGETEX.parseCommand(parser, 'key', 'field');
|
|
assert.deepEqual(parser.redisArgs, ['HGETEX', 'key', 'FIELDS', '1', 'field']);
|
|
});
|
|
|
|
it('hGetEx parseCommand expiration PERSIST string', () => {
|
|
const parser = new BasicCommandParser;
|
|
HGETEX.parseCommand(parser, 'key', 'field', {expiration: 'PERSIST'});
|
|
assert.deepEqual(parser.redisArgs, ['HGETEX', 'key', 'PERSIST', 'FIELDS', '1', 'field']);
|
|
});
|
|
|
|
it('hGetEx parseCommand expiration PERSIST obj', () => {
|
|
const parser = new BasicCommandParser;
|
|
HGETEX.parseCommand(parser, 'key', 'field', {expiration: {type: 'PERSIST'}});
|
|
assert.deepEqual(parser.redisArgs, ['HGETEX', 'key', 'PERSIST', 'FIELDS', '1', 'field']);
|
|
});
|
|
|
|
it('hGetEx parseCommand expiration EX obj', () => {
|
|
const parser = new BasicCommandParser;
|
|
HGETEX.parseCommand(parser, 'key', 'field', {expiration: {type: 'EX', value: 1000}});
|
|
assert.deepEqual(parser.redisArgs, ['HGETEX', 'key', 'EX', '1000', 'FIELDS', '1', 'field']);
|
|
});
|
|
|
|
it('hGetEx parseCommand expiration EXAT obj variadic', () => {
|
|
const parser = new BasicCommandParser;
|
|
HGETEX.parseCommand(parser, 'key', ['field1', 'field2'], {expiration: {type: 'EXAT', value: 1000}});
|
|
assert.deepEqual(parser.redisArgs, ['HGETEX', 'key', 'EXAT', '1000', 'FIELDS', '2', 'field1', 'field2']);
|
|
});
|
|
});
|
|
|
|
|
|
describe('HGETEX call', () => {
|
|
testUtils.testWithClientIfVersionWithinRange([[8], 'LATEST'], 'hGetEx empty single field', async client => {
|
|
assert.deepEqual(
|
|
await client.hGetEx('key', 'field1', {expiration: 'PERSIST'}),
|
|
[null]
|
|
);
|
|
}, GLOBAL.SERVERS.OPEN);
|
|
|
|
testUtils.testWithClientIfVersionWithinRange([[8], 'LATEST'], 'hGetEx empty multiple fields', async client => {
|
|
assert.deepEqual(
|
|
await client.hGetEx('key', ['field1', 'field2'], {expiration: 'PERSIST'}),
|
|
[null, null]
|
|
);
|
|
}, GLOBAL.SERVERS.OPEN);
|
|
|
|
testUtils.testWithClientIfVersionWithinRange([[8], 'LATEST'], 'hGetEx set expiry', async client => {
|
|
await client.hSet('key', 'field', 'value')
|
|
assert.deepEqual(
|
|
await client.hGetEx('key', 'field', {expiration: {type: 'PX', value: 50}}),
|
|
['value']
|
|
);
|
|
await setTimeout(100)
|
|
assert.deepEqual(
|
|
await client.hGet('key', 'field'),
|
|
null
|
|
);
|
|
}, GLOBAL.SERVERS.OPEN);
|
|
|
|
testUtils.testWithClientIfVersionWithinRange([[8], 'LATEST'], 'gGetEx set expiry PERSIST', async client => {
|
|
await client.hSet('key', 'field', 'value')
|
|
await client.hGetEx('key', 'field', {expiration: {type: 'PX', value: 50}})
|
|
await client.hGetEx('key', 'field', {expiration: 'PERSIST'})
|
|
await setTimeout(100)
|
|
assert.deepEqual(
|
|
await client.hGet('key', 'field'),
|
|
'value'
|
|
)
|
|
}, GLOBAL.SERVERS.OPEN);
|
|
}); |