You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-03 04:01:40 +03:00
* Parser support with all commands * remove "dist" from all imports for consistency * address most of my review comments * small tweak to multi type mapping handling * tweak multi commands / fix addScript cases * nits * addressed all in person review comments * revert addCommand/addScript changes to multi-commands addCommand needs to be there for sendCommand like ability within a multi. If its there, it might as well be used by createCommand() et al, to avoid repeating code. addScript is there (even though only used once), but now made private to keep the logic for bookkeeping near each other.
166 lines
3.8 KiB
TypeScript
166 lines
3.8 KiB
TypeScript
import { strict as assert } from 'node:assert';
|
|
import testUtils, { GLOBAL } from '../test-utils';
|
|
import SET from './SET';
|
|
import { parseArgs } from './generic-transformers';
|
|
|
|
describe('SET', () => {
|
|
describe('transformArguments', () => {
|
|
describe('value', () => {
|
|
it('string', () => {
|
|
assert.deepEqual(
|
|
parseArgs(SET, 'key', 'value'),
|
|
['SET', 'key', 'value']
|
|
);
|
|
});
|
|
|
|
it('number', () => {
|
|
assert.deepEqual(
|
|
parseArgs(SET, 'key', 0),
|
|
['SET', 'key', '0']
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('expiration', () => {
|
|
it('\'KEEPTTL\'', () => {
|
|
assert.deepEqual(
|
|
parseArgs(SET, 'key', 'value', {
|
|
expiration: 'KEEPTTL'
|
|
}),
|
|
['SET', 'key', 'value', 'KEEPTTL']
|
|
);
|
|
});
|
|
|
|
it('{ type: \'KEEPTTL\' }', () => {
|
|
assert.deepEqual(
|
|
parseArgs(SET, 'key', 'value', {
|
|
expiration: {
|
|
type: 'KEEPTTL'
|
|
}
|
|
}),
|
|
['SET', 'key', 'value', 'KEEPTTL']
|
|
);
|
|
});
|
|
|
|
it('{ type: \'EX\' }', () => {
|
|
assert.deepEqual(
|
|
parseArgs(SET, 'key', 'value', {
|
|
expiration: {
|
|
type: 'EX',
|
|
value: 0
|
|
}
|
|
}),
|
|
['SET', 'key', 'value', 'EX', '0']
|
|
);
|
|
});
|
|
|
|
it('with EX (backwards compatibility)', () => {
|
|
assert.deepEqual(
|
|
parseArgs(SET, 'key', 'value', {
|
|
EX: 0
|
|
}),
|
|
['SET', 'key', 'value', 'EX', '0']
|
|
);
|
|
});
|
|
|
|
it('with PX (backwards compatibility)', () => {
|
|
assert.deepEqual(
|
|
parseArgs(SET, 'key', 'value', {
|
|
PX: 0
|
|
}),
|
|
['SET', 'key', 'value', 'PX', '0']
|
|
);
|
|
});
|
|
|
|
it('with EXAT (backwards compatibility)', () => {
|
|
assert.deepEqual(
|
|
parseArgs(SET, 'key', 'value', {
|
|
EXAT: 0
|
|
}),
|
|
['SET', 'key', 'value', 'EXAT', '0']
|
|
);
|
|
});
|
|
|
|
it('with PXAT (backwards compatibility)', () => {
|
|
assert.deepEqual(
|
|
parseArgs(SET, 'key', 'value', {
|
|
PXAT: 0
|
|
}),
|
|
['SET', 'key', 'value', 'PXAT', '0']
|
|
);
|
|
});
|
|
|
|
it('with KEEPTTL (backwards compatibility)', () => {
|
|
assert.deepEqual(
|
|
parseArgs(SET, 'key', 'value', {
|
|
KEEPTTL: true
|
|
}),
|
|
['SET', 'key', 'value', 'KEEPTTL']
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('condition', () => {
|
|
it('with condition', () => {
|
|
assert.deepEqual(
|
|
parseArgs(SET, 'key', 'value', {
|
|
condition: 'NX'
|
|
}),
|
|
['SET', 'key', 'value', 'NX']
|
|
);
|
|
});
|
|
|
|
it('with NX (backwards compatibility)', () => {
|
|
assert.deepEqual(
|
|
parseArgs(SET, 'key', 'value', {
|
|
NX: true
|
|
}),
|
|
['SET', 'key', 'value', 'NX']
|
|
);
|
|
});
|
|
|
|
it('with XX (backwards compatibility)', () => {
|
|
assert.deepEqual(
|
|
parseArgs(SET, 'key', 'value', {
|
|
XX: true
|
|
}),
|
|
['SET', 'key', 'value', 'XX']
|
|
);
|
|
});
|
|
});
|
|
|
|
it('with GET', () => {
|
|
assert.deepEqual(
|
|
parseArgs(SET, 'key', 'value', {
|
|
GET: true
|
|
}),
|
|
['SET', 'key', 'value', 'GET']
|
|
);
|
|
});
|
|
|
|
it('with expiration, condition, GET', () => {
|
|
assert.deepEqual(
|
|
parseArgs(SET, 'key', 'value', {
|
|
expiration: {
|
|
type: 'EX',
|
|
value: 0
|
|
},
|
|
condition: 'NX',
|
|
GET: true
|
|
}),
|
|
['SET', 'key', 'value', 'EX', '0', 'NX', 'GET']
|
|
);
|
|
});
|
|
});
|
|
|
|
testUtils.testAll('set', async client => {
|
|
assert.equal(
|
|
await client.set('key', 'value'),
|
|
'OK'
|
|
);
|
|
}, {
|
|
client: GLOBAL.SERVERS.OPEN,
|
|
cluster: GLOBAL.CLUSTERS.OPEN
|
|
});
|
|
});
|