You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
feat(hash field expiration): Added hash field expiration commands (#2907)
* [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
This commit is contained in:
98
packages/client/lib/commands/HSETEX.spec.ts
Normal file
98
packages/client/lib/commands/HSETEX.spec.ts
Normal file
@@ -0,0 +1,98 @@
|
||||
import { strict as assert } from 'node:assert';
|
||||
import testUtils,{ GLOBAL } from '../test-utils';
|
||||
import { BasicCommandParser } from '../client/parser';
|
||||
import HSETEX from './HSETEX';
|
||||
|
||||
describe('HSETEX parseCommand', () => {
|
||||
it('hSetEx parseCommand base', () => {
|
||||
const parser = new BasicCommandParser;
|
||||
HSETEX.parseCommand(parser, 'key', ['field', 'value']);
|
||||
assert.deepEqual(parser.redisArgs, ['HSETEX', 'key', 'FIELDS', '1', 'field', 'value']);
|
||||
});
|
||||
|
||||
it('hSetEx parseCommand base empty obj', () => {
|
||||
const parser = new BasicCommandParser;
|
||||
assert.throws(() => {HSETEX.parseCommand(parser, 'key', {})});
|
||||
});
|
||||
|
||||
it('hSetEx parseCommand base one key obj', () => {
|
||||
const parser = new BasicCommandParser;
|
||||
HSETEX.parseCommand(parser, 'key', {'k': 'v'});
|
||||
assert.deepEqual(parser.redisArgs, ['HSETEX', 'key', 'FIELDS', '1', 'k', 'v']);
|
||||
});
|
||||
|
||||
it('hSetEx parseCommand array', () => {
|
||||
const parser = new BasicCommandParser;
|
||||
HSETEX.parseCommand(parser, 'key', ['field1', 'value1', 'field2', 'value2']);
|
||||
assert.deepEqual(parser.redisArgs, ['HSETEX', 'key', 'FIELDS', '2', 'field1', 'value1', 'field2', 'value2']);
|
||||
});
|
||||
|
||||
it('hSetEx parseCommand array invalid args, throws an error', () => {
|
||||
const parser = new BasicCommandParser;
|
||||
assert.throws(() => {HSETEX.parseCommand(parser, 'key', ['field1', 'value1', 'field2'])});
|
||||
});
|
||||
|
||||
it('hSetEx parseCommand array in array', () => {
|
||||
const parser1 = new BasicCommandParser;
|
||||
HSETEX.parseCommand(parser1, 'key', [['field1', 'value1'], ['field2', 'value2']]);
|
||||
assert.deepEqual(parser1.redisArgs, ['HSETEX', 'key', 'FIELDS', '2', 'field1', 'value1', 'field2', 'value2']);
|
||||
|
||||
const parser2 = new BasicCommandParser;
|
||||
HSETEX.parseCommand(parser2, 'key', [['field1', 'value1'], ['field2', 'value2'], ['field3', 'value3']]);
|
||||
assert.deepEqual(parser2.redisArgs, ['HSETEX', 'key', 'FIELDS', '3', 'field1', 'value1', 'field2', 'value2', 'field3', 'value3']);
|
||||
});
|
||||
|
||||
it('hSetEx parseCommand map', () => {
|
||||
const parser1 = new BasicCommandParser;
|
||||
HSETEX.parseCommand(parser1, 'key', new Map([['field1', 'value1'], ['field2', 'value2']]));
|
||||
assert.deepEqual(parser1.redisArgs, ['HSETEX', 'key', 'FIELDS', '2', 'field1', 'value1', 'field2', 'value2']);
|
||||
});
|
||||
|
||||
it('hSetEx parseCommand obj', () => {
|
||||
const parser1 = new BasicCommandParser;
|
||||
HSETEX.parseCommand(parser1, 'key', {field1: "value1", field2: "value2"});
|
||||
assert.deepEqual(parser1.redisArgs, ['HSETEX', 'key', 'FIELDS', '2', 'field1', 'value1', 'field2', 'value2']);
|
||||
});
|
||||
|
||||
it('hSetEx parseCommand options FNX KEEPTTL', () => {
|
||||
const parser = new BasicCommandParser;
|
||||
HSETEX.parseCommand(parser, 'key', ['field', 'value'], {mode: 'FNX', expiration: 'KEEPTTL'});
|
||||
assert.deepEqual(parser.redisArgs, ['HSETEX', 'key', 'FNX', 'KEEPTTL', 'FIELDS', '1', 'field', 'value']);
|
||||
});
|
||||
|
||||
it('hSetEx parseCommand options FXX EX 500', () => {
|
||||
const parser = new BasicCommandParser;
|
||||
HSETEX.parseCommand(parser, 'key', ['field', 'value'], {mode: 'FXX', expiration: {type: 'EX', value: 500}});
|
||||
assert.deepEqual(parser.redisArgs, ['HSETEX', 'key', 'FXX', 'EX', '500', 'FIELDS', '1', 'field', 'value']);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('HSETEX call', () => {
|
||||
testUtils.testWithClientIfVersionWithinRange([[8], 'LATEST'], 'hSetEx calls', async client => {
|
||||
assert.deepEqual(
|
||||
await client.hSetEx('key_hsetex_call', ['field1', 'value1'], {expiration: {type: "EX", value: 500}, mode: "FNX"}),
|
||||
1
|
||||
);
|
||||
|
||||
assert.deepEqual(
|
||||
await client.hSetEx('key_hsetex_call', ['field1', 'value1', 'field2', 'value2'], {expiration: {type: "EX", value: 500}, mode: "FXX"}),
|
||||
0
|
||||
);
|
||||
|
||||
assert.deepEqual(
|
||||
await client.hSetEx('key_hsetex_call', ['field1', 'value1', 'field2', 'value2'], {expiration: {type: "EX", value: 500}, mode: "FNX"}),
|
||||
0
|
||||
);
|
||||
|
||||
assert.deepEqual(
|
||||
await client.hSetEx('key_hsetex_call', ['field2', 'value2'], {expiration: {type: "EX", value: 500}, mode: "FNX"}),
|
||||
1
|
||||
);
|
||||
|
||||
assert.deepEqual(
|
||||
await client.hSetEx('key_hsetex_call', ['field1', 'value1', 'field2', 'value2'], {expiration: {type: "EX", value: 500}, mode: "FXX"}),
|
||||
1
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
});
|
Reference in New Issue
Block a user