1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00
This commit is contained in:
Leibale
2023-05-10 14:55:03 +03:00
parent b4196faa41
commit 13f1fa9e58
17 changed files with 119 additions and 99 deletions

View File

@@ -108,6 +108,7 @@ Some command arguments/replies have changed to align more closely to data types
- `GEORADIUSSTORE` -> `GEORADIUS_STORE` - `GEORADIUSSTORE` -> `GEORADIUS_STORE`
- `GEORADIUSBYMEMBERSTORE` -> `GEORADIUSBYMEMBER_STORE` - `GEORADIUSBYMEMBERSTORE` -> `GEORADIUSBYMEMBER_STORE`
- `XACK`: `boolean` -> `number` [^boolean-to-number] - `XACK`: `boolean` -> `number` [^boolean-to-number]
- `XADD`: the `INCR` option has been removed, use `XADD_INCR` instead
[^enum-to-constants]: TODO [^enum-to-constants]: TODO

View File

@@ -10,7 +10,7 @@ export default {
) { ) {
const args: Array<RedisArgument> = ['CONFIG', 'SET']; const args: Array<RedisArgument> = ['CONFIG', 'SET'];
if (typeof parameterOrConfig === 'string' || Buffer.isBuffer(parameterOrConfig)) { if (typeof parameterOrConfig === 'string' || parameterOrConfig instanceof Buffer) {
args.push(parameterOrConfig, value!); args.push(parameterOrConfig, value!);
} else { } else {
for (const [key, value] of Object.entries(parameterOrConfig)) { for (const [key, value] of Object.entries(parameterOrConfig)) {

View File

@@ -21,7 +21,7 @@ export default {
transformArguments(...[key, value, fieldValue]: SingleFieldArguments | MultipleFieldsArguments) { transformArguments(...[key, value, fieldValue]: SingleFieldArguments | MultipleFieldsArguments) {
const args: Array<RedisArgument> = ['HSET', key]; const args: Array<RedisArgument> = ['HSET', key];
if (typeof value === 'string' || typeof value === 'number' || Buffer.isBuffer(value)) { if (typeof value === 'string' || typeof value === 'number' || value instanceof Buffer) {
args.push( args.push(
convertValue(value), convertValue(value),
convertValue(fieldValue!) convertValue(fieldValue!)

View File

@@ -1,11 +1,11 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './SCRIPT_DEBUG'; import SCRIPT_DEBUG from './SCRIPT_DEBUG';
describe('SCRIPT DEBUG', () => { describe('SCRIPT DEBUG', () => {
it('transformArguments', () => { it('transformArguments', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('NO'), SCRIPT_DEBUG.transformArguments('NO'),
['SCRIPT', 'DEBUG', 'NO'] ['SCRIPT', 'DEBUG', 'NO']
); );
}); });

View File

@@ -6,5 +6,5 @@ export default {
transformArguments(mode: 'YES' | 'SYNC' | 'NO') { transformArguments(mode: 'YES' | 'SYNC' | 'NO') {
return ['SCRIPT', 'DEBUG', mode]; return ['SCRIPT', 'DEBUG', mode];
}, },
transformReply: undefined as unknown as () => SimpleStringReply transformReply: undefined as unknown as () => SimpleStringReply<'OK'>
} as const satisfies Command; } as const satisfies Command;

View File

@@ -1,19 +1,19 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './SCRIPT_EXISTS'; import SCRIPT_EXISTS from './SCRIPT_EXISTS';
describe('SCRIPT EXISTS', () => { describe('SCRIPT EXISTS', () => {
describe('transformArguments', () => { describe('transformArguments', () => {
it('string', () => { it('string', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('sha1'), SCRIPT_EXISTS.transformArguments('sha1'),
['SCRIPT', 'EXISTS', 'sha1'] ['SCRIPT', 'EXISTS', 'sha1']
); );
}); });
it('array', () => { it('array', () => {
assert.deepEqual( assert.deepEqual(
transformArguments(['1', '2']), SCRIPT_EXISTS.transformArguments(['1', '2']),
['SCRIPT', 'EXISTS', '1', '2'] ['SCRIPT', 'EXISTS', '1', '2']
); );
}); });
@@ -22,7 +22,7 @@ describe('SCRIPT EXISTS', () => {
testUtils.testWithClient('client.scriptExists', async client => { testUtils.testWithClient('client.scriptExists', async client => {
assert.deepEqual( assert.deepEqual(
await client.scriptExists('sha1'), await client.scriptExists('sha1'),
[false] [0]
); );
}, GLOBAL.SERVERS.OPEN); }, GLOBAL.SERVERS.OPEN);
}); });

View File

@@ -1,19 +1,19 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './SCRIPT_FLUSH'; import SCRIPT_FLUSH from './SCRIPT_FLUSH';
describe('SCRIPT FLUSH', () => { describe('SCRIPT FLUSH', () => {
describe('transformArguments', () => { describe('transformArguments', () => {
it('simple', () => { it('simple', () => {
assert.deepEqual( assert.deepEqual(
transformArguments(), SCRIPT_FLUSH.transformArguments(),
['SCRIPT', 'FLUSH'] ['SCRIPT', 'FLUSH']
); );
}); });
it('with mode', () => { it('with mode', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('SYNC'), SCRIPT_FLUSH.transformArguments('SYNC'),
['SCRIPT', 'FLUSH', 'SYNC'] ['SCRIPT', 'FLUSH', 'SYNC']
); );
}); });

View File

@@ -12,5 +12,5 @@ export default {
return args; return args;
}, },
transformReply: undefined as unknown as () => SimpleStringReply transformReply: undefined as unknown as () => SimpleStringReply<'OK'>
} as const satisfies Command; } as const satisfies Command;

View File

@@ -1,10 +1,10 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import { transformArguments } from './SCRIPT_KILL'; import SCRIPT_KILL from './SCRIPT_KILL';
describe('SCRIPT KILL', () => { describe('SCRIPT KILL', () => {
it('transformArguments', () => { it('transformArguments', () => {
assert.deepEqual( assert.deepEqual(
transformArguments(), SCRIPT_KILL.transformArguments(),
['SCRIPT', 'KILL'] ['SCRIPT', 'KILL']
); );
}); });

View File

@@ -6,5 +6,5 @@ export default {
transformArguments() { transformArguments() {
return ['SCRIPT', 'KILL']; return ['SCRIPT', 'KILL'];
}, },
transformReply: undefined as unknown as () => SimpleStringReply transformReply: undefined as unknown as () => SimpleStringReply<'OK'>
} as const satisfies Command; } as const satisfies Command;

View File

@@ -1,7 +1,7 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import { scriptSha1 } from '../lua-script';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './SCRIPT_LOAD'; import SCRIPT_LOAD from './SCRIPT_LOAD';
import { scriptSha1 } from '../lua-script';
describe('SCRIPT LOAD', () => { describe('SCRIPT LOAD', () => {
const SCRIPT = 'return 1;', const SCRIPT = 'return 1;',
@@ -9,7 +9,7 @@ describe('SCRIPT LOAD', () => {
it('transformArguments', () => { it('transformArguments', () => {
assert.deepEqual( assert.deepEqual(
transformArguments(SCRIPT), SCRIPT_LOAD.transformArguments(SCRIPT),
['SCRIPT', 'LOAD', SCRIPT] ['SCRIPT', 'LOAD', SCRIPT]
); );
}); });

View File

@@ -31,9 +31,13 @@ describe('XSETID', () => {
}); });
testUtils.testAll('xSetId', async client => { testUtils.testAll('xSetId', async client => {
assert.deepEqual( const id = await client.xAdd('key', '*', {
await client.xSetId('key', '0-0'), field: 'value'
[] });
assert.equal(
await client.xSetId('key', id),
'OK'
); );
}, { }, {
client: GLOBAL.SERVERS.OPEN, client: GLOBAL.SERVERS.OPEN,

View File

@@ -17,7 +17,7 @@ export function pushZInterArguments(
keys: ZKeys, keys: ZKeys,
options?: ZInterOptions options?: ZInterOptions
) { ) {
pushZKeysArguments(args, keys); args = pushZKeysArguments(args, keys);
if (options?.AGGREGATE) { if (options?.AGGREGATE) {
args.push('AGGREGATE', options.AGGREGATE); args.push('AGGREGATE', options.AGGREGATE);

View File

@@ -6,8 +6,8 @@ describe('ZINTERSTORE', () => {
describe('transformArguments', () => { describe('transformArguments', () => {
it('key (string)', () => { it('key (string)', () => {
assert.deepEqual( assert.deepEqual(
ZINTERSTORE.transformArguments('destination', 'key'), ZINTERSTORE.transformArguments('destination', 'source'),
['ZINTERSTORE', 'destination', '1', 'key'] ['ZINTERSTORE', 'destination', '1', 'source']
); );
}); });
@@ -21,10 +21,10 @@ describe('ZINTERSTORE', () => {
it('key & weight', () => { it('key & weight', () => {
assert.deepEqual( assert.deepEqual(
ZINTERSTORE.transformArguments('destination', { ZINTERSTORE.transformArguments('destination', {
key: 'key', key: 'source',
weight: 1 weight: 1
}), }),
['ZINTERSTORE', 'destination', '1', 'key', 'WEIGHTS', '1'] ['ZINTERSTORE', 'destination', '1', 'source', 'WEIGHTS', '1']
); );
}); });
@@ -43,10 +43,10 @@ describe('ZINTERSTORE', () => {
it('with AGGREGATE', () => { it('with AGGREGATE', () => {
assert.deepEqual( assert.deepEqual(
ZINTERSTORE.transformArguments('destination', 'key', { ZINTERSTORE.transformArguments('destination', 'source', {
AGGREGATE: 'SUM' AGGREGATE: 'SUM'
}), }),
['ZINTERSTORE', 'destination', '1', 'key', 'AGGREGATE', 'SUM'] ['ZINTERSTORE', 'destination', '1', 'source', 'AGGREGATE', 'SUM']
); );
}); });
}); });

View File

@@ -7,7 +7,7 @@ describe('ZUNIONSTORE', () => {
it('key (string)', () => { it('key (string)', () => {
assert.deepEqual( assert.deepEqual(
ZUNIONSTORE.transformArguments('destination', 'source'), ZUNIONSTORE.transformArguments('destination', 'source'),
['ZUNIONSTORE', 'destination', '1', 'key'] ['ZUNIONSTORE', 'destination', '1', 'source']
); );
}); });
@@ -21,10 +21,10 @@ describe('ZUNIONSTORE', () => {
it('key & weight', () => { it('key & weight', () => {
assert.deepEqual( assert.deepEqual(
ZUNIONSTORE.transformArguments('destination', { ZUNIONSTORE.transformArguments('destination', {
key: 'key', key: 'source',
weight: 1 weight: 1
}), }),
['ZUNIONSTORE', 'destination', '1', 'key', 'WEIGHTS', '1'] ['ZUNIONSTORE', 'destination', '1', 'source', 'WEIGHTS', '1']
); );
}); });
@@ -43,10 +43,10 @@ describe('ZUNIONSTORE', () => {
it('with AGGREGATE', () => { it('with AGGREGATE', () => {
assert.deepEqual( assert.deepEqual(
ZUNIONSTORE.transformArguments('destination', 'key', { ZUNIONSTORE.transformArguments('destination', 'source', {
AGGREGATE: 'SUM' AGGREGATE: 'SUM'
}), }),
['ZUNIONSTORE', 'destination', '1', 'key', 'AGGREGATE', 'SUM'] ['ZUNIONSTORE', 'destination', '1', 'source', 'AGGREGATE', 'SUM']
); );
}); });
}); });

View File

@@ -480,7 +480,7 @@ export function pushZKeysArguments(
} }
function isPlainKey(key: RedisArgument | ZKeyAndWeight): key is RedisArgument { function isPlainKey(key: RedisArgument | ZKeyAndWeight): key is RedisArgument {
return typeof key === 'string' || Buffer.isBuffer(key); return typeof key === 'string' || key instanceof Buffer;
} }
function isPlainKeys(keys: Array<RedisArgument> | Array<ZKeyAndWeight>): keys is Array<RedisArgument> { function isPlainKeys(keys: Array<RedisArgument> | Array<ZKeyAndWeight>): keys is Array<RedisArgument> {

View File

@@ -145,6 +145,11 @@ import RPUSHX from './RPUSHX';
import SADD from './SADD'; import SADD from './SADD';
import SCAN from './SCAN'; import SCAN from './SCAN';
import SCARD from './SCARD'; import SCARD from './SCARD';
import SCRIPT_DEBUG from './SCRIPT_DEBUG';
import SCRIPT_EXISTS from './SCRIPT_EXISTS';
import SCRIPT_FLUSH from './SCRIPT_FLUSH';
import SCRIPT_KILL from './SCRIPT_KILL';
import SCRIPT_LOAD from './SCRIPT_LOAD';
import SDIFF from './SDIFF'; import SDIFF from './SDIFF';
import SDIFFSTORE from './SDIFFSTORE'; import SDIFFSTORE from './SDIFFSTORE';
import SET from './SET'; import SET from './SET';
@@ -516,6 +521,16 @@ export default {
scan: SCAN, scan: SCAN,
SCARD, SCARD,
sCard: SCARD, sCard: SCARD,
SCRIPT_DEBUG,
scriptDebug: SCRIPT_DEBUG,
SCRIPT_EXISTS,
scriptExists: SCRIPT_EXISTS,
SCRIPT_FLUSH,
scriptFlush: SCRIPT_FLUSH,
SCRIPT_KILL,
scriptKill: SCRIPT_KILL,
SCRIPT_LOAD,
scriptLoad: SCRIPT_LOAD,
SDIFF, SDIFF,
sDiff: SDIFF, sDiff: SDIFF,
SDIFFSTORE, SDIFFSTORE,