1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-07 13:22:56 +03:00

Merge branch 'master' of github.com:redis/node-redis

This commit is contained in:
leibale
2022-06-30 13:38:29 -04:00
24 changed files with 1449 additions and 1468 deletions

View File

@@ -8,14 +8,14 @@
"dependencies": {
"@redis/client": "../packages/client",
"hdr-histogram-js": "3.0.0",
"ioredis": "5.0.4",
"ioredis": "5.1.0",
"redis-v3": "npm:redis@3.1.2",
"yargs": "17.4.1"
"yargs": "17.5.1"
}
},
"../packages/client": {
"name": "@redis/client",
"version": "1.0.5",
"version": "1.1.0",
"license": "MIT",
"dependencies": {
"cluster-key-slot": "1.1.0",
@@ -25,22 +25,22 @@
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "^1.0.2",
"@redis/test-utils": "*",
"@types/node": "^17.0.29",
"@types/sinon": "^10.0.11",
"@types/node": "^18.0.0",
"@types/sinon": "^10.0.12",
"@types/yallist": "^4.0.1",
"@typescript-eslint/eslint-plugin": "^5.21.0",
"@typescript-eslint/parser": "^5.21.0",
"eslint": "^8.14.0",
"@typescript-eslint/eslint-plugin": "^5.30.0",
"@typescript-eslint/parser": "^5.30.0",
"eslint": "^8.18.0",
"nyc": "^15.1.0",
"release-it": "^14.14.2",
"sinon": "^13.0.2",
"release-it": "^15.1.1",
"sinon": "^14.0.0",
"source-map-support": "^0.5.21",
"ts-node": "^10.7.0",
"typedoc": "^0.22.15",
"typescript": "^4.6.3"
"ts-node": "^10.8.1",
"typedoc": "^0.23.2",
"typescript": "^4.7.4"
},
"engines": {
"node": ">=12"
"node": ">=14"
}
},
"node_modules/@assemblyscript/loader": {
@@ -191,9 +191,9 @@
}
},
"node_modules/ioredis": {
"version": "5.0.4",
"resolved": "https://registry.npmjs.org/ioredis/-/ioredis-5.0.4.tgz",
"integrity": "sha512-qFJw3MnPNsJF1lcIOP3vztbsasOXK3nDdNAgjQj7t7/Bn/w10PGchTOpqylQNxjzPbLoYDu34LjeJtSWiKBntQ==",
"version": "5.1.0",
"resolved": "https://registry.npmjs.org/ioredis/-/ioredis-5.1.0.tgz",
"integrity": "sha512-HYHnvwxFwefeUBj0hZFejLvd8Q/YNAfnZlZG/hSRxkRhXMs1H8soMEVccHd1WlLrKkynorXBsAtqDGskOdAfVQ==",
"dependencies": {
"@ioredis/commands": "^1.1.1",
"cluster-key-slot": "^1.1.0",
@@ -354,9 +354,9 @@
}
},
"node_modules/yargs": {
"version": "17.4.1",
"resolved": "https://registry.npmjs.org/yargs/-/yargs-17.4.1.tgz",
"integrity": "sha512-WSZD9jgobAg3ZKuCQZSa3g9QOJeCCqLoLAykiWgmXnDo9EPnn4RPf5qVTtzgOx66o6/oqhcA5tHtJXpG8pMt3g==",
"version": "17.5.1",
"resolved": "https://registry.npmjs.org/yargs/-/yargs-17.5.1.tgz",
"integrity": "sha512-t6YAJcxDkNX7NFYiVtKvWUz8l+PaKTLiL63mJYWR2GnHq2gjEWISzsLp9wg3aY36dY1j+gfIEL3pIF+XlJJfbA==",
"dependencies": {
"cliui": "^7.0.2",
"escalade": "^3.1.1",
@@ -395,21 +395,21 @@
"requires": {
"@istanbuljs/nyc-config-typescript": "^1.0.2",
"@redis/test-utils": "*",
"@types/node": "^17.0.29",
"@types/sinon": "^10.0.11",
"@types/node": "^18.0.0",
"@types/sinon": "^10.0.12",
"@types/yallist": "^4.0.1",
"@typescript-eslint/eslint-plugin": "^5.21.0",
"@typescript-eslint/parser": "^5.21.0",
"@typescript-eslint/eslint-plugin": "^5.30.0",
"@typescript-eslint/parser": "^5.30.0",
"cluster-key-slot": "1.1.0",
"eslint": "^8.14.0",
"eslint": "^8.18.0",
"generic-pool": "3.8.2",
"nyc": "^15.1.0",
"release-it": "^14.14.2",
"sinon": "^13.0.2",
"release-it": "^15.1.1",
"sinon": "^14.0.0",
"source-map-support": "^0.5.21",
"ts-node": "^10.7.0",
"typedoc": "^0.22.15",
"typescript": "^4.6.3",
"ts-node": "^10.8.1",
"typedoc": "^0.23.2",
"typescript": "^4.7.4",
"yallist": "4.0.0"
}
},
@@ -498,9 +498,9 @@
}
},
"ioredis": {
"version": "5.0.4",
"resolved": "https://registry.npmjs.org/ioredis/-/ioredis-5.0.4.tgz",
"integrity": "sha512-qFJw3MnPNsJF1lcIOP3vztbsasOXK3nDdNAgjQj7t7/Bn/w10PGchTOpqylQNxjzPbLoYDu34LjeJtSWiKBntQ==",
"version": "5.1.0",
"resolved": "https://registry.npmjs.org/ioredis/-/ioredis-5.1.0.tgz",
"integrity": "sha512-HYHnvwxFwefeUBj0hZFejLvd8Q/YNAfnZlZG/hSRxkRhXMs1H8soMEVccHd1WlLrKkynorXBsAtqDGskOdAfVQ==",
"requires": {
"@ioredis/commands": "^1.1.1",
"cluster-key-slot": "^1.1.0",
@@ -618,9 +618,9 @@
"integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA=="
},
"yargs": {
"version": "17.4.1",
"resolved": "https://registry.npmjs.org/yargs/-/yargs-17.4.1.tgz",
"integrity": "sha512-WSZD9jgobAg3ZKuCQZSa3g9QOJeCCqLoLAykiWgmXnDo9EPnn4RPf5qVTtzgOx66o6/oqhcA5tHtJXpG8pMt3g==",
"version": "17.5.1",
"resolved": "https://registry.npmjs.org/yargs/-/yargs-17.5.1.tgz",
"integrity": "sha512-t6YAJcxDkNX7NFYiVtKvWUz8l+PaKTLiL63mJYWR2GnHq2gjEWISzsLp9wg3aY36dY1j+gfIEL3pIF+XlJJfbA==",
"requires": {
"cliui": "^7.0.2",
"escalade": "^3.1.1",

View File

@@ -9,8 +9,8 @@
"dependencies": {
"@redis/client": "../packages/client",
"hdr-histogram-js": "3.0.0",
"ioredis": "5.0.4",
"ioredis": "5.1.0",
"redis-v3": "npm:redis@3.1.2",
"yargs": "17.4.1"
"yargs": "17.5.1"
}
}

View File

@@ -15,7 +15,7 @@ async function countMinSketch() {
// https://oss.redis.com/redisbloom/CountMinSketch_Commands/#cmsinitbyprob
try {
await client.cms.initByProb('mycms', 0.001, 0.01);
console.log('Reserved Top K.');
console.log('Initialized Count-Min Sketch.');
} catch (e) {
console.log('Error, maybe RedisBloom is not installed?:');
console.log(e);

View File

@@ -40,29 +40,38 @@ async function searchHashes() {
client.hSet('noderedis:animals:4', {name: 'Fido', species: 'dog', age: 7})
]);
// Perform a search query, find all the dogs...
// Perform a search query, find all the dogs... sort by age, descending.
// Documentation: https://oss.redis.com/redisearch/Commands/#ftsearch
// Query synatax: https://oss.redis.com/redisearch/Query_Syntax/
const results = await client.ft.search('idx:animals', '@species:{dog}');
// Query syntax: https://oss.redis.com/redisearch/Query_Syntax/
const results = await client.ft.search(
'idx:animals',
'@species:{dog}',
{
SORTBY: {
BY: 'age',
DIRECTION: 'DESC' // or 'ASC' (default if DIRECTION is not present)
}
}
);
// results:
// {
// total: 2,
// documents: [
// {
// id: 'noderedis:animals:4',
// id: 'noderedis:animals:3',
// value: {
// name: 'Fido',
// species: 'dog',
// age: '7'
// age: '9',
// name: 'Rover',
// species: 'dog'
// }
// },
// {
// id: 'noderedis:animals:3',
// id: 'noderedis:animals:4',
// value: {
// name: 'Rover',
// species: 'dog',
// age: '9'
// age: '7',
// name: 'Fido',
// species: 'dog'
// }
// }
// ]
@@ -71,9 +80,9 @@ async function searchHashes() {
console.log(`Results found: ${results.total}.`);
for (const doc of results.documents) {
// noderedis:animals:4: Fido
// noderedis:animals:3: Rover
console.log(`${doc.id}: ${doc.value.name}`);
// noderedis:animals:3: Rover, 9 years old.
// noderedis:animals:4: Fido, 7 years old.
console.log(`${doc.id}: ${doc.value.name}, ${doc.value.age} years old.`);
}
await client.quit();

2589
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -18,12 +18,12 @@
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "^1.0.2",
"@redis/test-utils": "*",
"@types/node": "^17.0.31",
"@types/node": "^18.0.0",
"nyc": "^15.1.0",
"release-it": "^15.0.0",
"release-it": "^15.1.1",
"source-map-support": "^0.5.21",
"ts-node": "^10.7.0",
"typedoc": "^0.22.15",
"typescript": "^4.6.4"
"ts-node": "^10.8.1",
"typedoc": "^0.23.2",
"typescript": "^4.7.4"
}
}

View File

@@ -468,6 +468,20 @@ describe('Client', () => {
['PONG']
);
}, GLOBAL.SERVERS.OPEN);
testUtils.testWithClient('should remember selected db', async client => {
await client.multi()
.select(1)
.exec();
await killClient(client);
assert.equal(
(await client.clientInfo()).db,
1
);
}, {
...GLOBAL.SERVERS.OPEN,
minimumDockerVersion: [6, 2] // CLIENT INFO
});
});
testUtils.testWithClient('scripts', async client => {

View File

@@ -606,18 +606,26 @@ export default class RedisClient<
);
}
multiExecutor(commands: Array<RedisMultiQueuedCommand>, chainId?: symbol): Promise<Array<RedisCommandRawReply>> {
async multiExecutor(
commands: Array<RedisMultiQueuedCommand>,
selectedDB?: number,
chainId?: symbol
): Promise<Array<RedisCommandRawReply>> {
const promise = Promise.all(
commands.map(({ args }) => {
return this.#queue.addCommand(args, RedisClient.commandOptions({
chainId
}));
return this.#queue.addCommand(args, { chainId });
})
);
this.#tick();
return promise;
const results = await promise;
if (selectedDB !== undefined) {
this.#selectedDB = selectedDB;
}
return results;
}
async* scanIterator(options?: ScanCommandOptions): AsyncIterable<string> {

View File

@@ -58,13 +58,13 @@ type InstantiableRedisMultiCommand<
S extends RedisScripts
> = new (...args: ConstructorParameters<typeof RedisClientMultiCommand>) => RedisClientMultiCommandType<M, F, S>;
export type RedisClientMultiExecutor = (queue: Array<RedisMultiQueuedCommand>, chainId?: symbol) => Promise<Array<RedisCommandRawReply>>;
export type RedisClientMultiExecutor = (
queue: Array<RedisMultiQueuedCommand>,
selectedDB?: number,
chainId?: symbol
) => Promise<Array<RedisCommandRawReply>>;
export default class RedisClientMultiCommand {
readonly #multi = new RedisMultiCommand();
readonly #executor: RedisClientMultiExecutor;
static extend<
M extends RedisModules,
F extends RedisFunctions,
@@ -81,7 +81,10 @@ export default class RedisClientMultiCommand {
});
}
readonly #multi = new RedisMultiCommand();
readonly #executor: RedisClientMultiExecutor;
readonly v4: Record<string, any> = {};
#selectedDB?: number;
constructor(executor: RedisClientMultiExecutor, legacyMode = false) {
this.#executor = executor;
@@ -136,6 +139,13 @@ export default class RedisClientMultiCommand {
);
}
SELECT(db: number, transformReply?: RedisCommand['transformReply']): this {
this.#selectedDB = db;
return this.addCommand(['SELECT', db.toString()], transformReply);
}
select = this.SELECT;
addCommand(args: RedisCommandArguments, transformReply?: RedisCommand['transformReply']): this {
this.#multi.addCommand(args, transformReply);
return this;
@@ -160,7 +170,11 @@ export default class RedisClientMultiCommand {
if (!commands) return [];
return this.#multi.handleExecReplies(
await this.#executor(commands, RedisMultiCommand.generateChainId())
await this.#executor(
commands,
this.#selectedDB,
RedisMultiCommand.generateChainId()
)
);
}
@@ -168,7 +182,10 @@ export default class RedisClientMultiCommand {
async execAsPipeline(): Promise<Array<RedisCommandRawReply>> {
return this.#multi.transformReplies(
await this.#executor(this.#multi.queue)
await this.#executor(
this.#multi.queue,
this.#selectedDB
)
);
}
}

