Skip to content

Commit 54f9d57

Browse files
leibalericsammustard-mhSimon Prickettsimonprickett
authored
v4.0.1 (#1779)
* update workflows & README * add .deepsource.toml * fix client.quit, add error events on cluster, fix some "deepsource.io" warnings * Release 4.0.0-rc.1 * add cluster.duplicate, add some tests * fix #1650 - add support for Buffer in some commands, add GET_BUFFER command * fix GET and GET_BUFFER return type * update FAQ * Update invalid code example in README.md (#1654) * Update invalid code example in README.md * Update README.md Co-authored-by: Leibale Eidelman <[email protected]> * fix #1652 * ref #1653 - better types * better types * fix 5412479 * Update GEOSEARCHSTORE.spec.ts * fix #1660 - add support for client.HSET('key', 'field', 'value') * upgrade dependencies, update README * fix #1659 - add support for db-number in client options url * fix README, remove unused import, downgrade typedoc & typedoc-plugin-markdown * update client-configurations.md * fix README * add CLUSTER_SLOTS, add some tests * fix "createClient with url" test with redis 5 * remove unused imports * Release 4.0.0-rc.2 * add missing semicolon * replace empty "transformReply" functions with typescript "declare" * fix EVAL & EVALSHA, add some tests, npm update * fix #1665 - add ZRANGEBYLEX, ZRANGEBYSCORE, ZRANGEBYSCORE_WITHSCORES * new issue templates * add all COMMAND commands * run COMMAND & COMMAND INFO tests only on redis >6 * Create SECURITY.md * fix #1671 - add support for all client configurations in cluster * ref #1671 - add support for defaults * remove some commands from cluster, npm update, clean code, * lock benny version * fix #1674 - remove `isolationPoolOptions` when creating isolated connection * increase test coverage * update .npmignore * Release 4.0.0-rc.3 * fix README * remove whitespace from LICENSE * use "export { x as y }" instead of import & const * move from "NodeRedis" to "Redis" * fix #1676 * update comments * Auth before select database (#1679) * Auth before select database * fix #1681 Co-authored-by: leibale <[email protected]> * Adds connect-as-acl-user example. (#1684) * Adds connect-as-acl-user example. * Adds blank line at end. * Set to private. * Adds examples folder to npmignore. * Adds Apple .DS_Store file to .gitignore (#1685) * Adds Apple .DS_Store file. * Add .DS_Store to .npmignore too Co-authored-by: Leibale Eidelman <[email protected]> * move examples * clean some tests * clean code * Adds examples table of contents and contribution guidelines. (#1686) * Updated examples to use named functions. (#1687) * Updated examples to user named functions. * Update README.md Co-authored-by: Leibale Eidelman <[email protected]> * update docs, add 6.0.x to the tests matrix, add eslint, npm update, fix some commands, fix some types Co-authored-by: Simon Prickett <[email protected]> * fix tests with redis 6.0.x * fix ACL GETUSER test * fix client.quit and client.disconnect * fix ACL GETUSER * Adds TypeScript note and corrects a typo. * Fixes a bug in the Scan Iterator section. (#1694) * Made examples use local version. * Add `lua-multi-incr.js` example (#1692) Also fix syntax error in the lua example in the README Closes #1689. * Add(examples): Create an example for blPop & lPush (#1696) * Add(examples): Create an example for blPop & lPush Signed-off-by: Aditya Rastogi <[email protected]> * Update(examples): fix case, add timeout, update readme Signed-off-by: Aditya Rastogi <[email protected]> Closes #1693. * Add command-with-modifiers.js example (#1695) * Adds TypeScript note and corrects a typo. * Adds command-with-modifiers example. (#1688) * Adds command-with-modifiers example. (#1688) * Adds command-with-modifiers example. (#1688) * Removed callbacks. Co-authored-by: Simon Prickett <[email protected]> Closes #1688. * Issue # 1697 FIX - creates an example script that shows how to use the SSCAN iterator (#1699) * #1697 fix for set scan example * adds the js file * adds comment * Minor layout and comment adjustment. Co-authored-by: srawat2 <shashank19aug> Co-authored-by: Simon Prickett <[email protected]> Closes #1697. * fix #1706 - HSET return type should be number * use dockers for tests, fix some bugs * increase dockers timeout to 30s * release drafter (#1683) * release drafter * fixing contributors * use dockers for tests, use npm workspaces, add rejson & redisearch modules, fix some bugs * fix #1712 - fix LINDEX return type * uncomment TIME tests * use codecov * fix tests.yml * uncomment "should handle live resharding" test * fix #1714 - update README(s) * add package-lock.json * update CONTRIBUTING.md * update examples * uncomment some tests * fix test-utils * move "all-in-one" to root folder * fix tests workflow * fix bug in cluster slots, enhance live resharding test * fix live resharding test * fix #1707 - handle number arguments in legacy mode * Add rejectedUnauthorized and other TLS options (#1708) * Update socket.ts * fix #1716 - decode username and password from url * fix some Z (sorted list) commands, increase commands test coverage * remove empty lines * fix 'Scenario' typo (#1720) * update readmes, add createCluster to the `redis` package * add .release-it.json files, update some md files * run tests on pull requests too * Support esModuleInterop set to false. (#1717) * Support esModuleInterop set to false. When testing the upcoming 4.x release, we got a bunch of typescript errors emitted from this project. We quickly realized this is because the library uses the esModuleInterop flag. This makes some imports _slightly_ easier to write, but it comes at a cost: it forces any application or library using this library to *also* have esModuleInterop on. The `esModuleInterop` flag is a bit of a holdover from an earlier time, and I would not recommend using it in libraries. The main issue is that if it's set to true, you are forcing any users of the library to also have `esModuleInterop`, where if you keep have it set to `false` (the default), you leave the decision to the user. This change should have no rammifications to users with `esModuleInterop` on, but it will enable support for those that have it off. This is especially good for library authors such as myself, because I would also like to keep this flag off to not force *my* users into this feature. * All tests now pass! * Move @types/redis-parser into client sub-package and removed a comma * npm update, remove html from readme * add tests and licence badges * update changelog.md * update .npmignore and .release-it.json * update .release-it.json * Release [email protected] * revert d32f1ed * fix .npmignore * replace @redis with @node-redis * Release [email protected] * update json & search version * Release [email protected] * Release [email protected] * update dependencies * Release [email protected] * fix #1724 - fix LINDEX signature * add positive test for LINDEX * fix #1718 - add support for buffers in pubsub * Fixed a few typos. * fix ARRPOP * fix #1726 * enhance cluster reshard handling * Adds RediSearch demo. * Adds intro sentence. * Made top level comment more descriptive. * Adds RedisJSON example. * Renamed JSON search example. * Some refactoring. * Fixed search example for JSON. * Minor wording updates. * Added missing pet name. * Adds JSON package overview. * Fixed typo. * Search package README initial version. * remove echo from docker entrypoint.sh * npm update * update docs * fix merge * fix merge * Release [email protected] * npm update * Release [email protected] * update sub modules * Release [email protected] * update README * Fixed `zScanIterator` example (#1733) The example for `zScanIterator` had the wrong values in the `for` loop. * fix #1738 - add support for buffers in HSET * fix for c96a0dd - remove .only from HSET tests * increase HSET test coverage * fix for d0de622 * ref #1741 - fix socket options type * fix #1741 - change default to `localhost` and update docs * fix #1739 - add support for number as value in HSET * fix tests workflow * increase pushGeoCountArgument test coverage * init time series * Update v3-to-v4.md (#1737) * Update v3-to-v4.md * Update v3-to-v4.md * Update v3-to-v4.md * Update docs/v3-to-v4.md Co-authored-by: Simon Prickett <[email protected]> * Update docs/v3-to-v4.md Co-authored-by: Simon Prickett <[email protected]> * Update docs/v3-to-v4.md Co-authored-by: Simon Prickett <[email protected]> * Update docs/v3-to-v4.md Co-authored-by: Simon Prickett <[email protected]> * Update docs/v3-to-v4.md Co-authored-by: Simon Prickett <[email protected]> * Update docs/v3-to-v4.md Co-authored-by: Simon Prickett <[email protected]> Co-authored-by: Leibale Eidelman <[email protected]> Co-authored-by: Simon Prickett <[email protected]> * fix #1744 - add npm minimum version * fix #1743 - restrict the list of published files (#1742) * fix TS.CREATERULE * fix #1673 - Export RedisClientType and RedisClusterType types (#1704) * add description to package.json * fix #1749 - FT.SEARCH SORTBY * Client: Export errors (#1750) * Client: Export errors * export RedisModules & RedisScripts as well Co-authored-by: Leibale Eidelman <[email protected]> * fix for 592714f - "fix tests" * fix for a453114 - fix FT.SEARCH * fix FT.SEARCH * improve encodeCommand performance, add set-get-delete-string benchmark * fix encodeCommand * Add the `event` doc (#1753) * hdr-histogram-js * fix #1764 - fix PubSub resubscribe * fix #1758 - implement some CLIENT commands, add `name` to `RedisClientOptions` * update tests badge link * update license badge link * ref #1765 - support lowercase command names in legacy mode * update benchmarks * fix LINSERT test title * fix v4 benchmarks * fix discord link * fix #1771 - fix PubSub resubscribe * fix #1766 - allow .quit() in PubSub mode * fix for e112568 - should not retry connecting if failed due to wrong auth * Add LGTM (#1773) * Update README.md * Update README.md Co-authored-by: Leibale Eidelman <[email protected]> * fix #1734 - fix PubSub unsubscribe race condition * Support RedisTimeSeries (#1757) * Implement missing commands and add test * Update DECRBY.spec.ts * Small changes * clean code * Update MGET_WITHLABELS.ts Use map in transformReply Co-authored-by: leibale <[email protected]> * fix #1774 #1767 - update docs Co-authored-by: Chayim <[email protected]> * Search commands (#1778) * ft.alter * ft.profile * clean code * fix generated documentation * fix documentation workflow * fix documentation workflow * fix documentation workflow * update CHANGELOG * Release [email protected] * update tsconfig.json * Release [email protected] * Release [email protected] * fix time-series .release-it.json * add @node-redis/time-series to README * add time-series to all in one * Release [email protected] Co-authored-by: Richard Samuelsson <[email protected]> Co-authored-by: mustard <[email protected]> Co-authored-by: Simon Prickett <[email protected]> Co-authored-by: Simon Prickett <[email protected]> Co-authored-by: Suze Shardlow <[email protected]> Co-authored-by: Joshua T <[email protected]> Co-authored-by: Aditya Rastogi <[email protected]> Co-authored-by: Rohan Kumar <[email protected]> Co-authored-by: Kalki <[email protected]> Co-authored-by: Chayim <[email protected]> Co-authored-by: Da-Jin Chu <[email protected]> Co-authored-by: Henrique Corrêa <[email protected]> Co-authored-by: Evert Pot <[email protected]> Co-authored-by: AnnAngela <[email protected]> Co-authored-by: Damien Arrachequesne <[email protected]> Co-authored-by: kjlis <[email protected]> Co-authored-by: Vojta Staněk <[email protected]> Co-authored-by: Guy Korland <[email protected]> Co-authored-by: Avital Fine <[email protected]>
1 parent 3790c6e commit 54f9d57

File tree

132 files changed

+5987
-1375
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+5987
-1375
lines changed

.github/workflows/documentation.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@ jobs:
1717
uses: actions/[email protected]
1818
- name: Install Packages
1919
run: npm ci
20+
- name: Build tests tools
21+
run: npm run build:tests-tools
2022
- name: Generate Documentation
2123
run: npm run documentation
22-
- name: Upload Documentation to Wiki
23-
uses: SwiftDocOrg/github-wiki-publish-action@v1
24-
with:
25-
path: documentation
24+
- name: Upload
25+
run: |
26+
git remote set-url origin https://git:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git
27+
npm run gh-pages
2628
env:
27-
GH_PERSONAL_ACCESS_TOKEN: ${{ secrets.BOT_PERSONAL_ACCESS_TOKEN }}
29+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
30+

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
- name: Build tests tools
3535
run: npm run build:tests-tools
3636
- name: Run Tests
37-
run: npm run test -- --forbid-only --redis-version=${{ matrix.redis-version }}
37+
run: npm run test -- -- --forbid-only --redis-version=${{ matrix.redis-version }}
3838
- name: Upload to Codecov
3939
run: |
4040
curl https://keybase.io/codecovsecurity/pgp_keys.asc | gpg --no-default-keyring --keyring trustedkeys.gpg --import

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ dist/
66
node_modules/
77
.DS_Store
88
dump.rdb
9+
documentation/

README.md

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# Node-Redis
22

3-
[![Tests](https://img.shields.io/github/workflow/status/redis/node-redis/Tests/master.svg?label=tests)](https://codecov.io/gh/redis/node-redis)
3+
[![Tests](https://img.shields.io/github/workflow/status/redis/node-redis/Tests/master.svg?label=tests)](https://github.com/redis/node-redis/actions/workflows/tests.yml)
44
[![Coverage](https://codecov.io/gh/redis/node-redis/branch/master/graph/badge.svg?token=xcfqHhJC37)](https://codecov.io/gh/redis/node-redis)
5-
[![License](https://img.shields.io/github/license/redis/node-redis.svg)](https://codecov.io/gh/redis/node-redis)
6-
[![Chat](https://img.shields.io/discord/697882427875393627.svg)](https://discord.gg/XMMVgxUm)
5+
[![License](https://img.shields.io/github/license/redis/node-redis.svg)](https://github.com/redis/node-redis/blob/master/LICENSE)
6+
[![LGTM alerts](https://img.shields.io/lgtm/alerts/g/redis/node-redis.svg?logo=LGTM)](https://lgtm.com/projects/g/redis/node-redis/alerts)
7+
[![Chat](https://img.shields.io/discord/697882427875393627.svg)](https://discord.gg/redis)
78

89
node-redis is a modern, high performance [Redis](https://redis.io) client for Node.js with built-in support for Redis 6.2 commands and modules including [RediSearch](https://redisearch.io) and [RedisJSON](https://redisjson.io).
910

@@ -180,7 +181,7 @@ This works with `HSCAN`, `SSCAN`, and `ZSCAN` too:
180181
```typescript
181182
for await (const { field, value } of client.hScanIterator('hash')) {}
182183
for await (const member of client.sScanIterator('set')) {}
183-
for await (const { score, member } of client.zScanIterator('sorted-set')) {}
184+
for await (const { score, value } of client.zScanIterator('sorted-set')) {}
184185
```
185186

186187
You can override the default options by providing a configuration object:
@@ -277,6 +278,20 @@ await Promise.all([
277278

278279
Check out the [Clustering Guide](./docs/clustering.md) when using Node Redis to connect to a Redis Cluster.
279280

281+
### Events
282+
283+
The Node Redis client class is an Nodejs EventEmitter and it emits an event each time the network status changes:
284+
285+
| Event name | Scenes | Parameters |
286+
|--------------|-------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------|
287+
| connect | The client is initiating a connection to the server. | _undefined_ |
288+
| ready | The client successfully initiated the connection to the server. | _undefined_ |
289+
| end | The client disconnected the connection to the server via `.quit()` or `.disconnect()`. | _undefined_ |
290+
| error | When a network error has occurred, such as unable to connect to the server or the connection closed unexpectedly. | The error object, such as `SocketClosedUnexpectedlyError: Socket closed unexpectedly` or `Error: connect ECONNREFUSED [IP]:[PORT]` |
291+
| reconnecting | The client is trying to reconnect to the server. | _undefined_ |
292+
293+
The client will not emit any other events beyond those listed above.
294+
280295
## Supported Redis versions
281296

282297
Node Redis is supported with the following versions of Redis:
@@ -292,12 +307,13 @@ Node Redis is supported with the following versions of Redis:
292307
293308
## Packages
294309

295-
| Name | Description |
296-
|-----------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
297-
| [redis](./) | [![Downloads](https://img.shields.io/npm/dm/redis.svg)](https://www.npmjs.com/package/redis/v/next) [![Version](https://img.shields.io/npm/v/redis/next.svg)](https://www.npmjs.com/package/redis/v/next) |
298-
| [@node-redis/client](./packages/client) | [![Downloads](https://img.shields.io/npm/dm/@node-redis/client.svg)](https://www.npmjs.com/package/@node-redis/client/v/next) [![Version](https://img.shields.io/npm/v/@node-redis/client/next.svg)](https://www.npmjs.com/package/@node-redis/client/v/next) |
299-
| [@node-redis/json](./packages/json) | [![Downloads](https://img.shields.io/npm/dm/@node-redis/json.svg)](https://www.npmjs.com/package/@node-redis/json/v/next) [![Version](https://img.shields.io/npm/v/@node-redis/json/next.svg)](https://www.npmjs.com/package/@node-redis/json/v/next) [Redis JSON](https://oss.redis.com/redisjson/) commands |
300-
| [@node-redis/search](./packages/search) | [![Downloads](https://img.shields.io/npm/dm/@node-redis/search.svg)](https://www.npmjs.com/package/@node-redis/search/v/next) [![Version](https://img.shields.io/npm/v/@node-redis/search/next.svg)](https://www.npmjs.com/package/@node-redis/search/v/next) [Redis Search](https://oss.redis.com/redisearch/) commands |
310+
| ----------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
311+
|---------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
312+
| [redis](./) | [![Downloads](https://img.shields.io/npm/dm/redis.svg)](https://www.npmjs.com/package/redis) [![Version](https://img.shields.io/npm/v/redis.svg)](https://www.npmjs.com/package/redis) |
313+
| [@node-redis/client](./packages/client) | [![Downloads](https://img.shields.io/npm/dm/@node-redis/client.svg)](https://www.npmjs.com/package/@node-redis/client) [![Version](https://img.shields.io/npm/v/@node-redis/client.svg)](https://www.npmjs.com/package/@node-redis/client) [![Docs](https://img.shields.io/badge/-documentation-dc382c)](https://redis.js.org/documentation/client/) |
314+
| [@node-redis/json](./packages/json) | [![Downloads](https://img.shields.io/npm/dm/@node-redis/json.svg)](https://www.npmjs.com/package/@node-redis/json) [![Version](https://img.shields.io/npm/v/@node-redis/json.svg)](https://www.npmjs.com/package/@node-redis/json) [![Docs](https://img.shields.io/badge/-documentation-dc382c)](https://redis.js.org/documentation/json/) [Redis JSON](https://oss.redis.com/redisjson/) commands |
315+
| [@node-redis/search](./packages/search) | [![Downloads](https://img.shields.io/npm/dm/@node-redis/search.svg)](https://www.npmjs.com/package/@node-redis/search) [![Version](https://img.shields.io/npm/v/@node-redis/search.svg)](https://www.npmjs.com/package/@node-redis/search) [![Docs](https://img.shields.io/badge/-documentation-dc382c)](https://redis.js.org/documentation/search/) [Redis Search](https://oss.redis.com/redisearch/) commands |
316+
| [@node-redis/time-series](./packages/time-series) | [![Downloads](https://img.shields.io/npm/dm/@node-redis/time-series.svg)](https://www.npmjs.com/package/@node-redis/time-series) [![Version](https://img.shields.io/npm/v/@node-redis/time-series.svg)](https://www.npmjs.com/package/@node-redis/time-series) [![Docs](https://img.shields.io/badge/-documentation-dc382c)](https://redis.js.org/documentation/time-series/) [Redis Time-Series](https://oss.redis.com/redistimeseries/) commands |
301317

302318
## Contributing
303319

benchmark/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.js.json

benchmark/lib/defaults.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
version: 0.1
2+
3+
remote:
4+
- type: oss-standalone
5+
- setup: redis-small
6+
7+
setups:
8+
- oss-standalone
9+
10+
spec:
11+
setups:
12+
- name: oss-standalone
13+
type: oss-standalone
14+
redis_topology:
15+
primaries: 1
16+
replicas: 0
17+
resources:
18+
requests:
19+
cpus: "1"
20+
memory: "10g"
21+
22+
exporter:
23+
output_path: "./*.js.json"
24+
redistimeseries:
25+
timemetric: "$.timestamp"
26+
metrics:
27+
- "$.p0"
28+
- "$.p50"
29+
- "$.p95"
30+
- "$.p99"
31+
- "$.p100"
32+
- "$.operationsPerSecond"

benchmark/lib/index.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import yargs from 'yargs';
2+
import { hideBin } from 'yargs/helpers';
3+
import { promises as fs } from 'fs';
4+
import { fork } from 'child_process';
5+
import { URL, fileURLToPath } from 'url';
6+
import { once } from 'events';
7+
import { extname } from 'path';
8+
9+
async function getPathChoices() {
10+
const dirents = await fs.readdir(new URL('.', import.meta.url), {
11+
withFileTypes: true
12+
});
13+
14+
const choices = [];
15+
for (const dirent of dirents) {
16+
if (!dirent.isDirectory()) continue;
17+
18+
choices.push(dirent.name);
19+
}
20+
21+
return choices;
22+
}
23+
24+
const argv = hideBin(process.argv);
25+
26+
async function getName() {
27+
return yargs(argv)
28+
.option('name', {
29+
demandOption: true,
30+
choices: await getPathChoices()
31+
})
32+
.parseSync().name;
33+
}
34+
35+
const runnerPath = fileURLToPath(new URL('runner.js', import.meta.url)),
36+
path = new URL(`${await getName()}/`, import.meta.url);
37+
38+
async function getMetadata() {
39+
try {
40+
return await import(new URL('index.js', path));
41+
} catch (err) {
42+
if (err.code === 'ERR_MODULE_NOT_FOUND') return;
43+
44+
throw err;
45+
}
46+
}
47+
48+
const metadata = await getMetadata(),
49+
timestamp = Date.now();
50+
51+
for (const file of await fs.readdir(path)) {
52+
if (file === 'index.js' || extname(file) !== '.js') continue;
53+
54+
const benchmarkProcess = fork(runnerPath, [
55+
...argv,
56+
'--path',
57+
fileURLToPath(path) + file
58+
]);
59+
60+
await once(benchmarkProcess, 'message');
61+
benchmarkProcess.send({
62+
metadata,
63+
timestamp
64+
});
65+
await once(benchmarkProcess, 'close');
66+
}

benchmark/lib/ping/ioredis.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import Redis from 'ioredis';
2+
3+
export default async (host) => {
4+
const client = new Redis({
5+
host,
6+
lazyConnect: true
7+
});
8+
9+
await client.connect();
10+
11+
return {
12+
benchmark() {
13+
return client.ping();
14+
},
15+
teardown() {
16+
return client.disconnect();
17+
}
18+
}
19+
};

benchmark/lib/ping/ping.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: "ping"
2+
3+
clientconfig:
4+
- command: |
5+
npm install -ws
6+
npm run build:tests-tools
7+
cd benchmark
8+
npm install
9+
npm run start -- --name ping --redis-server-host ${server_private_ip}

benchmark/lib/ping/v3.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { createClient } from 'redis-v3';
2+
import { once } from 'events';
3+
import { promisify } from 'util';
4+
5+
export default async (host) => {
6+
const client = createClient({ host }),
7+
pingAsync = promisify(client.ping).bind(client),
8+
quitAsync = promisify(client.quit).bind(client);
9+
10+
await once(client, 'connect');
11+
12+
return {
13+
benchmark() {
14+
return pingAsync();
15+
},
16+
teardown() {
17+
return quitAsync();
18+
}
19+
};
20+
21+
};

benchmark/lib/ping/v4.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { createClient } from '@node-redis/client';
2+
3+
export default async (host) => {
4+
const client = createClient({
5+
socket: {
6+
host
7+
}
8+
});
9+
10+
await client.connect();
11+
12+
return {
13+
benchmark() {
14+
return client.ping();
15+
},
16+
teardown() {
17+
return client.disconnect();
18+
}
19+
};
20+
};

benchmark/lib/runner.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import yargs from 'yargs';
2+
import { hideBin } from 'yargs/helpers';
3+
import { basename } from 'path';
4+
import { promises as fs } from 'fs';
5+
import * as hdr from 'hdr-histogram-js';
6+
hdr.initWebAssemblySync();
7+
8+
const { path, times, concurrency, 'redis-server-host': host } = yargs(hideBin(process.argv))
9+
.option('path', {
10+
type: 'string',
11+
demandOption: true
12+
})
13+
.option('times', {
14+
type: 'number',
15+
default: 1_000_000,
16+
demandOption: true
17+
})
18+
.option('concurrency', {
19+
type: 'number',
20+
default: 100,
21+
demandOption: true
22+
})
23+
.option('redis-server-host', {
24+
type: 'string'
25+
})
26+
.parseSync();
27+
28+
const [ { metadata, timestamp }, module ] = await Promise.all([
29+
new Promise(resolve => {
30+
process.once('message', resolve);
31+
process.send('ready');
32+
}),
33+
import(path)
34+
]),
35+
{ benchmark, teardown } = await module.default(host, metadata);
36+
37+
async function run(times) {
38+
return new Promise(resolve => {
39+
const histogram = hdr.build({ useWebAssembly: true });
40+
let num = 0,
41+
inProgress = 0;
42+
43+
async function run() {
44+
++inProgress;
45+
++num;
46+
47+
const start = process.hrtime.bigint();
48+
await benchmark(metadata);
49+
histogram.recordValue(Number(process.hrtime.bigint() - start));
50+
--inProgress;
51+
52+
if (num < times) {
53+
run();
54+
} else if (inProgress === 0) {
55+
resolve(histogram);
56+
}
57+
}
58+
59+
const toInitiate = Math.min(concurrency, times);
60+
for (let i = 0; i < toInitiate; i++) {
61+
run();
62+
}
63+
});
64+
}
65+
66+
// warmup
67+
await run(Math.min(times * 0.1, 10_000));
68+
69+
// benchmark
70+
const benchmarkStart = process.hrtime.bigint(),
71+
histogram = await run(times),
72+
benchmarkNanoseconds = process.hrtime.bigint() - benchmarkStart,
73+
json = {
74+
timestamp,
75+
operationsPerSecond: times / Number(benchmarkNanoseconds) * 1_000_000_000,
76+
p0: histogram.getValueAtPercentile(0),
77+
p50: histogram.getValueAtPercentile(50),
78+
p95: histogram.getValueAtPercentile(95),
79+
p99: histogram.getValueAtPercentile(99),
80+
p100: histogram.getValueAtPercentile(100)
81+
};
82+
console.log(`[${basename(path)}]:`);
83+
console.table(json);
84+
await fs.writeFile(`${path}.json`, JSON.stringify(json));
85+
86+
await teardown();
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: "set-get-delete-string-1KB"
2+
3+
clientconfig:
4+
- command: |
5+
npm install -ws
6+
npm run build:tests-tools
7+
cd benchmark
8+
npm install
9+
npm run start -- --name set-get-delete-string --size 1024 --redis-server-host ${server_private_ip}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: "set-get-delete-string-1MB"
2+
3+
clientconfig:
4+
- command: |
5+
npm install -ws
6+
npm run build:tests-tools
7+
cd benchmark
8+
npm install
9+
npm run start -- --name set-get-delete-string --size 1048576 --redis-server-host ${server_private_ip}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: "set-get-delete-string-8B"
2+
3+
clientconfig:
4+
- command: |
5+
npm install -ws
6+
npm run build:tests-tools
7+
cd benchmark
8+
npm install
9+
npm run start -- --name set-get-delete-string --size 8 --redis-server-host ${server_private_ip}

0 commit comments

Comments
 (0)