Skip to content

Commit

Permalink
v4.0.1 (#1779)
Browse files Browse the repository at this point in the history
* 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 <leibale1998@gmail.com>

* 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 <leibale1998@gmail.com>

* 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 <leibale1998@gmail.com>

* 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 <leibale1998@gmail.com>

* 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 <simon@crudworks.org>

* 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 <adit.rastogi2014@gmail.com>

* Update(examples): fix case, add timeout, update readme

Signed-off-by: Aditya Rastogi <adit.rastogi2014@gmail.com>

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 <simon@redislabs.com>

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 <simon@redislabs.com>

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 client@1.0.0-rc.0

* revert d32f1ed

* fix .npmignore

* replace @redis with @node-redis

* Release client@1.0.0-rc.0

* update json & search version

* Release json@1.0.0-rc.0

* Release search@1.0.0-rc.0

* update dependencies

* Release redis@4.0.0-rc.4

* 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 client@1.0.0

* npm update

* Release search@1.0.0

* update sub modules

* Release redis@4.0.0

* 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 <simon@crudworks.org>

* Update docs/v3-to-v4.md

Co-authored-by: Simon Prickett <simon@crudworks.org>

* Update docs/v3-to-v4.md

Co-authored-by: Simon Prickett <simon@crudworks.org>

* Update docs/v3-to-v4.md

Co-authored-by: Simon Prickett <simon@crudworks.org>

* Update docs/v3-to-v4.md

Co-authored-by: Simon Prickett <simon@crudworks.org>

* Update docs/v3-to-v4.md

Co-authored-by: Simon Prickett <simon@crudworks.org>

Co-authored-by: Leibale Eidelman <leibale1998@gmail.com>
Co-authored-by: Simon Prickett <simon@crudworks.org>

* 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 <leibale1998@gmail.com>

* 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 <leibale1998@gmail.com>

* 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 <leibale1998@gmail.com>

* fix #1774 #1767 - update docs

Co-authored-by: Chayim <chayim@users.noreply.github.com>

* Search commands (#1778)

* ft.alter

* ft.profile

* clean code

* fix generated documentation

* fix documentation workflow

* fix documentation workflow

* fix documentation workflow

* update CHANGELOG

* Release client@1.0.1

* update tsconfig.json

* Release json@1.0.1

* Release search@1.0.1

* fix time-series .release-it.json

* add @node-redis/time-series to README

* add time-series to all in one

* Release redis@4.0.1

Co-authored-by: Richard Samuelsson <noobtoothfairy@gmail.com>
Co-authored-by: mustard <mhqnwt@gmail.com>
Co-authored-by: Simon Prickett <simon@redislabs.com>
Co-authored-by: Simon Prickett <simon@crudworks.org>
Co-authored-by: Suze Shardlow <SuzeShardlow@users.noreply.github.com>
Co-authored-by: Joshua T <buildingsomethingfun@gmail.com>
Co-authored-by: Aditya Rastogi <adit.rastogi2014@gmail.com>
Co-authored-by: Rohan Kumar <rohan.kr20@gmail.com>
Co-authored-by: Kalki <shashank.kviit@gmail.com>
Co-authored-by: Chayim <chayim@users.noreply.github.com>
Co-authored-by: Da-Jin Chu <dajinchu@gmail.com>
Co-authored-by: Henrique Corrêa <75134774+HeCorr@users.noreply.github.com>
Co-authored-by: Evert Pot <me@evertpot.com>
Co-authored-by: AnnAngela <naganjue@vip.qq.com>
Co-authored-by: Damien Arrachequesne <damien.arrachequesne@gmail.com>
Co-authored-by: kjlis <kjlis@users.noreply.github.com>
Co-authored-by: Vojta Staněk <stanekv01@gmail.com>
Co-authored-by: Guy Korland <gkorland@gmail.com>
Co-authored-by: Avital Fine <79420960+AvitalFineRedis@users.noreply.github.com>
  • Loading branch information
20 people committed Dec 13, 2021
1 parent 3790c6e commit 54f9d57
Show file tree
Hide file tree
Showing 132 changed files with 5,987 additions and 1,375 deletions.
13 changes: 8 additions & 5 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ jobs:
uses: actions/setup-node@v2.3.0
- name: Install Packages
run: npm ci
- name: Build tests tools
run: npm run build:tests-tools
- name: Generate Documentation
run: npm run documentation
- name: Upload Documentation to Wiki
uses: SwiftDocOrg/github-wiki-publish-action@v1
with:
path: documentation
- name: Upload
run: |
git remote set-url origin https://git:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git
npm run gh-pages
env:
GH_PERSONAL_ACCESS_TOKEN: ${{ secrets.BOT_PERSONAL_ACCESS_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- name: Build tests tools
run: npm run build:tests-tools
- name: Run Tests
run: npm run test -- --forbid-only --redis-version=${{ matrix.redis-version }}
run: npm run test -- -- --forbid-only --redis-version=${{ matrix.redis-version }}
- name: Upload to Codecov
run: |
curl https://keybase.io/codecovsecurity/pgp_keys.asc | gpg --no-default-keyring --keyring trustedkeys.gpg --import
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ dist/
node_modules/
.DS_Store
dump.rdb
documentation/
36 changes: 26 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Node-Redis

[![Tests](https://img.shields.io/github/workflow/status/redis/node-redis/Tests/master.svg?label=tests)](https://codecov.io/gh/redis/node-redis)
[![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)
[![Coverage](https://codecov.io/gh/redis/node-redis/branch/master/graph/badge.svg?token=xcfqHhJC37)](https://codecov.io/gh/redis/node-redis)
[![License](https://img.shields.io/github/license/redis/node-redis.svg)](https://codecov.io/gh/redis/node-redis)
[![Chat](https://img.shields.io/discord/697882427875393627.svg)](https://discord.gg/XMMVgxUm)
[![License](https://img.shields.io/github/license/redis/node-redis.svg)](https://github.com/redis/node-redis/blob/master/LICENSE)
[![LGTM alerts](https://img.shields.io/lgtm/alerts/g/redis/node-redis.svg?logo=LGTM)](https://lgtm.com/projects/g/redis/node-redis/alerts)
[![Chat](https://img.shields.io/discord/697882427875393627.svg)](https://discord.gg/redis)

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).

Expand Down Expand Up @@ -180,7 +181,7 @@ This works with `HSCAN`, `SSCAN`, and `ZSCAN` too:
```typescript
for await (const { field, value } of client.hScanIterator('hash')) {}
for await (const member of client.sScanIterator('set')) {}
for await (const { score, member } of client.zScanIterator('sorted-set')) {}
for await (const { score, value } of client.zScanIterator('sorted-set')) {}
```

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

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

### Events

The Node Redis client class is an Nodejs EventEmitter and it emits an event each time the network status changes:

| Event name | Scenes | Parameters |
|--------------|-------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------|
| connect | The client is initiating a connection to the server. | _undefined_ |
| ready | The client successfully initiated the connection to the server. | _undefined_ |
| end | The client disconnected the connection to the server via `.quit()` or `.disconnect()`. | _undefined_ |
| 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]` |
| reconnecting | The client is trying to reconnect to the server. | _undefined_ |

The client will not emit any other events beyond those listed above.

## Supported Redis versions

Node Redis is supported with the following versions of Redis:
Expand All @@ -292,12 +307,13 @@ Node Redis is supported with the following versions of Redis:
## Packages

| Name | Description |
|-----------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [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) |
| [@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) |
| [@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 |
| [@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 |
| ----------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|---------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [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) |
| [@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/) |
| [@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 |
| [@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 |
| [@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 |

## Contributing

Expand Down
1 change: 1 addition & 0 deletions benchmark/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.js.json
32 changes: 32 additions & 0 deletions benchmark/lib/defaults.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version: 0.1

remote:
- type: oss-standalone
- setup: redis-small

setups:
- oss-standalone

spec:
setups:
- name: oss-standalone
type: oss-standalone
redis_topology:
primaries: 1
replicas: 0
resources:
requests:
cpus: "1"
memory: "10g"

exporter:
output_path: "./*.js.json"
redistimeseries:
timemetric: "$.timestamp"
metrics:
- "$.p0"
- "$.p50"
- "$.p95"
- "$.p99"
- "$.p100"
- "$.operationsPerSecond"
66 changes: 66 additions & 0 deletions benchmark/lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import { promises as fs } from 'fs';
import { fork } from 'child_process';
import { URL, fileURLToPath } from 'url';
import { once } from 'events';
import { extname } from 'path';

async function getPathChoices() {
const dirents = await fs.readdir(new URL('.', import.meta.url), {
withFileTypes: true
});

const choices = [];
for (const dirent of dirents) {
if (!dirent.isDirectory()) continue;

choices.push(dirent.name);
}

return choices;
}

const argv = hideBin(process.argv);

async function getName() {
return yargs(argv)
.option('name', {
demandOption: true,
choices: await getPathChoices()
})
.parseSync().name;
}

const runnerPath = fileURLToPath(new URL('runner.js', import.meta.url)),
path = new URL(`${await getName()}/`, import.meta.url);

async function getMetadata() {
try {
return await import(new URL('index.js', path));
} catch (err) {
if (err.code === 'ERR_MODULE_NOT_FOUND') return;

throw err;
}
}

const metadata = await getMetadata(),
timestamp = Date.now();

for (const file of await fs.readdir(path)) {
if (file === 'index.js' || extname(file) !== '.js') continue;

const benchmarkProcess = fork(runnerPath, [
...argv,
'--path',
fileURLToPath(path) + file
]);

await once(benchmarkProcess, 'message');
benchmarkProcess.send({
metadata,
timestamp
});
await once(benchmarkProcess, 'close');
}
19 changes: 19 additions & 0 deletions benchmark/lib/ping/ioredis.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Redis from 'ioredis';

export default async (host) => {
const client = new Redis({
host,
lazyConnect: true
});

await client.connect();

return {
benchmark() {
return client.ping();
},
teardown() {
return client.disconnect();
}
}
};
9 changes: 9 additions & 0 deletions benchmark/lib/ping/ping.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: "ping"

clientconfig:
- command: |
npm install -ws
npm run build:tests-tools
cd benchmark
npm install
npm run start -- --name ping --redis-server-host ${server_private_ip}
21 changes: 21 additions & 0 deletions benchmark/lib/ping/v3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { createClient } from 'redis-v3';
import { once } from 'events';
import { promisify } from 'util';

export default async (host) => {
const client = createClient({ host }),
pingAsync = promisify(client.ping).bind(client),
quitAsync = promisify(client.quit).bind(client);

await once(client, 'connect');

return {
benchmark() {
return pingAsync();
},
teardown() {
return quitAsync();
}
};

};
20 changes: 20 additions & 0 deletions benchmark/lib/ping/v4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { createClient } from '@node-redis/client';

export default async (host) => {
const client = createClient({
socket: {
host
}
});

await client.connect();

return {
benchmark() {
return client.ping();
},
teardown() {
return client.disconnect();
}
};
};
86 changes: 86 additions & 0 deletions benchmark/lib/runner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import { basename } from 'path';
import { promises as fs } from 'fs';
import * as hdr from 'hdr-histogram-js';
hdr.initWebAssemblySync();

const { path, times, concurrency, 'redis-server-host': host } = yargs(hideBin(process.argv))
.option('path', {
type: 'string',
demandOption: true
})
.option('times', {
type: 'number',
default: 1_000_000,
demandOption: true
})
.option('concurrency', {
type: 'number',
default: 100,
demandOption: true
})
.option('redis-server-host', {
type: 'string'
})
.parseSync();

const [ { metadata, timestamp }, module ] = await Promise.all([
new Promise(resolve => {
process.once('message', resolve);
process.send('ready');
}),
import(path)
]),
{ benchmark, teardown } = await module.default(host, metadata);

async function run(times) {
return new Promise(resolve => {
const histogram = hdr.build({ useWebAssembly: true });
let num = 0,
inProgress = 0;

async function run() {
++inProgress;
++num;

const start = process.hrtime.bigint();
await benchmark(metadata);
histogram.recordValue(Number(process.hrtime.bigint() - start));
--inProgress;

if (num < times) {
run();
} else if (inProgress === 0) {
resolve(histogram);
}
}

const toInitiate = Math.min(concurrency, times);
for (let i = 0; i < toInitiate; i++) {
run();
}
});
}

// warmup
await run(Math.min(times * 0.1, 10_000));

// benchmark
const benchmarkStart = process.hrtime.bigint(),
histogram = await run(times),
benchmarkNanoseconds = process.hrtime.bigint() - benchmarkStart,
json = {
timestamp,
operationsPerSecond: times / Number(benchmarkNanoseconds) * 1_000_000_000,
p0: histogram.getValueAtPercentile(0),
p50: histogram.getValueAtPercentile(50),
p95: histogram.getValueAtPercentile(95),
p99: histogram.getValueAtPercentile(99),
p100: histogram.getValueAtPercentile(100)
};
console.log(`[${basename(path)}]:`);
console.table(json);
await fs.writeFile(`${path}.json`, JSON.stringify(json));

await teardown();
9 changes: 9 additions & 0 deletions benchmark/lib/set-get-delete-string/1KB.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: "set-get-delete-string-1KB"

clientconfig:
- command: |
npm install -ws
npm run build:tests-tools
cd benchmark
npm install
npm run start -- --name set-get-delete-string --size 1024 --redis-server-host ${server_private_ip}
9 changes: 9 additions & 0 deletions benchmark/lib/set-get-delete-string/1MB.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: "set-get-delete-string-1MB"

clientconfig:
- command: |
npm install -ws
npm run build:tests-tools
cd benchmark
npm install
npm run start -- --name set-get-delete-string --size 1048576 --redis-server-host ${server_private_ip}
9 changes: 9 additions & 0 deletions benchmark/lib/set-get-delete-string/8B.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: "set-get-delete-string-8B"

clientconfig:
- command: |
npm install -ws
npm run build:tests-tools
cd benchmark
npm install
npm run start -- --name set-get-delete-string --size 8 --redis-server-host ${server_private_ip}

0 comments on commit 54f9d57

Please sign in to comment.