View File

@@ -230,7 +230,7 @@ export default class RedisCluster<
return this.#execute(
firstKey,
false,
client => client.multiExecutor(commands, chainId)
client => client.multiExecutor(commands, undefined, chainId)
);
},
routing

View File

@@ -41,12 +41,21 @@ describe('HSET', () => {
);
});
it('Object', () => {
describe('Object', () => {
it('string', () => {
assert.deepEqual(
transformArguments('key', { field: 'value' }),
['HSET', 'key', 'field', 'value']
);
});
it('Buffer', () => {
assert.deepEqual(
transformArguments('key', { field: Buffer.from('value') }),
['HSET', 'key', 'field', Buffer.from('value')]
);
});
});
});
testUtils.testWithClient('client.hSet', async client => {

View File

@@ -20,8 +20,10 @@ export function transformArguments(...[ key, value, fieldValue ]: SingleFieldArg
const args: RedisCommandArguments = ['HSET', key];
if (typeof value === 'string' || typeof value === 'number' || Buffer.isBuffer(value)) {
pushValue(args, value);
pushValue(args, fieldValue!);
args.push(
convertValue(value),
convertValue(fieldValue!)
);
} else if (value instanceof Map) {
pushMap(args, value);
} else if (Array.isArray(value)) {
@@ -35,8 +37,10 @@ export function transformArguments(...[ key, value, fieldValue ]: SingleFieldArg
function pushMap(args: RedisCommandArguments, map: HSETMap): void {
for (const [key, value] of map.entries()) {
pushValue(args, key);
pushValue(args, value);
args.push(
convertValue(key),
convertValue(value)
);
}
}
@@ -47,22 +51,23 @@ function pushTuples(args: RedisCommandArguments, tuples: HSETTuples): void {
continue;
}
pushValue(args, tuple);
args.push(convertValue(tuple));
}
}
function pushObject(args: RedisCommandArguments, object: HSETObject): void {
for (const key of Object.keys(object)) {
args.push(key.toString(), object[key].toString());
args.push(
convertValue(key),
convertValue(object[key])
);
}
}
function pushValue(args: RedisCommandArguments, value: Types): void {
args.push(
typeof value === 'number' ?
function convertValue(value: Types): RedisCommandArgument {
return typeof value === 'number' ?
value.toString() :
value
);
value;
}
export declare function transformReply(): number;

View File

@@ -3,7 +3,7 @@ import { SinonSpy } from 'sinon';
import { promiseTimeout } from './utils';
export default new TestUtils({
defaultDockerVersion: '7.0-rc3',
defaultDockerVersion: '7.0.2',
dockerImageName: 'redis',
dockerImageVersionArgument: 'redis-version'
});

View File

@@ -21,19 +21,19 @@
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "^1.0.2",
"@redis/test-utils": "*",
"@types/node": "^17.0.31",
"@types/sinon": "^10.0.11",
"@types/node": "^18.0.0",
"@types/sinon": "^10.0.12",
"@types/yallist": "^4.0.1",
"@typescript-eslint/eslint-plugin": "^5.21.0",
"@typescript-eslint/parser": "^5.21.0",
"eslint": "^8.14.0",
"@typescript-eslint/eslint-plugin": "^5.30.0",
"@typescript-eslint/parser": "^5.30.0",
"eslint": "^8.18.0",
"nyc": "^15.1.0",
"release-it": "^15.0.0",
"sinon": "^13.0.2",
"release-it": "^15.1.1",
"sinon": "^14.0.0",
"source-map-support": "^0.5.21",
"ts-node": "^10.7.0",
"typedoc": "^0.22.15",
"typescript": "^4.6.4"
"ts-node": "^10.8.1",
"typedoc": "^0.23.2",
"typescript": "^4.7.4"
},
"engines": {
"node": ">=14"

View File

@@ -4,7 +4,7 @@ import RedisGraph from '.';
export default new TestUtils({
dockerImageName: 'redislabs/redisgraph',
dockerImageVersionArgument: 'redisgraph-version',
defaultDockerVersion: '2.8.9'
defaultDockerVersion: '2.8.15'
});
export const GLOBAL = {

View File

@@ -18,12 +18,12 @@
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "^1.0.2",
"@redis/test-utils": "*",
"@types/node": "^17.0.31",
"@types/node": "^18.0.0",
"nyc": "^15.1.0",
"release-it": "^15.0.0",
"release-it": "^15.1.1",
"source-map-support": "^0.5.21",
"ts-node": "^10.7.0",
"typedoc": "^0.22.15",
"typescript": "^4.6.4"
"ts-node": "^10.8.1",
"typedoc": "^0.23.2",
"typescript": "^4.7.4"
}
}

View File

@@ -4,7 +4,7 @@ import RedisJSON from '.';
export default new TestUtils({
dockerImageName: 'redislabs/rejson',
dockerImageVersionArgument: 'rejson-version',
defaultDockerVersion: '2.0.7'
defaultDockerVersion: '2.0.9'
});
export const GLOBAL = {

View File

@@ -18,12 +18,12 @@
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "^1.0.2",
"@redis/test-utils": "*",
"@types/node": "^17.0.31",
"@types/node": "^18.0.0",
"nyc": "^15.1.0",
"release-it": "^15.0.0",
"release-it": "^15.1.1",
"source-map-support": "^0.5.21",
"ts-node": "^10.7.0",
"typedoc": "^0.22.15",
"typescript": "^4.6.4"
"ts-node": "^10.8.1",
"typedoc": "^0.23.2",
"typescript": "^4.7.4"
}
}

View File

@@ -4,7 +4,7 @@ import RediSearch from '.';
export default new TestUtils({
dockerImageName: 'redislabs/redisearch',
dockerImageVersionArgument: 'redisearch-version',
defaultDockerVersion: '2.4.3'
defaultDockerVersion: '2.4.9'
});
export const GLOBAL = {

View File

@@ -18,12 +18,12 @@
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "^1.0.2",
"@redis/test-utils": "*",
"@types/node": "^17.0.31",
"@types/node": "^18.0.0",
"nyc": "^15.1.0",
"release-it": "^15.0.0",
"release-it": "^15.1.1",
"source-map-support": "^0.5.21",
"ts-node": "^10.7.0",
"typedoc": "^0.22.15",
"typescript": "^4.6.4"
"ts-node": "^10.8.1",
"typedoc": "^0.23.2",
"typescript": "^4.7.4"
}
}

View File

@@ -55,7 +55,7 @@ async function spawnRedisServerDocker({ image, version }: RedisServerDockerConfi
'docker run -d --network host $(' +
`docker build ${DOCKER_FODLER_PATH} -q ` +
`--build-arg IMAGE=${image}:${version} ` +
`--build-arg REDIS_ARGUMENTS="--save --port ${port.toString()} ${serverArguments.join(' ')}"` +
`--build-arg REDIS_ARGUMENTS="--save '' --port ${port.toString()} ${serverArguments.join(' ')}"` +
')'
);

View File

@@ -12,13 +12,13 @@
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "^1.0.2",
"@types/mocha": "^9.1.1",
"@types/node": "^17.0.31",
"@types/node": "^18.0.0",
"@types/yargs": "^17.0.10",
"mocha": "^10.0.0",
"nyc": "^15.1.0",
"source-map-support": "^0.5.21",
"ts-node": "^10.7.0",
"typescript": "^4.6.4",
"yargs": "^17.4.1"
"ts-node": "^10.8.1",
"typescript": "^4.7.4",
"yargs": "^17.5.1"
}
}

View File

@@ -4,7 +4,7 @@ import TimeSeries from '.';
export default new TestUtils({
dockerImageName: 'redislabs/redistimeseries',
dockerImageVersionArgument: 'timeseries-version',
defaultDockerVersion: '1.6.9'
defaultDockerVersion: '1.6.16'
});
export const GLOBAL = {

View File

@@ -18,12 +18,12 @@
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "^1.0.2",
"@redis/test-utils": "*",
"@types/node": "^17.0.31",
"@types/node": "^18.0.0",
"nyc": "^15.1.0",
"release-it": "^15.0.0",
"release-it": "^15.1.1",
"source-map-support": "^0.5.21",
"ts-node": "^10.7.0",
"typedoc": "^0.22.15",
"typescript": "^4.6.4"
"ts-node": "^10.8.1",
"typedoc": "^0.23.2",
"typescript": "^4.7.4"
}
}