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`
- `GEORADIUSBYMEMBERSTORE` -> `GEORADIUSBYMEMBER_STORE`
- `XACK`: `boolean` -> `number` [^boolean-to-number]
- `XADD`: the `INCR` option has been removed, use `XADD_INCR` instead
[^enum-to-constants]: TODO

View File

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

View File

@@ -21,7 +21,7 @@ export default {
transformArguments(...[key, value, fieldValue]: SingleFieldArguments | MultipleFieldsArguments) {
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(
convertValue(value),
convertValue(fieldValue!)

View File

@@ -1,19 +1,19 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './SCRIPT_DEBUG';
import SCRIPT_DEBUG from './SCRIPT_DEBUG';
describe('SCRIPT DEBUG', () => {
it('transformArguments', () => {
assert.deepEqual(
transformArguments('NO'),
['SCRIPT', 'DEBUG', 'NO']
);
});
it('transformArguments', () => {
assert.deepEqual(
SCRIPT_DEBUG.transformArguments('NO'),
['SCRIPT', 'DEBUG', 'NO']
);
});
testUtils.testWithClient('client.scriptDebug', async client => {
assert.equal(
await client.scriptDebug('NO'),
'OK'
);
}, GLOBAL.SERVERS.OPEN);
testUtils.testWithClient('client.scriptDebug', async client => {
assert.equal(
await client.scriptDebug('NO'),
'OK'
);
}, GLOBAL.SERVERS.OPEN);
});

View File

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

View File

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

View File

@@ -1,28 +1,28 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './SCRIPT_FLUSH';
import SCRIPT_FLUSH from './SCRIPT_FLUSH';
describe('SCRIPT FLUSH', () => {
describe('transformArguments', () => {
it('simple', () => {
assert.deepEqual(
transformArguments(),
['SCRIPT', 'FLUSH']
);
});
it('with mode', () => {
assert.deepEqual(
transformArguments('SYNC'),
['SCRIPT', 'FLUSH', 'SYNC']
);
});
describe('transformArguments', () => {
it('simple', () => {
assert.deepEqual(
SCRIPT_FLUSH.transformArguments(),
['SCRIPT', 'FLUSH']
);
});
testUtils.testWithClient('client.scriptFlush', async client => {
assert.equal(
await client.scriptFlush(),
'OK'
);
}, GLOBAL.SERVERS.OPEN);
it('with mode', () => {
assert.deepEqual(
SCRIPT_FLUSH.transformArguments('SYNC'),
['SCRIPT', 'FLUSH', 'SYNC']
);
});
});
testUtils.testWithClient('client.scriptFlush', async client => {
assert.equal(
await client.scriptFlush(),
'OK'
);
}, GLOBAL.SERVERS.OPEN);
});

View File

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

View File

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

View File

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

View File

@@ -1,23 +1,23 @@
import { strict as assert } from 'assert';
import { scriptSha1 } from '../lua-script';
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', () => {
const SCRIPT = 'return 1;',
SCRIPT_SHA1 = scriptSha1(SCRIPT);
const SCRIPT = 'return 1;',
SCRIPT_SHA1 = scriptSha1(SCRIPT);
it('transformArguments', () => {
assert.deepEqual(
transformArguments(SCRIPT),
['SCRIPT', 'LOAD', SCRIPT]
);
});
it('transformArguments', () => {
assert.deepEqual(
SCRIPT_LOAD.transformArguments(SCRIPT),
['SCRIPT', 'LOAD', SCRIPT]
);
});
testUtils.testWithClient('client.scriptLoad', async client => {
assert.equal(
await client.scriptLoad(SCRIPT),
SCRIPT_SHA1
);
}, GLOBAL.SERVERS.OPEN);
testUtils.testWithClient('client.scriptLoad', async client => {
assert.equal(
await client.scriptLoad(SCRIPT),
SCRIPT_SHA1
);
}, GLOBAL.SERVERS.OPEN);
});

View File

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

View File

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

View File

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

View File

@@ -145,6 +145,11 @@ import RPUSHX from './RPUSHX';
import SADD from './SADD';
import SCAN from './SCAN';
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 SDIFFSTORE from './SDIFFSTORE';
import SET from './SET';
@@ -516,6 +521,16 @@ export default {
scan: SCAN,
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,
SDIFFSTORE,