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

Release 4.0.0-rc.3 (#1678)

* 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 54124793ad

* 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

Co-authored-by: Richard Samuelsson <noobtoothfairy@gmail.com>
This commit is contained in:
Leibale Eidelman
2021-10-11 19:40:14 -04:00
committed by GitHub
parent e592d9403d
commit 199285aa71
258 changed files with 2715 additions and 2779 deletions

View File

@@ -1,21 +0,0 @@
---
title: ⚠️ Bug report
labels: needs-triage
---
### Issue
> Describe your issue here
---
### Environment
<!-- e.g. "node --version" -->
- **Node.js Version**: `VERSION_HERE`
<!-- e.g. "redis-server --version" -->
- **Redis Server Version**: `VERSION_HERE`
<!-- e.g. Windows 10, Mac OSX 10.15.2 -->
- **Platform**: `PLATFORM_HERE`

15
.github/ISSUE_TEMPLATE/bug-report.md vendored Normal file
View File

@@ -0,0 +1,15 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: Bug
assignees: ''
---
<!-- Describe your issue here -->
**Environment:**
- **Node.js Version**: <!-- e.g. "node --version" -->
- **Redis Server Version**: <!-- e.g. "redis-server --version" -->
- **Node Redis Version**: <!-- e.g. "npm ls redis" -->
- **Platform**: <!-- e.g. Ubuntu 20.04.3, Windows 10, Mac OS 11.6 -->

View File

@@ -0,0 +1,7 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: Bug
assignees: ''
---

View File

@@ -1,12 +1,13 @@
.vscode/
.idea/
node_modules/
.nyc_output
.nyc_output/
coverage/
dump.rdb
documentation/
CONTRIBUTING.md
tsconfig.json
.deepsource.toml
.nycrc.json
benchmark/
.github/

View File

@@ -53,7 +53,7 @@ The above code connects to localhost on port 6379. To connect to a different hos
```typescript
createClient({
url: 'redis://alice:foobared@awesome.redis.server:6380',
url: 'redis://alice:foobared@awesome.redis.server:6380'
});
```
@@ -78,7 +78,7 @@ Modifiers to commands are specified using a JavaScript object:
```typescript
await client.set('key', 'value', {
EX: 10,
NX: true,
NX: true
});
```
@@ -181,12 +181,9 @@ for await (const key of client.scanIterator()) {
This works with `HSCAN`, `SSCAN`, and `ZSCAN` too:
```typescript
for await (const member of client.hScanIterator('hash')) {
}
for await (const { field, value } of client.sScanIterator('set')) {
}
for await (const { member, score } of client.zScanIterator('sorted-set')) {
}
for await (const member of client.hScanIterator('hash')) {}
for await (const { field, value } of client.sScanIterator('set')) {}
for await (const { member, score } of client.zScanIterator('sorted-set')) {}
```
You can override the default options by providing a configuration object:
@@ -204,7 +201,8 @@ client.scanIterator({
Define new functions using [Lua scripts](https://redis.io/commands/eval) which execute on the Redis server:
```typescript
import { createClient, defineScript } from 'redis';
import { createClient } from 'redis';
import { defineScript } from 'redis/lua-script';
(async () => {
const client = createClient({
@@ -218,9 +216,9 @@ import { createClient, defineScript } from 'redis';
},
transformReply(reply: number): number {
return reply;
},
}),
},
}
})
}
});
await client.connect();
@@ -241,14 +239,12 @@ import { createCluster } from 'redis';
const cluster = createCluster({
rootNodes: [
{
host: '10.0.0.1',
port: 30001,
url: 'redis://10.0.0.1:30001'
},
{
host: '10.0.0.2',
port: 30002,
},
],
url: 'redis://10.0.0.2:30002'
}
]
});
cluster.on('error', (err) => console.log('Redis Cluster Error', err));
@@ -274,7 +270,7 @@ Of course, if you don't do something with your Promises you're certain to get [u
```typescript
await Promise.all([
client.set('Tm9kZSBSZWRpcw==', 'users:1'),
client.sAdd('users:1:tokens', 'Tm9kZSBSZWRpcw=='),
client.sAdd('users:1:tokens', 'Tm9kZSBSZWRpcw==')
]);
```

16
SECURITY.md Normal file
View File

@@ -0,0 +1,16 @@
# Security Policy
## Supported Versions
Node Redis is generally backwards compatible with very few exceptions, so we recommend users to always use the latest version to experience stability, performance and security.
| Version | Supported |
| ------- | ------------------ |
| 4.0.x | :white_check_mark: |
| 3.1.x | :white_check_mark: |
| < 3.1 | :x: |
## Reporting a Vulnerability
If you believe youve discovered a serious vulnerability, please contact the Node Redis core team at redis@redis.io. We will evaluate your report and if necessary issue a fix and an advisory. If the issue was previously undisclosed,
well also mention your name in the credits.

View File

@@ -4,40 +4,42 @@
"requires": true,
"packages": {
"": {
"name": "benchmark",
"license": "ISC",
"dependencies": {
"@probe.gl/bench": "^3.4.0",
"benny": "^3.6.15",
"benny": "3.6.15",
"v3": "npm:redis@3.1.2",
"v4": "file:../"
}
},
"..": {
"name": "redis",
"version": "4.0.0-next.5",
"version": "4.0.0-rc.2",
"license": "MIT",
"dependencies": {
"cluster-key-slot": "1.1.0",
"generic-pool": "3.8.2",
"redis-parser": "3.0.0",
"yallist": "4.0.0"
},
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "^1.0.1",
"@tsconfig/node12": "^1.0.9",
"@types/mocha": "^9.0.0",
"@types/node": "^16.4.5",
"@types/sinon": "^10.0.2",
"@types/node": "^16.10.3",
"@types/sinon": "^10.0.4",
"@types/which": "^2.0.1",
"@types/yallist": "^4.0.1",
"mocha": "^9.0.3",
"mocha": "^9.1.2",
"nyc": "^15.1.0",
"release-it": "^14.10.1",
"release-it": "^14.11.6",
"sinon": "^11.1.2",
"source-map-support": "^0.5.19",
"ts-node": "^10.1.0",
"typedoc": "^0.21.4",
"typedoc-github-wiki-theme": "^0.5.1",
"typedoc-plugin-markdown": "^3.10.4",
"typescript": "^4.3.5",
"source-map-support": "^0.5.20",
"ts-node": "^10.3.0",
"typedoc": "^0.22.5",
"typedoc-github-wiki-theme": "^0.6.0",
"typedoc-plugin-markdown": "^3.11.3",
"typescript": "^4.4.3",
"which": "^2.0.2"
},
"engines": {
@@ -81,34 +83,6 @@
"fast-deep-equal": "^3.1.1"
}
},
"node_modules/@babel/runtime": {
"version": "7.14.8",
"resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.14.8.tgz",
"integrity": "sha512-twj3L8Og5SaCRCErB4x4ajbvBIVV77CGeFglHpeg5WC5FF8TZzBWXtTJ4MqaD9QszLYTtr+IsaAL2rEUevb+eg==",
"dependencies": {
"regenerator-runtime": "^0.13.4"
},
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/@probe.gl/bench": {
"version": "3.4.0",
"resolved": "https://registry.npmjs.org/@probe.gl/bench/-/bench-3.4.0.tgz",
"integrity": "sha512-S7iNPz5G3zEfEP0S4SAMvtj+dwP7EWfVBaA8Cy5CVIgM1lnpUbXvqoAJxlVEedNC32Icxwq65XQheufy1Zzmug==",
"dependencies": {
"@babel/runtime": "^7.0.0",
"probe.gl": "3.4.0"
}
},
"node_modules/@probe.gl/stats": {
"version": "3.4.0",
"resolved": "https://registry.npmjs.org/@probe.gl/stats/-/stats-3.4.0.tgz",
"integrity": "sha512-Gl37r9qGuiKadIvTZdSZvzCNOttJYw6RcY1oT0oDuB8r2uhuZAdSMQRQTy9FTinp6MY6O9wngGnV6EpQ8wSBAw==",
"dependencies": {
"@babel/runtime": "^7.0.0"
}
},
"node_modules/ansi-escapes": {
"version": "4.3.2",
"resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-4.3.2.tgz",
@@ -124,9 +98,9 @@
}
},
"node_modules/ansi-regex": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz",
"integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==",
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
"integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
"engines": {
"node": ">=8"
}
@@ -223,9 +197,9 @@
}
},
"node_modules/denque": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/denque/-/denque-1.5.0.tgz",
"integrity": "sha512-CYiCSgIF1p6EUByQPlGkKnP1M9g0ZV3qMIrqMqZqdwazygIA/YP2vrbcyl1h/WppKJTdl1F85cXIle+394iDAQ==",
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/denque/-/denque-1.5.1.tgz",
"integrity": "sha512-XwE+iZ4D6ZUB7mfYRMb5wByE8L74HCn30FBN7sWnXksWc1LO1bPDl67pBR9o/kC4z/xSNAwkMYcGgqDV3BE3Hw==",
"engines": {
"node": ">=0.10"
}
@@ -255,9 +229,9 @@
}
},
"node_modules/graceful-fs": {
"version": "4.2.6",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.6.tgz",
"integrity": "sha512-nTnJ528pbqxYanhpDYsi4Rd8MAeaBA67+RZ10CM1m3bTAVFEDcd5AuA4a6W5YkGZ1iNXHzZz8T6TBKLeBuNriQ=="
"version": "4.2.8",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.8.tgz",
"integrity": "sha512-qkIilPUYcNhJpd33n0GBXTB1MMPp14TxEsEs0pTrsSVucApsYzW5V+Q8Qxhik6KU3evy+qkAAowTByymK0avdg=="
},
"node_modules/is-fullwidth-code-point": {
"version": "3.0.0",
@@ -366,9 +340,9 @@
"integrity": "sha512-fnWVljUchTro6RiCFvCXBbNhJc2NijN7oIQxbwsyL0buWJPG85v81ehlHI9fXrJsMNgTofEoWIQeClKpgxFLrg=="
},
"node_modules/prettier": {
"version": "2.3.2",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.3.2.tgz",
"integrity": "sha512-lnJzDfJ66zkMy58OL5/NY5zp70S7Nz6KqcKkXYzn2tMVrNxvbqaBpg7H3qHaLxCJ5lNMsGuM8+ohS7cZrthdLQ==",
"version": "2.4.1",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.4.1.tgz",
"integrity": "sha512-9fbDAXSBcc6Bs1mZrDYb3XKzDLm4EXXL9sC1LqKP5rZkT6KRr/rf9amVUcODVXgguK/isJz0d0hP72WeaKWsvA==",
"bin": {
"prettier": "bin-prettier.js"
},
@@ -376,15 +350,6 @@
"node": ">=10.13.0"
}
},
"node_modules/probe.gl": {
"version": "3.4.0",
"resolved": "https://registry.npmjs.org/probe.gl/-/probe.gl-3.4.0.tgz",
"integrity": "sha512-9CLByZATuhuG/Viq3ckfWU+dAhb7dMmjzsyCy4s7ds9ueTejcVRENxL197/XacOK/AN61YrEERB0QnouB0Qc0Q==",
"dependencies": {
"@babel/runtime": "^7.0.0",
"@probe.gl/stats": "3.4.0"
}
},
"node_modules/redis-commands": {
"version": "1.7.0",
"resolved": "https://registry.npmjs.org/redis-commands/-/redis-commands-1.7.0.tgz",
@@ -409,11 +374,6 @@
"node": ">=4"
}
},
"node_modules/regenerator-runtime": {
"version": "0.13.9",
"resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.9.tgz",
"integrity": "sha512-p3VT+cOEgxFsRRA9X4lkI1E+k2/CtnKtU4gcxyaCUreilL/vqI6CdZ3wxVUx3UOUg+gnUOQQcRI7BmSI656MYA=="
},
"node_modules/restore-cursor": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-3.1.0.tgz",
@@ -427,9 +387,9 @@
}
},
"node_modules/signal-exit": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.3.tgz",
"integrity": "sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA=="
"version": "3.0.5",
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.5.tgz",
"integrity": "sha512-KWcOiKeQj6ZyXx7zq4YxSMgHRlod4czeBQZrPb8OKcohcqAXShm7E20kEMle9WBt26hFcAf0qLOcp5zmY7kOqQ=="
},
"node_modules/slice-ansi": {
"version": "4.0.0",
@@ -453,24 +413,24 @@
"integrity": "sha512-IYsheLg6dasD3zT/w9+8Iq9tcIQqqu91ZIpJOnIEM25C3X/g4Tl8mhXwW2ZQpbrsJISr9+wizEYgsibN5/b32Q=="
},
"node_modules/string-width": {
"version": "4.2.2",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.2.tgz",
"integrity": "sha512-XBJbT3N4JhVumXE0eoLU9DCjcaF92KLNqTmFCnG1pf8duUxFGwtP6AD6nkjw9a3IdiRtL3E2w3JDiE/xi3vOeA==",
"version": "4.2.3",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
"integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==",
"dependencies": {
"emoji-regex": "^8.0.0",
"is-fullwidth-code-point": "^3.0.0",
"strip-ansi": "^6.0.0"
"strip-ansi": "^6.0.1"
},
"engines": {
"node": ">=8"
}
},
"node_modules/strip-ansi": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.0.tgz",
"integrity": "sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w==",
"version": "6.0.1",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz",
"integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==",
"dependencies": {
"ansi-regex": "^5.0.0"
"ansi-regex": "^5.0.1"
},
"engines": {
"node": ">=8"
@@ -570,31 +530,6 @@
"fast-deep-equal": "^3.1.1"
}
},
"@babel/runtime": {
"version": "7.14.8",
"resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.14.8.tgz",
"integrity": "sha512-twj3L8Og5SaCRCErB4x4ajbvBIVV77CGeFglHpeg5WC5FF8TZzBWXtTJ4MqaD9QszLYTtr+IsaAL2rEUevb+eg==",
"requires": {
"regenerator-runtime": "^0.13.4"
}
},
"@probe.gl/bench": {
"version": "3.4.0",
"resolved": "https://registry.npmjs.org/@probe.gl/bench/-/bench-3.4.0.tgz",
"integrity": "sha512-S7iNPz5G3zEfEP0S4SAMvtj+dwP7EWfVBaA8Cy5CVIgM1lnpUbXvqoAJxlVEedNC32Icxwq65XQheufy1Zzmug==",
"requires": {
"@babel/runtime": "^7.0.0",
"probe.gl": "3.4.0"
}
},
"@probe.gl/stats": {
"version": "3.4.0",
"resolved": "https://registry.npmjs.org/@probe.gl/stats/-/stats-3.4.0.tgz",
"integrity": "sha512-Gl37r9qGuiKadIvTZdSZvzCNOttJYw6RcY1oT0oDuB8r2uhuZAdSMQRQTy9FTinp6MY6O9wngGnV6EpQ8wSBAw==",
"requires": {
"@babel/runtime": "^7.0.0"
}
},
"ansi-escapes": {
"version": "4.3.2",
"resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-4.3.2.tgz",
@@ -604,9 +539,9 @@
}
},
"ansi-regex": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz",
"integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg=="
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
"integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ=="
},
"ansi-styles": {
"version": "4.3.0",
@@ -679,9 +614,9 @@
"integrity": "sha512-U7VdrJFnJgo4xjrHpTzu0yrHPGImdsmD95ZlgYSEajAn2JKzDhDTPG9kBTefmObL2w/ngeZnilk+OV9CG3d7UA=="
},
"denque": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/denque/-/denque-1.5.0.tgz",
"integrity": "sha512-CYiCSgIF1p6EUByQPlGkKnP1M9g0ZV3qMIrqMqZqdwazygIA/YP2vrbcyl1h/WppKJTdl1F85cXIle+394iDAQ=="
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/denque/-/denque-1.5.1.tgz",
"integrity": "sha512-XwE+iZ4D6ZUB7mfYRMb5wByE8L74HCn30FBN7sWnXksWc1LO1bPDl67pBR9o/kC4z/xSNAwkMYcGgqDV3BE3Hw=="
},
"emoji-regex": {
"version": "8.0.0",
@@ -705,9 +640,9 @@
}
},
"graceful-fs": {
"version": "4.2.6",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.6.tgz",
"integrity": "sha512-nTnJ528pbqxYanhpDYsi4Rd8MAeaBA67+RZ10CM1m3bTAVFEDcd5AuA4a6W5YkGZ1iNXHzZz8T6TBKLeBuNriQ=="
"version": "4.2.8",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.8.tgz",
"integrity": "sha512-qkIilPUYcNhJpd33n0GBXTB1MMPp14TxEsEs0pTrsSVucApsYzW5V+Q8Qxhik6KU3evy+qkAAowTByymK0avdg=="
},
"is-fullwidth-code-point": {
"version": "3.0.0",
@@ -783,18 +718,9 @@
"integrity": "sha512-fnWVljUchTro6RiCFvCXBbNhJc2NijN7oIQxbwsyL0buWJPG85v81ehlHI9fXrJsMNgTofEoWIQeClKpgxFLrg=="
},
"prettier": {
"version": "2.3.2",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.3.2.tgz",
"integrity": "sha512-lnJzDfJ66zkMy58OL5/NY5zp70S7Nz6KqcKkXYzn2tMVrNxvbqaBpg7H3qHaLxCJ5lNMsGuM8+ohS7cZrthdLQ=="
},
"probe.gl": {
"version": "3.4.0",
"resolved": "https://registry.npmjs.org/probe.gl/-/probe.gl-3.4.0.tgz",
"integrity": "sha512-9CLByZATuhuG/Viq3ckfWU+dAhb7dMmjzsyCy4s7ds9ueTejcVRENxL197/XacOK/AN61YrEERB0QnouB0Qc0Q==",
"requires": {
"@babel/runtime": "^7.0.0",
"@probe.gl/stats": "3.4.0"
}
"version": "2.4.1",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.4.1.tgz",
"integrity": "sha512-9fbDAXSBcc6Bs1mZrDYb3XKzDLm4EXXL9sC1LqKP5rZkT6KRr/rf9amVUcODVXgguK/isJz0d0hP72WeaKWsvA=="
},
"redis-commands": {
"version": "1.7.0",
@@ -814,11 +740,6 @@
"redis-errors": "^1.0.0"
}
},
"regenerator-runtime": {
"version": "0.13.9",
"resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.9.tgz",
"integrity": "sha512-p3VT+cOEgxFsRRA9X4lkI1E+k2/CtnKtU4gcxyaCUreilL/vqI6CdZ3wxVUx3UOUg+gnUOQQcRI7BmSI656MYA=="
},
"restore-cursor": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-3.1.0.tgz",
@@ -829,9 +750,9 @@
}
},
"signal-exit": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.3.tgz",
"integrity": "sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA=="
"version": "3.0.5",
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.5.tgz",
"integrity": "sha512-KWcOiKeQj6ZyXx7zq4YxSMgHRlod4czeBQZrPb8OKcohcqAXShm7E20kEMle9WBt26hFcAf0qLOcp5zmY7kOqQ=="
},
"slice-ansi": {
"version": "4.0.0",
@@ -849,21 +770,21 @@
"integrity": "sha512-IYsheLg6dasD3zT/w9+8Iq9tcIQqqu91ZIpJOnIEM25C3X/g4Tl8mhXwW2ZQpbrsJISr9+wizEYgsibN5/b32Q=="
},
"string-width": {
"version": "4.2.2",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.2.tgz",
"integrity": "sha512-XBJbT3N4JhVumXE0eoLU9DCjcaF92KLNqTmFCnG1pf8duUxFGwtP6AD6nkjw9a3IdiRtL3E2w3JDiE/xi3vOeA==",
"version": "4.2.3",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
"integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==",
"requires": {
"emoji-regex": "^8.0.0",
"is-fullwidth-code-point": "^3.0.0",
"strip-ansi": "^6.0.0"
"strip-ansi": "^6.0.1"
}
},
"strip-ansi": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.0.tgz",
"integrity": "sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w==",
"version": "6.0.1",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz",
"integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==",
"requires": {
"ansi-regex": "^5.0.0"
"ansi-regex": "^5.0.1"
}
},
"type-fest": {
@@ -891,23 +812,25 @@
"version": "file:..",
"requires": {
"@istanbuljs/nyc-config-typescript": "^1.0.1",
"@tsconfig/node12": "^1.0.9",
"@types/mocha": "^9.0.0",
"@types/node": "^16.4.5",
"@types/sinon": "^10.0.2",
"@types/node": "^16.10.3",
"@types/sinon": "^10.0.4",
"@types/which": "^2.0.1",
"@types/yallist": "^4.0.1",
"cluster-key-slot": "1.1.0",
"mocha": "^9.0.3",
"generic-pool": "3.8.2",
"mocha": "^9.1.2",
"nyc": "^15.1.0",
"redis-parser": "3.0.0",
"release-it": "^14.10.1",
"release-it": "^14.11.6",
"sinon": "^11.1.2",
"source-map-support": "^0.5.19",
"ts-node": "^10.1.0",
"typedoc": "^0.21.4",
"typedoc-github-wiki-theme": "^0.5.1",
"typedoc-plugin-markdown": "^3.10.4",
"typescript": "^4.3.5",
"source-map-support": "^0.5.20",
"ts-node": "^10.3.0",
"typedoc": "^0.22.5",
"typedoc-github-wiki-theme": "^0.6.0",
"typedoc-plugin-markdown": "^3.11.3",
"typescript": "^4.4.3",
"which": "^2.0.2",
"yallist": "4.0.0"
}

View File

@@ -10,7 +10,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"benny": "^3.6.15",
"benny": "3.6.15",
"v3": "npm:redis@3.1.2",
"v4": "file:../"
}

View File

@@ -6,5 +6,3 @@ export const createClient = RedisClient.create;
export const commandOptions = RedisClient.commandOptions;
export const createCluster = RedisCluster.create;
export { defineScript } from './lib/lua-script';

View File

@@ -1,7 +1,7 @@
import LinkedList from 'yallist';
import RedisParser from 'redis-parser';
import { AbortError } from './errors';
import { RedisReply } from './commands';
import { AbortError } from '../errors';
import { RedisCommandRawReply } from '../commands';
export interface QueueCommandOptions {
asap?: boolean;
@@ -107,7 +107,7 @@ export default class RedisCommandsQueue {
this.#maxLength = maxLength;
}
addCommand<T = RedisReply>(args: Array<string | Buffer>, options?: QueueCommandOptions, bufferMode?: boolean): Promise<T> {
addCommand<T = RedisCommandRawReply>(args: Array<string | Buffer>, options?: QueueCommandOptions, bufferMode?: boolean): Promise<T> {
if (this.#pubSubState.subscribing || this.#pubSubState.subscribed) {
return Promise.reject(new Error('Cannot send commands in PubSub mode'));
} else if (this.#maxLength && this.#waitingToBeSent.length + this.#waitingForReply.length >= this.#maxLength) {

233
lib/client/commands.ts Normal file
View File

@@ -0,0 +1,233 @@
import CLUSTER_COMMANDS from '../cluster/commands';
import * as ACL_CAT from '../commands/ACL_CAT';
import * as ACL_DELUSER from '../commands/ACL_DELUSER';
import * as ACL_GENPASS from '../commands/ACL_GENPASS';
import * as ACL_GETUSER from '../commands/ACL_GETUSER';
import * as ACL_LIST from '../commands/ACL_LIST';
import * as ACL_LOAD from '../commands/ACL_LOAD';
import * as ACL_LOG_RESET from '../commands/ACL_LOG_RESET';
import * as ACL_LOG from '../commands/ACL_LOG';
import * as ACL_SAVE from '../commands/ACL_SAVE';
import * as ACL_SETUSER from '../commands/ACL_SETUSER';
import * as ACL_USERS from '../commands/ACL_USERS';
import * as ACL_WHOAMI from '../commands/ACL_WHOAMI';
import * as ASKING from '../commands/ASKING';
import * as AUTH from '../commands/AUTH';
import * as BGREWRITEAOF from '../commands/BGREWRITEAOF';
import * as BGSAVE from '../commands/BGSAVE';
import * as CLIENT_ID from '../commands/CLIENT_ID';
import * as CLIENT_INFO from '../commands/CLIENT_INFO';
import * as CLUSTER_ADDSLOTS from '../commands/CLUSTER_ADDSLOTS';
import * as CLUSTER_FLUSHSLOTS from '../commands/CLUSTER_FLUSHSLOTS';
import * as CLUSTER_INFO from '../commands/CLUSTER_INFO';
import * as CLUSTER_NODES from '../commands/CLUSTER_NODES';
import * as CLUSTER_MEET from '../commands/CLUSTER_MEET';
import * as CLUSTER_RESET from '../commands/CLUSTER_RESET';
import * as CLUSTER_SETSLOT from '../commands/CLUSTER_SETSLOT';
import * as CLUSTER_SLOTS from '../commands/CLUSTER_SLOTS';
import * as COMMAND_COUNT from '../commands/COMMAND_COUNT';
import * as COMMAND_GETKEYS from '../commands/COMMAND_GETKEYS';
import * as COMMAND_INFO from '../commands/COMMAND_INFO';
import * as COMMAND from '../commands/COMMAND';
import * as CONFIG_GET from '../commands/CONFIG_GET';
import * as CONFIG_RESETASTAT from '../commands/CONFIG_RESETSTAT';
import * as CONFIG_REWRITE from '../commands/CONFIG_REWRITE';
import * as CONFIG_SET from '../commands/CONFIG_SET';
import * as DBSIZE from '../commands/DBSIZE';
import * as DISCARD from '../commands/DISCARD';
import * as ECHO from '../commands/ECHO';
import * as FAILOVER from '../commands/FAILOVER';
import * as FLUSHALL from '../commands/FLUSHALL';
import * as FLUSHDB from '../commands/FLUSHDB';
import * as HELLO from '../commands/HELLO';
import * as INFO from '../commands/INFO';
import * as KEYS from '../commands/KEYS';
import * as LASTSAVE from '../commands/LASTSAVE';
import * as LOLWUT from '../commands/LOLWUT';
import * as MEMOERY_DOCTOR from '../commands/MEMORY_DOCTOR';
import * as MEMORY_MALLOC_STATS from '../commands/MEMORY_MALLOC-STATS';
import * as MEMORY_PURGE from '../commands/MEMORY_PURGE';
import * as MEMORY_STATS from '../commands/MEMORY_STATS';
import * as MEMORY_USAGE from '../commands/MEMORY_USAGE';
import * as MODULE_LIST from '../commands/MODULE_LIST';
import * as MODULE_LOAD from '../commands/MODULE_LOAD';
import * as MODULE_UNLOAD from '../commands/MODULE_UNLOAD';
import * as MOVE from '../commands/MOVE';
import * as PING from '../commands/PING';
import * as PUBSUB_CHANNELS from '../commands/PUBSUB_CHANNELS';
import * as PUBSUB_NUMPAT from '../commands/PUBSUB_NUMPAT';
import * as PUBSUB_NUMSUB from '../commands/PUBSUB_NUMSUB';
import * as RANDOMKEY from '../commands/RANDOMKEY';
import * as READONLY from '../commands/READONLY';
import * as READWRITE from '../commands/READWRITE';
import * as REPLICAOF from '../commands/REPLICAOF';
import * as RESTORE_ASKING from '../commands/RESTORE-ASKING';
import * as ROLE from '../commands/ROLE';
import * as SAVE from '../commands/SAVE';
import * as SCAN from '../commands/SCAN';
import * as SCRIPT_DEBUG from '../commands/SCRIPT_DEBUG';
import * as SCRIPT_EXISTS from '../commands/SCRIPT_EXISTS';
import * as SCRIPT_FLUSH from '../commands/SCRIPT_FLUSH';
import * as SCRIPT_KILL from '../commands/SCRIPT_KILL';
import * as SCRIPT_LOAD from '../commands/SCRIPT_LOAD';
import * as SHUTDOWN from '../commands/SHUTDOWN';
import * as SWAPDB from '../commands/SWAPDB';
import * as TIME from '../commands/TIME';
import * as UNWATCH from '../commands/UNWATCH';
import * as WAIT from '../commands/WAIT';
export default {
...CLUSTER_COMMANDS,
ACL_CAT,
aclCat: ACL_CAT,
ACL_DELUSER,
aclDelUser: ACL_DELUSER,
ACL_GENPASS,
aclGenPass: ACL_GENPASS,
ACL_GETUSER,
aclGetUser: ACL_GETUSER,
ACL_LIST,
aclList: ACL_LIST,
ACL_LOAD,
aclLoad: ACL_LOAD,
ACL_LOG_RESET,
aclLogReset: ACL_LOG_RESET,
ACL_LOG,
aclLog: ACL_LOG,
ACL_SAVE,
aclSave: ACL_SAVE,
ACL_SETUSER,
aclSetUser: ACL_SETUSER,
ACL_USERS,
aclUsers: ACL_USERS,
ACL_WHOAMI,
aclWhoAmI: ACL_WHOAMI,
ASKING,
asking: ASKING,
AUTH,
auth: AUTH,
BGREWRITEAOF,
bgRewriteAof: BGREWRITEAOF,
BGSAVE,
bgSave: BGSAVE,
CLIENT_ID,
clientId: CLIENT_ID,
CLIENT_INFO,
clientInfo: CLIENT_INFO,
CLUSTER_ADDSLOTS,
clusterAddSlots: CLUSTER_ADDSLOTS,
CLUSTER_FLUSHSLOTS,
clusterFlushSlots: CLUSTER_FLUSHSLOTS,
CLUSTER_INFO,
clusterInfo: CLUSTER_INFO,
CLUSTER_NODES,
clusterNodes: CLUSTER_NODES,
CLUSTER_MEET,
clusterMeet: CLUSTER_MEET,
CLUSTER_RESET,
clusterReset: CLUSTER_RESET,
CLUSTER_SETSLOT,
clusterSetSlot: CLUSTER_SETSLOT,
CLUSTER_SLOTS,
clusterSlots: CLUSTER_SLOTS,
COMMAND_COUNT,
commandCount: COMMAND_COUNT,
COMMAND_GETKEYS,
commandGetKeys: COMMAND_GETKEYS,
COMMAND_INFO,
commandInfo: COMMAND_INFO,
COMMAND,
command: COMMAND,
CONFIG_GET,
configGet: CONFIG_GET,
CONFIG_RESETASTAT,
configResetStat: CONFIG_RESETASTAT,
CONFIG_REWRITE,
configRewrite: CONFIG_REWRITE,
CONFIG_SET,
configSet: CONFIG_SET,
DBSIZE,
dbSize: DBSIZE,
DISCARD,
discard: DISCARD,
ECHO,
echo: ECHO,
FAILOVER,
failover: FAILOVER,
FLUSHALL,
flushAll: FLUSHALL,
FLUSHDB,
flushDb: FLUSHDB,
HELLO,
hello: HELLO,
INFO,
info: INFO,
KEYS,
keys: KEYS,
LASTSAVE,
lastSave: LASTSAVE,
LOLWUT,
lolwut: LOLWUT,
MEMOERY_DOCTOR,
memoryDoctor: MEMOERY_DOCTOR,
'MEMORY_MALLOC-STATS': MEMORY_MALLOC_STATS,
memoryMallocStats: MEMORY_MALLOC_STATS,
MEMORY_PURGE,
memoryPurge: MEMORY_PURGE,
MEMORY_STATS,
memoryStats: MEMORY_STATS,
MEMORY_USAGE,
memoryUsage: MEMORY_USAGE,
MODULE_LIST,
moduleList: MODULE_LIST,
MODULE_LOAD,
moduleLoad: MODULE_LOAD,
MODULE_UNLOAD,
moduleUnload: MODULE_UNLOAD,
MOVE,
move: MOVE,
PING,
ping: PING,
PUBSUB_CHANNELS,
pubSubChannels: PUBSUB_CHANNELS,
PUBSUB_NUMPAT,
pubSubNumPat: PUBSUB_NUMPAT,
PUBSUB_NUMSUB,
pubSubNumSub: PUBSUB_NUMSUB,
RANDOMKEY,
randomKey: RANDOMKEY,
READONLY,
readonly: READONLY,
READWRITE,
readwrite: READWRITE,
REPLICAOF,
replicaOf: REPLICAOF,
'RESTORE-ASKING': RESTORE_ASKING,
restoreAsking: RESTORE_ASKING,
ROLE,
role: ROLE,
SAVE,
save: SAVE,
SCAN,
scan: SCAN,
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,
SHUTDOWN,
shutdown: SHUTDOWN,
SWAPDB,
swapDb: SWAPDB,
TIME,
time: TIME,
UNWATCH,
unwatch: UNWATCH,
WAIT,
wait: WAIT,
};

View File

@@ -1,11 +1,11 @@
import { strict as assert, AssertionError } from 'assert';
import { once } from 'events';
import { itWithClient, TEST_REDIS_SERVERS, TestRedisServers, waitTillBeenCalled, isRedisVersionGreaterThan } from './test-utils';
import RedisClient from './client';
import { AbortError, ClientClosedError, ConnectionTimeoutError, WatchError } from './errors';
import { defineScript } from './lua-script';
import { itWithClient, TEST_REDIS_SERVERS, TestRedisServers, waitTillBeenCalled, isRedisVersionGreaterThan } from '../test-utils';
import RedisClient from '.';
import { AbortError, ClientClosedError, ConnectionTimeoutError, WatchError } from '../errors';
import { defineScript } from '../lua-script';
import { spy } from 'sinon';
import { RedisNetSocketOptions } from './socket';
import { RedisNetSocketOptions } from '../client/socket';
export const SQUARE_SCRIPT = defineScript({
NUMBER_OF_KEYS: 0,
@@ -366,6 +366,15 @@ describe('Client', () => {
WatchError
);
});
itWithClient(TestRedisServers.OPEN, 'execAsPipeline', async client => {
assert.deepEqual(
await client.multi()
.ping()
.exec(true),
['PONG']
);
});
});
it('scripts', async () => {

View File

@@ -1,79 +1,81 @@
import COMMANDS from './commands';
import { RedisCommand, RedisCommandArguments, RedisCommandRawReply, RedisCommandReply, RedisModules, RedisPlugins, RedisScript, RedisScripts } from '../commands';
import RedisSocket, { RedisSocketOptions, RedisNetSocketOptions, RedisTlsSocketOptions } from './socket';
import RedisCommandsQueue, { PubSubListener, PubSubSubscribeCommands, PubSubUnsubscribeCommands, QueueCommandOptions } from './commands-queue';
import COMMANDS, { TransformArgumentsReply } from './commands';
import { RedisCommand, RedisModules, RedisReply } from './commands';
import RedisMultiCommand, { MultiQueuedCommand, RedisMultiCommandType } from './multi-command';
import RedisClientMultiCommand, { RedisClientMultiCommandType } from './multi-command';
import { RedisMultiQueuedCommand } from '../multi-command';
import EventEmitter from 'events';
import { CommandOptions, commandOptions, isCommandOptions } from './command-options';
import { RedisLuaScript, RedisLuaScripts } from './lua-script';
import { ScanOptions, ZMember } from './commands/generic-transformers';
import { ScanCommandOptions } from './commands/SCAN';
import { HScanTuple } from './commands/HSCAN';
import { encodeCommand, extendWithDefaultCommands, extendWithModulesAndScripts, transformCommandArguments } from './commander';
import { CommandOptions, commandOptions, isCommandOptions } from '../command-options';
import { ScanOptions, ZMember } from '../commands/generic-transformers';
import { ScanCommandOptions } from '../commands/SCAN';
import { HScanTuple } from '../commands/HSCAN';
import { encodeCommand, extendWithCommands, extendWithModulesAndScripts, transformCommandArguments, transformCommandReply } from '../commander';
import { Pool, Options as PoolOptions, createPool } from 'generic-pool';
import { ClientClosedError } from './errors';
import { ClientClosedError } from '../errors';
import { URL } from 'url';
export interface RedisClientOptions<M, S> {
export interface RedisClientOptions<M extends RedisModules, S extends RedisScripts> extends RedisPlugins<M, S> {
url?: string;
socket?: RedisSocketOptions;
username?: string;
password?: string;
database?: number;
modules?: M;
scripts?: S;
commandsQueueMaxLength?: number;
readonly?: boolean;
legacyMode?: boolean;
isolationPoolOptions?: PoolOptions;
}
export type RedisCommandSignature<C extends RedisCommand> =
(...args: Parameters<C['transformArguments']> | [options: CommandOptions<ClientCommandOptions>, ...rest: Parameters<C['transformArguments']>]) => Promise<ReturnType<C['transformReply']>>;
export type RedisClientCommandSignature<C extends RedisCommand> =
(...args: Parameters<C['transformArguments']> | [options: CommandOptions<ClientCommandOptions>, ...rest: Parameters<C['transformArguments']>]) => Promise<RedisCommandReply<C>>;
type WithCommands = {
[P in keyof typeof COMMANDS]: RedisCommandSignature<(typeof COMMANDS)[P]>;
[P in keyof typeof COMMANDS]: RedisClientCommandSignature<(typeof COMMANDS)[P]>;
};
type WithModules<M extends RedisModules> = {
export type WithModules<M extends RedisModules> = {
[P in keyof M]: {
[C in keyof M[P]]: RedisCommandSignature<M[P][C]>;
[C in keyof M[P]]: RedisClientCommandSignature<M[P][C]>;
};
};
type WithScripts<S extends RedisLuaScripts> = {
[P in keyof S]: RedisCommandSignature<S[P]>;
export type WithScripts<S extends RedisScripts> = {
[P in keyof S]: RedisClientCommandSignature<S[P]>;
};
export type WithPlugins<M extends RedisModules, S extends RedisLuaScripts> =
WithCommands & WithModules<M> & WithScripts<S>;
export type RedisClientType<M extends RedisModules = {}, S extends RedisScripts = {}> =
RedisClient<M, S> & WithCommands & WithModules<M> & WithScripts<S>;
export type RedisClientType<M extends RedisModules = {}, S extends RedisLuaScripts = {}> =
WithPlugins<M, S> & RedisClient<M, S>;
export type InstantiableRedisClient<M extends RedisModules, S extends RedisScripts> =
new (...args: ConstructorParameters<typeof RedisClient>) => RedisClientType<M, S>;
export interface ClientCommandOptions extends QueueCommandOptions {
isolated?: boolean;
}
export default class RedisClient<M extends RedisModules, S extends RedisLuaScripts> extends EventEmitter {
export default class RedisClient<M extends RedisModules, S extends RedisScripts> extends EventEmitter {
static commandOptions(options: ClientCommandOptions): CommandOptions<ClientCommandOptions> {
return commandOptions(options);
}
static create<M extends RedisModules = {}, S extends RedisLuaScripts = {}>(options?: RedisClientOptions<M, S>): RedisClientType<M, S> {
const Client = (<any>extendWithModulesAndScripts({
static extend<M extends RedisModules = {}, S extends RedisScripts = {}>(plugins?: RedisPlugins<M, S>): InstantiableRedisClient<M, S> {
const Client = <any>extendWithModulesAndScripts({
BaseClass: RedisClient,
modules: options?.modules,
modules: plugins?.modules,
modulesCommandsExecutor: RedisClient.prototype.commandsExecutor,
scripts: options?.scripts,
scripts: plugins?.scripts,
scriptsExecutor: RedisClient.prototype.scriptsExecutor
}));
});
if (Client !== RedisClient) {
Client.prototype.Multi = RedisMultiCommand.extend(options);
Client.prototype.Multi = RedisClientMultiCommand.extend(plugins);
}
return new Client(options);
return Client;
}
static create<M extends RedisModules = {}, S extends RedisScripts = {}>(options?: RedisClientOptions<M, S>): RedisClientType<M, S> {
return new (RedisClient.extend(options))(options);
}
static parseURL(url: string): RedisClientOptions<{}, {}> {
@@ -145,7 +147,9 @@ export default class RedisClient<M extends RedisModules, S extends RedisLuaScrip
this.#queue = this.#initiateQueue();
this.#isolationPool = createPool({
create: async () => {
const duplicate = this.duplicate();
const duplicate = this.duplicate({
isolationPoolOptions: undefined
});
await duplicate.connect();
return duplicate;
},
@@ -267,29 +271,33 @@ export default class RedisClient<M extends RedisModules, S extends RedisLuaScrip
};
}
duplicate(): RedisClientType<M, S> {
return new (Object.getPrototypeOf(this).constructor)(this.#options);
duplicate(overrides?: Partial<RedisClientOptions<M, S>>): RedisClientType<M, S> {
return new (Object.getPrototypeOf(this).constructor)({
...this.#options,
...overrides
});
}
async connect(): Promise<void> {
await this.#socket.connect();
}
async commandsExecutor(command: RedisCommand, args: Array<unknown>): Promise<ReturnType<typeof command['transformReply']>> {
async commandsExecutor(command: RedisCommand, args: Array<unknown>): Promise<RedisCommandReply<typeof command>> {
const { args: redisArgs, options } = transformCommandArguments<ClientCommandOptions>(command, args);
return command.transformReply(
return transformCommandReply(
command,
await this.#sendCommand(redisArgs, options, command.BUFFER_MODE),
redisArgs.preserve,
redisArgs.preserve
);
}
sendCommand<T = RedisReply>(args: TransformArgumentsReply, options?: ClientCommandOptions, bufferMode?: boolean): Promise<T> {
sendCommand<T = RedisCommandRawReply>(args: RedisCommandArguments, options?: ClientCommandOptions, bufferMode?: boolean): Promise<T> {
return this.#sendCommand(args, options, bufferMode);
}
// using `#sendCommand` cause `sendCommand` is overwritten in legacy mode
async #sendCommand<T = RedisReply>(args: TransformArgumentsReply, options?: ClientCommandOptions, bufferMode?: boolean): Promise<T> {
async #sendCommand<T = RedisCommandRawReply>(args: RedisCommandArguments, options?: ClientCommandOptions, bufferMode?: boolean): Promise<T> {
if (!this.#socket.isOpen) {
throw new ClientClosedError();
}
@@ -308,16 +316,17 @@ export default class RedisClient<M extends RedisModules, S extends RedisLuaScrip
return await promise;
}
async scriptsExecutor(script: RedisLuaScript, args: Array<unknown>): Promise<ReturnType<typeof script['transformReply']>> {
async scriptsExecutor(script: RedisScript, args: Array<unknown>): Promise<RedisCommandReply<typeof script>> {
const { args: redisArgs, options } = transformCommandArguments<ClientCommandOptions>(script, args);
return script.transformReply(
return transformCommandReply(
script,
await this.executeScript(script, redisArgs, options, script.BUFFER_MODE),
redisArgs.preserve
);
}
async executeScript(script: RedisLuaScript, args: TransformArgumentsReply, options?: ClientCommandOptions, bufferMode?: boolean): Promise<ReturnType<typeof script['transformReply']>> {
async executeScript(script: RedisScript, args: RedisCommandArguments, options?: ClientCommandOptions, bufferMode?: boolean): Promise<RedisCommandReply<typeof script>> {
try {
return await this.#sendCommand([
'EVALSHA',
@@ -339,8 +348,6 @@ export default class RedisClient<M extends RedisModules, S extends RedisLuaScrip
}
}
async SELECT(db: number): Promise<void>;
async SELECT(options: CommandOptions<ClientCommandOptions>, db: number): Promise<void>;
async SELECT(options?: any, db?: any): Promise<void> {
@@ -427,14 +434,14 @@ export default class RedisClient<M extends RedisModules, S extends RedisLuaScrip
return this.#isolationPool.use(fn);
}
multi(): RedisMultiCommandType<M, S> {
multi(): RedisClientMultiCommandType<M, S> {
return new (this as any).Multi(
this.#multiExecutor.bind(this),
this.#options
this.multiExecutor.bind(this),
this.#options?.legacyMode
);
}
#multiExecutor(commands: Array<MultiQueuedCommand>, chainId?: symbol): Promise<Array<RedisReply>> {
multiExecutor(commands: Array<RedisMultiQueuedCommand>, chainId?: symbol): Promise<Array<RedisCommandRawReply>> {
const promise = Promise.all(
commands.map(({ args }) => {
return this.#queue.addCommand(args, RedisClient.commandOptions({
@@ -506,5 +513,9 @@ export default class RedisClient<M extends RedisModules, S extends RedisLuaScrip
}
}
extendWithDefaultCommands(RedisClient, RedisClient.prototype.commandsExecutor);
(RedisClient.prototype as any).Multi = RedisMultiCommand.extend();
extendWithCommands({
BaseClass: RedisClient,
commands: COMMANDS,
executor: RedisClient.prototype.commandsExecutor
});
(RedisClient.prototype as any).Multi = RedisClientMultiCommand;

132
lib/client/multi-command.ts Normal file
View File

@@ -0,0 +1,132 @@
import COMMANDS from './commands';
import { RedisCommand, RedisCommandArguments, RedisCommandRawReply, RedisModules, RedisPlugins, RedisScript, RedisScripts } from '../commands';
import RedisMultiCommand, { RedisMultiQueuedCommand } from '../multi-command';
import { extendWithCommands, extendWithModulesAndScripts } from '../commander';
type RedisClientMultiCommandSignature<C extends RedisCommand, M extends RedisModules, S extends RedisScripts> =
(...args: Parameters<C['transformArguments']>) => RedisClientMultiCommandType<M, S>;
type WithCommands<M extends RedisModules, S extends RedisScripts> = {
[P in keyof typeof COMMANDS]: RedisClientMultiCommandSignature<(typeof COMMANDS)[P], M, S>
};
type WithModules<M extends RedisModules, S extends RedisScripts> = {
[P in keyof M]: {
[C in keyof M[P]]: RedisClientMultiCommandSignature<M[P][C], M, S>;
};
};
type WithScripts<M extends RedisModules, S extends RedisScripts> = {
[P in keyof S]: RedisClientMultiCommandSignature<S[P], M, S>
};
export type RedisClientMultiCommandType<M extends RedisModules = {}, S extends RedisScripts = {}> =
RedisClientMultiCommand & WithCommands<M, S> & WithModules<M, S> & WithScripts<M, S>;
export type RedisClientMultiExecutor = (queue: Array<RedisMultiQueuedCommand>, chainId?: symbol) => Promise<Array<RedisCommandRawReply>>;
export default class RedisClientMultiCommand {
readonly #multi = new RedisMultiCommand();
readonly #executor: RedisClientMultiExecutor;
static extend<M extends RedisModules, S extends RedisScripts>(
plugins?: RedisPlugins<M, S>
): new (...args: ConstructorParameters<typeof RedisMultiCommand>) => RedisClientMultiCommandType<M, S> {
return <any>extendWithModulesAndScripts({
BaseClass: RedisClientMultiCommand,
modules: plugins?.modules,
modulesCommandsExecutor: RedisClientMultiCommand.prototype.commandsExecutor,
scripts: plugins?.scripts,
scriptsExecutor: RedisClientMultiCommand.prototype.scriptsExecutor
});
}
readonly v4: Record<string, any> = {};
constructor(executor: RedisClientMultiExecutor, legacyMode = false) {
this.#executor = executor;
if (legacyMode) {
this.#legacyMode();
}
}
#legacyMode(): void {
this.v4.addCommand = this.addCommand.bind(this);
(this as any).addCommand = (...args: Array<string | Buffer | Array<string | Buffer>>): this => {
this.#multi.addCommand(args.flat());
return this;
};
this.v4.exec = this.exec.bind(this);
(this as any).exec = (callback?: (err: Error | null, replies?: Array<unknown>) => unknown): void => {
this.v4.exec()
.then((reply: Array<unknown>) => {
if (!callback) return;
callback(null, reply);
})
.catch((err: Error) => {
if (!callback) {
// this.emit('error', err);
return;
}
callback(err);
});
};
for (const name of Object.keys(COMMANDS)) {
this.#defineLegacyCommand(name);
}
}
#defineLegacyCommand(name: string): void {
(this as any).v4[name] = (this as any)[name].bind(this.v4);
(this as any)[name] = (...args: Array<unknown>): void => (this as any).addCommand(name, args);
}
commandsExecutor(command: RedisCommand, args: Array<unknown>): this {
return this.addCommand(
command.transformArguments(...args),
command.transformReply
);
}
addCommand(args: RedisCommandArguments, transformReply?: RedisCommand['transformReply']): this {
this.#multi.addCommand(args, transformReply);
return this;
}
scriptsExecutor(script: RedisScript, args: Array<unknown>): this {
this.#multi.addScript(script, args);
return this;
}
async exec(execAsPipeline = false): Promise<Array<RedisCommandRawReply>> {
if (execAsPipeline) {
return this.execAsPipeline();
}
const commands = this.#multi.exec();
if (!commands) return [];
return this.#multi.handleExecReplies(
await this.#executor(commands, RedisMultiCommand.generateChainId())
);
}
EXEC = this.exec;
async execAsPipeline(): Promise<Array<RedisCommandRawReply>> {
if (!this.#multi.queue.length) return [];
return this.#multi.transformReplies(
await this.#executor(this.#multi.queue)
);
}
}
extendWithCommands({
BaseClass: RedisClientMultiCommand,
commands: COMMANDS,
executor: RedisClientMultiCommand.prototype.commandsExecutor
});

View File

@@ -1,8 +1,8 @@
import EventEmitter from 'events';
import net from 'net';
import tls from 'tls';
import { ConnectionTimeoutError, ClientClosedError } from './errors';
import { promiseTimeout } from './utils';
import { ConnectionTimeoutError, ClientClosedError } from '../errors';
import { promiseTimeout } from '../utils';
export interface RedisSocketCommonOptions {
connectTimeout?: number;

View File

@@ -1,17 +1,15 @@
import calculateSlot from 'cluster-key-slot';
import RedisClient, { RedisClientType } from './client';
import { RedisSocketOptions } from './socket';
import { RedisClusterMasterNode, RedisClusterReplicaNode } from './commands/CLUSTER_NODES';
import { RedisClusterOptions } from './cluster';
import { RedisModules } from './commands';
import { RedisLuaScripts } from './lua-script';
import RedisClient, { InstantiableRedisClient, RedisClientType } from '../client';
import { RedisClusterMasterNode, RedisClusterReplicaNode } from '../commands/CLUSTER_NODES';
import { RedisClusterClientOptions, RedisClusterOptions } from '.';
import { RedisModules, RedisScripts } from '../commands';
export interface ClusterNode<M extends RedisModules, S extends RedisLuaScripts> {
export interface ClusterNode<M extends RedisModules, S extends RedisScripts> {
id: string;
client: RedisClientType<M, S>;
}
interface SlotNodes<M extends RedisModules, S extends RedisLuaScripts> {
interface SlotNodes<M extends RedisModules, S extends RedisScripts> {
master: ClusterNode<M, S>;
replicas: Array<ClusterNode<M, S>>;
clientIterator: IterableIterator<RedisClientType<M, S>> | undefined;
@@ -19,41 +17,41 @@ interface SlotNodes<M extends RedisModules, S extends RedisLuaScripts> {
type OnError = (err: unknown) => void;
export default class RedisClusterSlots<M extends RedisModules, S extends RedisLuaScripts> {
readonly #options: RedisClusterOptions;
export default class RedisClusterSlots<M extends RedisModules, S extends RedisScripts> {
readonly #options: RedisClusterOptions<M, S>;
readonly #Client: InstantiableRedisClient<M, S>;
readonly #onError: OnError;
readonly #nodeByUrl = new Map<string, ClusterNode<M, S>>();
readonly #slots: Array<SlotNodes<M, S>> = [];
constructor(options: RedisClusterOptions, onError: OnError) {
constructor(options: RedisClusterOptions<M, S>, onError: OnError) {
this.#options = options;
this.#Client = RedisClient.extend(options);
this.#onError = onError;
}
async connect(): Promise<void> {
for (const rootNode of this.#options.rootNodes) {
if (await this.#discoverNodes(rootNode)) return;
if (await this.#discoverNodes(this.#clientOptionsDefaults(rootNode))) return;
}
throw new Error('None of the root nodes is available');
}
async discover(startWith: RedisClientType<M, S>): Promise<void> {
if (await this.#discoverNodes(startWith.options?.socket)) return;
if (await this.#discoverNodes(startWith.options)) return;
for (const { client } of this.#nodeByUrl.values()) {
if (client === startWith) continue;
if (await this.#discoverNodes(client.options?.socket)) return;
if (await this.#discoverNodes(client.options)) return;
}
throw new Error('None of the cluster nodes is available');
}
async #discoverNodes(socketOptions?: RedisSocketOptions): Promise<boolean> {
const client = RedisClient.create({
socket: socketOptions
});
async #discoverNodes(clientOptions?: RedisClusterClientOptions): Promise<boolean> {
const client = new this.#Client(clientOptions);
await client.connect();
@@ -101,6 +99,18 @@ export default class RedisClusterSlots<M extends RedisModules, S extends RedisLu
await Promise.all(promises);
}
#clientOptionsDefaults(options: RedisClusterClientOptions): RedisClusterClientOptions {
if (!this.#options.defaults) return options;
const merged = Object.assign({}, this.#options.defaults, options);
if (options.socket && this.#options.defaults.socket) {
Object.assign({}, this.#options.defaults.socket, options.socket);
}
return merged;
}
#initiateClientForNode(nodeData: RedisClusterMasterNode | RedisClusterReplicaNode, readonly: boolean, clientsInUse: Set<string>, promises: Array<Promise<void>>): ClusterNode<M, S> {
const url = `${nodeData.host}:${nodeData.port}`;
clientsInUse.add(url);
@@ -109,13 +119,15 @@ export default class RedisClusterSlots<M extends RedisModules, S extends RedisLu
if (!node) {
node = {
id: nodeData.id,
client: RedisClient.create({
client: new this.#Client(
this.#clientOptionsDefaults({
socket: {
host: nodeData.host,
port: nodeData.port
},
readonly
})
)
};
promises.push(node.client.connect());
this.#nodeByUrl.set(url, node);

535
lib/cluster/commands.ts Normal file
View File

@@ -0,0 +1,535 @@
import * as APPEND from '../commands/APPEND';
import * as BITCOUNT from '../commands/BITCOUNT';
import * as BITFIELD from '../commands/BITFIELD';
import * as BITOP from '../commands/BITOP';
import * as BITPOS from '../commands/BITPOS';
import * as BLMOVE from '../commands/BLMOVE';
import * as BLPOP from '../commands/BLPOP';
import * as BRPOP from '../commands/BRPOP';
import * as BRPOPLPUSH from '../commands/BRPOPLPUSH';
import * as BZPOPMAX from '../commands/BZPOPMAX';
import * as BZPOPMIN from '../commands/BZPOPMIN';
import * as COPY from '../commands/COPY';
import * as DECR from '../commands/DECR';
import * as DECRBY from '../commands/DECRBY';
import * as DEL from '../commands/DEL';
import * as DUMP from '../commands/DUMP';
import * as EVAL from '../commands/EVAL';
import * as EVALSHA from '../commands/EVALSHA';
import * as EXISTS from '../commands/EXISTS';
import * as EXPIRE from '../commands/EXPIRE';
import * as EXPIREAT from '../commands/EXPIREAT';
import * as GEOADD from '../commands/GEOADD';
import * as GEODIST from '../commands/GEODIST';
import * as GEOHASH from '../commands/GEOHASH';
import * as GEOPOS from '../commands/GEOPOS';
import * as GEOSEARCH_WITH from '../commands/GEOSEARCH_WITH';
import * as GEOSEARCH from '../commands/GEOSEARCH';
import * as GEOSEARCHSTORE from '../commands/GEOSEARCHSTORE';
import * as GET_BUFFER from '../commands/GET_BUFFER';
import * as GET from '../commands/GET';
import * as GETBIT from '../commands/GETBIT';
import * as GETDEL from '../commands/GETDEL';
import * as GETEX from '../commands/GETEX';
import * as GETRANGE from '../commands/GETRANGE';
import * as GETSET from '../commands/GETSET';
import * as HDEL from '../commands/HDEL';
import * as HEXISTS from '../commands/HEXISTS';
import * as HGET from '../commands/HGET';
import * as HGETALL from '../commands/HGETALL';
import * as HINCRBY from '../commands/HINCRBY';
import * as HINCRBYFLOAT from '../commands/HINCRBYFLOAT';
import * as HKEYS from '../commands/HKEYS';
import * as HLEN from '../commands/HLEN';
import * as HMGET from '../commands/HMGET';
import * as HRANDFIELD_COUNT_WITHVALUES from '../commands/HRANDFIELD_COUNT_WITHVALUES';
import * as HRANDFIELD_COUNT from '../commands/HRANDFIELD_COUNT';
import * as HRANDFIELD from '../commands/HRANDFIELD';
import * as HSCAN from '../commands/HSCAN';
import * as HSET from '../commands/HSET';
import * as HSETNX from '../commands/HSETNX';
import * as HSTRLEN from '../commands/HSTRLEN';
import * as HVALS from '../commands/HVALS';
import * as INCR from '../commands/INCR';
import * as INCRBY from '../commands/INCRBY';
import * as INCRBYFLOAT from '../commands/INCRBYFLOAT';
import * as LINDEX from '../commands/LINDEX';
import * as LINSERT from '../commands/LINSERT';
import * as LLEN from '../commands/LLEN';
import * as LMOVE from '../commands/LMOVE';
import * as LPOP_COUNT from '../commands/LPOP_COUNT';
import * as LPOP from '../commands/LPOP';
import * as LPOS_COUNT from '../commands/LPOS_COUNT';
import * as LPOS from '../commands/LPOS';
import * as LPUSH from '../commands/LPUSH';
import * as LPUSHX from '../commands/LPUSHX';
import * as LRANGE from '../commands/LRANGE';
import * as LREM from '../commands/LREM';
import * as LSET from '../commands/LSET';
import * as LTRIM from '../commands/LTRIM';
import * as MGET from '../commands/MGET';
import * as MIGRATE from '../commands/MIGRATE';
import * as MSET from '../commands/MSET';
import * as MSETNX from '../commands/MSETNX';
import * as PERSIST from '../commands/PERSIST';
import * as PEXPIRE from '../commands/PEXPIRE';
import * as PEXPIREAT from '../commands/PEXPIREAT';
import * as PFADD from '../commands/PFADD';
import * as PFCOUNT from '../commands/PFCOUNT';
import * as PFMERGE from '../commands/PFMERGE';
import * as PSETEX from '../commands/PSETEX';
import * as PTTL from '../commands/PTTL';
import * as PUBLISH from '../commands/PUBLISH';
import * as RENAME from '../commands/RENAME';
import * as RENAMENX from '../commands/RENAMENX';
import * as RPOP_COUNT from '../commands/RPOP_COUNT';
import * as RPOP from '../commands/RPOP';
import * as RPOPLPUSH from '../commands/RPOPLPUSH';
import * as RPUSH from '../commands/RPUSH';
import * as RPUSHX from '../commands/RPUSHX';
import * as SADD from '../commands/SADD';
import * as SCARD from '../commands/SCARD';
import * as SDIFF from '../commands/SDIFF';
import * as SDIFFSTORE from '../commands/SDIFFSTORE';
import * as SET from '../commands/SET';
import * as SETBIT from '../commands/SETBIT';
import * as SETEX from '../commands/SETEX';
import * as SETNX from '../commands/SETNX';
import * as SETRANGE from '../commands/SETRANGE';
import * as SINTER from '../commands/SINTER';
import * as SINTERSTORE from '../commands/SINTERSTORE';
import * as SISMEMBER from '../commands/SISMEMBER';
import * as SMEMBERS from '../commands/SMEMBERS';
import * as SMISMEMBER from '../commands/SMISMEMBER';
import * as SMOVE from '../commands/SMOVE';
import * as SORT from '../commands/SORT';
import * as SPOP from '../commands/SPOP';
import * as SRANDMEMBER_COUNT from '../commands/SRANDMEMBER_COUNT';
import * as SRANDMEMBER from '../commands/SRANDMEMBER';
import * as SREM from '../commands/SREM';
import * as SSCAN from '../commands/SSCAN';
import * as STRLEN from '../commands/STRLEN';
import * as SUNION from '../commands/SUNION';
import * as SUNIONSTORE from '../commands/SUNIONSTORE';
import * as TOUCH from '../commands/TOUCH';
import * as TTL from '../commands/TTL';
import * as TYPE from '../commands/TYPE';
import * as UNLINK from '../commands/UNLINK';
import * as WATCH from '../commands/WATCH';
import * as XACK from '../commands/XACK';
import * as XADD from '../commands/XADD';
import * as XAUTOCLAIM_JUSTID from '../commands/XAUTOCLAIM_JUSTID';
import * as XAUTOCLAIM from '../commands/XAUTOCLAIM';
import * as XCLAIM from '../commands/XCLAIM';
import * as XCLAIM_JUSTID from '../commands/XCLAIM_JUSTID';
import * as XDEL from '../commands/XDEL';
import * as XGROUP_CREATE from '../commands/XGROUP_CREATE';
import * as XGROUP_CREATECONSUMER from '../commands/XGROUP_CREATECONSUMER';
import * as XGROUP_DELCONSUMER from '../commands/XGROUP_DELCONSUMER';
import * as XGROUP_DESTROY from '../commands/XGROUP_DESTROY';
import * as XGROUP_SETID from '../commands/XGROUP_SETID';
import * as XINFO_CONSUMERS from '../commands/XINFO_CONSUMERS';
import * as XINFO_GROUPS from '../commands/XINFO_GROUPS';
import * as XINFO_STREAM from '../commands/XINFO_STREAM';
import * as XLEN from '../commands/XLEN';
import * as XPENDING_RANGE from '../commands/XPENDING_RANGE';
import * as XPENDING from '../commands/XPENDING';
import * as XRANGE from '../commands/XRANGE';
import * as XREAD from '../commands/XREAD';
import * as XREADGROUP from '../commands/XREADGROUP';
import * as XREVRANGE from '../commands/XREVRANGE';
import * as XTRIM from '../commands/XTRIM';
import * as ZADD from '../commands/ZADD';
import * as ZCARD from '../commands/ZCARD';
import * as ZCOUNT from '../commands/ZCOUNT';
import * as ZDIFF_WITHSCORES from '../commands/ZDIFF_WITHSCORES';
import * as ZDIFF from '../commands/ZDIFF';
import * as ZDIFFSTORE from '../commands/ZDIFFSTORE';
import * as ZINCRBY from '../commands/ZINCRBY';
import * as ZINTER_WITHSCORES from '../commands/ZINTER_WITHSCORES';
import * as ZINTER from '../commands/ZINTER';
import * as ZINTERSTORE from '../commands/ZINTERSTORE';
import * as ZLEXCOUNT from '../commands/ZLEXCOUNT';
import * as ZMSCORE from '../commands/ZMSCORE';
import * as ZPOPMAX_COUNT from '../commands/ZPOPMAX_COUNT';
import * as ZPOPMAX from '../commands/ZPOPMAX';
import * as ZPOPMIN_COUNT from '../commands/ZPOPMIN_COUNT';
import * as ZPOPMIN from '../commands/ZPOPMIN';
import * as ZRANDMEMBER_COUNT_WITHSCORES from '../commands/ZRANDMEMBER_COUNT_WITHSCORES';
import * as ZRANDMEMBER_COUNT from '../commands/ZRANDMEMBER_COUNT';
import * as ZRANDMEMBER from '../commands/ZRANDMEMBER';
import * as ZRANGE_WITHSCORES from '../commands/ZRANGE_WITHSCORES';
import * as ZRANGE from '../commands/ZRANGE';
import * as ZRANGEBYLEX from '../commands/ZRANGEBYLEX';
import * as ZRANGEBYSCORE_WITHSCORES from '../commands/ZRANGEBYSCORE_WITHSCORES';
import * as ZRANGEBYSCORE from '../commands/ZRANGEBYSCORE';
import * as ZRANGESTORE from '../commands/ZRANGESTORE';
import * as ZRANK from '../commands/ZRANK';
import * as ZREM from '../commands/ZREM';
import * as ZREMRANGEBYLEX from '../commands/ZREMRANGEBYLEX';
import * as ZREMRANGEBYRANK from '../commands/ZREMRANGEBYRANK';
import * as ZREMRANGEBYSCORE from '../commands/ZREMRANGEBYSCORE';
import * as ZREVRANK from '../commands/ZREVRANK';
import * as ZSCAN from '../commands/ZSCAN';
import * as ZSCORE from '../commands/ZSCORE';
import * as ZUNION_WITHSCORES from '../commands/ZUNION_WITHSCORES';
import * as ZUNION from '../commands/ZUNION';
import * as ZUNIONSTORE from '../commands/ZUNIONSTORE';
export default {
APPEND,
append: APPEND,
BITCOUNT,
bitCount: BITCOUNT,
BITFIELD,
bitField: BITFIELD,
BITOP,
bitOp: BITOP,
BITPOS,
bitPos: BITPOS,
BLMOVE,
blMove: BLMOVE,
BLPOP,
blPop: BLPOP,
BRPOP,
brPop: BRPOP,
BRPOPLPUSH,
brPopLPush: BRPOPLPUSH,
BZPOPMAX,
bzPopMax: BZPOPMAX,
BZPOPMIN,
bzPopMin: BZPOPMIN,
COPY,
copy: COPY,
DECR,
decr: DECR,
DECRBY,
decrBy: DECRBY,
DEL,
del: DEL,
DUMP,
dump: DUMP,
EVAL,
eval: EVAL,
EVALSHA,
evalSha: EVALSHA,
EXISTS,
exists: EXISTS,
EXPIRE,
expire: EXPIRE,
EXPIREAT,
expireAt: EXPIREAT,
GEOADD,
geoAdd: GEOADD,
GEODIST,
geoDist: GEODIST,
GEOHASH,
geoHash: GEOHASH,
GEOPOS,
geoPos: GEOPOS,
GEOSEARCH_WITH,
geoSearchWith: GEOSEARCH_WITH,
GEOSEARCH,
geoSearch: GEOSEARCH,
GEOSEARCHSTORE,
geoSearchStore: GEOSEARCHSTORE,
GET_BUFFER,
getBuffer: GET_BUFFER,
GET,
get: GET,
GETBIT,
getBit: GETBIT,
GETDEL,
getDel: GETDEL,
GETEX,
getEx: GETEX,
GETRANGE,
getRange: GETRANGE,
GETSET,
getSet: GETSET,
HDEL,
hDel: HDEL,
HEXISTS,
hExists: HEXISTS,
HGET,
hGet: HGET,
HGETALL,
hGetAll: HGETALL,
HINCRBY,
hIncrBy: HINCRBY,
HINCRBYFLOAT,
hIncrByFloat: HINCRBYFLOAT,
HKEYS,
hKeys: HKEYS,
HLEN,
hLen: HLEN,
HMGET,
hmGet: HMGET,
HRANDFIELD_COUNT_WITHVALUES,
hRandFieldCountWithValues: HRANDFIELD_COUNT_WITHVALUES,
HRANDFIELD_COUNT,
hRandFieldCount: HRANDFIELD_COUNT,
HRANDFIELD,
hRandField: HRANDFIELD,
HSCAN,
hScan: HSCAN,
HSET,
hSet: HSET,
HSETNX,
hSetNX: HSETNX,
HSTRLEN,
hStrLen: HSTRLEN,
HVALS,
hVals: HVALS,
INCR,
incr: INCR,
INCRBY,
incrBy: INCRBY,
INCRBYFLOAT,
incrByFloat: INCRBYFLOAT,
LINDEX,
lIndex: LINDEX,
LINSERT,
lInsert: LINSERT,
LLEN,
lLen: LLEN,
LMOVE,
lMove: LMOVE,
LPOP_COUNT,
lPopCount: LPOP_COUNT,
LPOP,
lPop: LPOP,
LPOS_COUNT,
lPosCount: LPOS_COUNT,
LPOS,
lPos: LPOS,
LPUSH,
lPush: LPUSH,
LPUSHX,
lPushX: LPUSHX,
LRANGE,
lRange: LRANGE,
LREM,
lRem: LREM,
LSET,
lSet: LSET,
LTRIM,
lTrim: LTRIM,
MGET,
mGet: MGET,
MIGRATE,
migrate: MIGRATE,
MSET,
mSet: MSET,
MSETNX,
mSetNX: MSETNX,
PERSIST,
persist: PERSIST,
PEXPIRE,
pExpire: PEXPIRE,
PEXPIREAT,
pExpireAt: PEXPIREAT,
PFADD,
pfAdd: PFADD,
PFCOUNT,
pfCount: PFCOUNT,
PFMERGE,
pfMerge: PFMERGE,
PSETEX,
pSetEx: PSETEX,
PTTL,
pTTL: PTTL,
PUBLISH,
publish: PUBLISH,
RENAME,
rename: RENAME,
RENAMENX,
renameNX: RENAMENX,
RPOP_COUNT,
rPopCount: RPOP_COUNT,
RPOP,
rPop: RPOP,
RPOPLPUSH,
rPopLPush: RPOPLPUSH,
RPUSH,
rPush: RPUSH,
RPUSHX,
rPushX: RPUSHX,
SADD,
sAdd: SADD,
SCARD,
sCard: SCARD,
SDIFF,
sDiff: SDIFF,
SDIFFSTORE,
sDiffStore: SDIFFSTORE,
SINTER,
sInter: SINTER,
SINTERSTORE,
sInterStore: SINTERSTORE,
SET,
set: SET,
SETBIT,
setBit: SETBIT,
SETEX,
setEx: SETEX,
SETNX,
setNX: SETNX,
SETRANGE,
setRange: SETRANGE,
SISMEMBER,
sIsMember: SISMEMBER,
SMEMBERS,
sMembers: SMEMBERS,
SMISMEMBER,
smIsMember: SMISMEMBER,
SMOVE,
sMove: SMOVE,
SORT,
sort: SORT,
SPOP,
sPop: SPOP,
SRANDMEMBER_COUNT,
sRandMemberCount: SRANDMEMBER_COUNT,
SRANDMEMBER,
sRandMember: SRANDMEMBER,
SREM,
sRem: SREM,
SSCAN,
sScan: SSCAN,
STRLEN,
strLen: STRLEN,
SUNION,
sUnion: SUNION,
SUNIONSTORE,
sUnionStore: SUNIONSTORE,
TOUCH,
touch: TOUCH,
TTL,
ttl: TTL,
TYPE,
type: TYPE,
UNLINK,
unlink: UNLINK,
WATCH,
watch: WATCH,
XACK,
xAck: XACK,
XADD,
xAdd: XADD,
XAUTOCLAIM_JUSTID,
xAutoClaimJustId: XAUTOCLAIM_JUSTID,
XAUTOCLAIM,
xAutoClaim: XAUTOCLAIM,
XCLAIM,
xClaim: XCLAIM,
XCLAIM_JUSTID,
xClaimJustId: XCLAIM_JUSTID,
XDEL,
xDel: XDEL,
XGROUP_CREATE,
xGroupCreate: XGROUP_CREATE,
XGROUP_CREATECONSUMER,
xGroupCreateConsumer: XGROUP_CREATECONSUMER,
XGROUP_DELCONSUMER,
xGroupDelConsumer: XGROUP_DELCONSUMER,
XGROUP_DESTROY,
xGroupDestroy: XGROUP_DESTROY,
XGROUP_SETID,
xGroupSetId: XGROUP_SETID,
XINFO_CONSUMERS,
xInfoConsumers: XINFO_CONSUMERS,
XINFO_GROUPS,
xInfoGroups: XINFO_GROUPS,
XINFO_STREAM,
xInfoStream: XINFO_STREAM,
XLEN,
xLen: XLEN,
XPENDING_RANGE,
xPendingRange: XPENDING_RANGE,
XPENDING,
xPending: XPENDING,
XRANGE,
xRange: XRANGE,
XREAD,
xRead: XREAD,
XREADGROUP,
xReadGroup: XREADGROUP,
XREVRANGE,
xRevRange: XREVRANGE,
XTRIM,
xTrim: XTRIM,
ZADD,
zAdd: ZADD,
ZCARD,
zCard: ZCARD,
ZCOUNT,
zCount: ZCOUNT,
ZDIFF_WITHSCORES,
zDiffWithScores: ZDIFF_WITHSCORES,
ZDIFF,
zDiff: ZDIFF,
ZDIFFSTORE,
zDiffStore: ZDIFFSTORE,
ZINCRBY,
zIncrBy: ZINCRBY,
ZINTER_WITHSCORES,
zInterWithScores: ZINTER_WITHSCORES,
ZINTER,
zInter: ZINTER,
ZINTERSTORE,
zInterStore: ZINTERSTORE,
ZLEXCOUNT,
zLexCount: ZLEXCOUNT,
ZMSCORE,
zmScore: ZMSCORE,
ZPOPMAX_COUNT,
zPopMaxCount: ZPOPMAX_COUNT,
ZPOPMAX,
zPopMax: ZPOPMAX,
ZPOPMIN_COUNT,
zPopMinCount: ZPOPMIN_COUNT,
ZPOPMIN,
zPopMin: ZPOPMIN,
ZRANDMEMBER_COUNT_WITHSCORES,
zRandMemberCountWithScores: ZRANDMEMBER_COUNT_WITHSCORES,
ZRANDMEMBER_COUNT,
zRandMemberCount: ZRANDMEMBER_COUNT,
ZRANDMEMBER,
zRandMember: ZRANDMEMBER,
ZRANGE_WITHSCORES,
zRangeWithScores: ZRANGE_WITHSCORES,
ZRANGE,
zRange: ZRANGE,
ZRANGEBYLEX,
zRangeByLex: ZRANGEBYLEX,
ZRANGEBYSCORE_WITHSCORES,
zRangeByScoreWithScores: ZRANGEBYSCORE_WITHSCORES,
ZRANGEBYSCORE,
zRangeByScore: ZRANGEBYSCORE,
ZRANGESTORE,
zRangeStore: ZRANGESTORE,
ZRANK,
zRank: ZRANK,
ZREM,
zRem: ZREM,
ZREMRANGEBYLEX,
zRemRangeByLex: ZREMRANGEBYLEX,
ZREMRANGEBYRANK,
zRemRangeByRank: ZREMRANGEBYRANK,
ZREMRANGEBYSCORE,
zRemRangeByScore: ZREMRANGEBYSCORE,
ZREVRANK,
zRevRank: ZREVRANK,
ZSCAN,
zScan: ZSCAN,
ZSCORE,
zScore: ZSCORE,
ZUNION_WITHSCORES,
zUnionWithScores: ZUNION_WITHSCORES,
ZUNION,
zUnion: ZUNION,
ZUNIONSTORE,
zUnionStore: ZUNIONSTORE
};

View File

@@ -1,21 +1,21 @@
import { strict as assert } from 'assert';
import RedisCluster from './cluster';
import { defineScript } from './lua-script';
import { itWithCluster, itWithDedicatedCluster, TestRedisClusters, TEST_REDIS_CLUSTERES } from './test-utils';
import RedisCluster from '.';
import { defineScript } from '../lua-script';
import { itWithCluster, itWithDedicatedCluster, TestRedisClusters, TEST_REDIS_CLUSTERES } from '../test-utils';
import calculateSlot from 'cluster-key-slot';
import { ClusterSlotStates } from './commands/CLUSTER_SETSLOT';
import { ClusterSlotStates } from '../commands/CLUSTER_SETSLOT';
describe('Cluster', () => {
it('sendCommand', async () => {
const cluster = RedisCluster.create({
rootNodes: TEST_REDIS_CLUSTERES[TestRedisClusters.OPEN],
...TEST_REDIS_CLUSTERES[TestRedisClusters.OPEN],
useReplicas: true
});
await cluster.connect();
try {
await cluster.ping();
await cluster.publish('channel', 'message');
await cluster.set('a', 'b');
await cluster.set('a{a}', 'bb');
await cluster.set('aa', 'bb');
@@ -31,18 +31,17 @@ describe('Cluster', () => {
itWithCluster(TestRedisClusters.OPEN, 'multi', async cluster => {
const key = 'key';
assert.deepEqual(
await cluster.multi(key)
.ping()
await cluster.multi()
.set(key, 'value')
.get(key)
.exec(),
['PONG', 'OK', 'value']
['OK', 'value']
);
});
it('scripts', async () => {
const cluster = RedisCluster.create({
rootNodes: TEST_REDIS_CLUSTERES[TestRedisClusters.OPEN],
...TEST_REDIS_CLUSTERES[TestRedisClusters.OPEN],
scripts: {
add: defineScript({
NUMBER_OF_KEYS: 0,

View File

@@ -1,25 +1,35 @@
import { RedisCommand, RedisModules, TransformArgumentsReply } from './commands';
import RedisClient, { ClientCommandOptions, RedisClientType, WithPlugins } from './client';
import { RedisSocketOptions } from './socket';
import COMMANDS from './commands';
import { RedisCommand, RedisCommandArguments, RedisCommandReply, RedisModules, RedisScript, RedisScripts } from '../commands';
import { ClientCommandOptions, RedisClientCommandSignature, RedisClientOptions, RedisClientType, WithModules, WithScripts } from '../client';
import RedisClusterSlots, { ClusterNode } from './cluster-slots';
import { RedisLuaScript, RedisLuaScripts } from './lua-script';
import { extendWithModulesAndScripts, extendWithDefaultCommands, transformCommandArguments } from './commander';
import RedisMultiCommand, { MultiQueuedCommand, RedisMultiCommandType } from './multi-command';
import { extendWithModulesAndScripts, transformCommandArguments, transformCommandReply, extendWithCommands } from '../commander';
import { EventEmitter } from 'events';
import RedisClusterMultiCommand, { RedisClusterMultiCommandType } from './multi-command';
import { RedisMultiQueuedCommand } from '../multi-command';
export interface RedisClusterOptions<M = RedisModules, S = RedisLuaScripts> {
rootNodes: Array<RedisSocketOptions>;
export type RedisClusterClientOptions = Omit<RedisClientOptions<{}, {}>, 'modules' | 'scripts'>;
export interface RedisClusterPlugins<M extends RedisModules, S extends RedisScripts> {
modules?: M;
scripts?: S;
}
export interface RedisClusterOptions<M extends RedisModules, S extends RedisScripts> extends RedisClusterPlugins<M, S> {
rootNodes: Array<RedisClusterClientOptions>;
defaults?: Partial<RedisClusterClientOptions>;
useReplicas?: boolean;
maxCommandRedirections?: number;
}
export type RedisClusterType<M extends RedisModules = {}, S extends RedisLuaScripts = {}> =
WithPlugins<M, S> & RedisCluster<M, S>;
type WithCommands = {
[P in keyof typeof COMMANDS]: RedisClientCommandSignature<(typeof COMMANDS)[P]>;
};
export default class RedisCluster<M extends RedisModules = {}, S extends RedisLuaScripts = {}> extends EventEmitter {
static #extractFirstKey(command: RedisCommand, originalArgs: Array<unknown>, redisArgs: TransformArgumentsReply): string | Buffer | undefined {
export type RedisClusterType<M extends RedisModules = {}, S extends RedisScripts = {}> =
RedisCluster<M, S> & WithCommands & WithModules<M> & WithScripts<S>;
export default class RedisCluster<M extends RedisModules = {}, S extends RedisScripts = {}> extends EventEmitter {
static extractFirstKey(command: RedisCommand, originalArgs: Array<unknown>, redisArgs: RedisCommandArguments): string | Buffer | undefined {
if (command.FIRST_KEY_INDEX === undefined) {
return undefined;
} else if (typeof command.FIRST_KEY_INDEX === 'number') {
@@ -29,7 +39,7 @@ export default class RedisCluster<M extends RedisModules = {}, S extends RedisLu
return command.FIRST_KEY_INDEX(...originalArgs);
}
static create<M extends RedisModules = {}, S extends RedisLuaScripts = {}>(options?: RedisClusterOptions<M, S>): RedisClusterType<M, S> {
static create<M extends RedisModules = {}, S extends RedisScripts = {}>(options?: RedisClusterOptions<M, S>): RedisClusterType<M, S> {
return new (<any>extendWithModulesAndScripts({
BaseClass: RedisCluster,
modules: options?.modules,
@@ -39,32 +49,36 @@ export default class RedisCluster<M extends RedisModules = {}, S extends RedisLu
}))(options);
}
readonly #options: RedisClusterOptions;
readonly #options: RedisClusterOptions<M, S>;
readonly #slots: RedisClusterSlots<M, S>;
readonly #Multi: new (...args: ConstructorParameters<typeof RedisMultiCommand>) => RedisMultiCommandType<M, S>;
readonly #Multi: new (...args: ConstructorParameters<typeof RedisClusterMultiCommand>) => RedisClusterMultiCommandType<M, S>;
constructor(options: RedisClusterOptions<M, S>) {
super();
this.#options = options;
this.#slots = new RedisClusterSlots(options, err => this.emit('error', err));
this.#Multi = RedisMultiCommand.extend(options);
this.#Multi = RedisClusterMultiCommand.extend(options);
}
duplicate(): RedisClusterOptions<M, S> {
return new (Object.getPrototypeOf(this).constructor)(this.#options);
duplicate(overrides?: Partial<RedisClusterOptions<M, S>>): RedisClusterType<M, S> {
return new (Object.getPrototypeOf(this).constructor)({
...this.#options,
...overrides
});
}
async connect(): Promise<void> {
return this.#slots.connect();
}
async commandsExecutor(command: RedisCommand, args: Array<unknown>): Promise<ReturnType<typeof command['transformReply']>> {
async commandsExecutor(command: RedisCommand, args: Array<unknown>): Promise<RedisCommandReply<typeof command>> {
const { args: redisArgs, options } = transformCommandArguments<ClientCommandOptions>(command, args);
const reply = command.transformReply(
return transformCommandReply(
command,
await this.sendCommand(
RedisCluster.#extractFirstKey(command, args, redisArgs),
RedisCluster.extractFirstKey(command, args, redisArgs),
command.IS_READ_ONLY,
redisArgs,
options,
@@ -72,18 +86,16 @@ export default class RedisCluster<M extends RedisModules = {}, S extends RedisLu
),
redisArgs.preserve
);
return reply;
}
async sendCommand<C extends RedisCommand>(
firstKey: string | Buffer | undefined,
isReadonly: boolean | undefined,
args: TransformArgumentsReply,
args: RedisCommandArguments,
options?: ClientCommandOptions,
bufferMode?: boolean,
redirections = 0
): Promise<ReturnType<C['transformReply']>> {
): Promise<RedisCommandReply<C>> {
const client = this.#slots.getClient(firstKey, isReadonly);
try {
@@ -100,10 +112,11 @@ export default class RedisCluster<M extends RedisModules = {}, S extends RedisLu
}
}
async scriptsExecutor(script: RedisLuaScript, args: Array<unknown>): Promise<ReturnType<typeof script['transformReply']>> {
async scriptsExecutor(script: RedisScript, args: Array<unknown>): Promise<RedisCommandReply<typeof script>> {
const { args: redisArgs, options } = transformCommandArguments<ClientCommandOptions>(script, args);
const reply = script.transformReply(
return transformCommandReply(
script,
await this.executeScript(
script,
args,
@@ -112,19 +125,17 @@ export default class RedisCluster<M extends RedisModules = {}, S extends RedisLu
),
redisArgs.preserve
);
return reply;
}
async executeScript(
script: RedisLuaScript,
script: RedisScript,
originalArgs: Array<unknown>,
redisArgs: TransformArgumentsReply,
redisArgs: RedisCommandArguments,
options?: ClientCommandOptions,
redirections = 0
): Promise<ReturnType<typeof script['transformReply']>> {
): Promise<RedisCommandReply<typeof script>> {
const client = this.#slots.getClient(
RedisCluster.#extractFirstKey(script, originalArgs, redisArgs),
RedisCluster.extractFirstKey(script, originalArgs, redisArgs),
script.IS_READ_ONLY
);
@@ -169,20 +180,14 @@ export default class RedisCluster<M extends RedisModules = {}, S extends RedisLu
throw err;
}
multi(routing: string): RedisMultiCommandType<M, S> {
multi(routing?: string | Buffer): RedisClusterMultiCommandType<M, S> {
return new this.#Multi(
async (commands: Array<MultiQueuedCommand>, chainId?: symbol) => {
const client = this.#slots.getClient(routing);
return Promise.all(
commands.map(({ args }) => {
return client.sendCommand(args, RedisClient.commandOptions({
chainId
}));
})
);
async (commands: Array<RedisMultiQueuedCommand>, firstKey?: string | Buffer, chainId?: symbol) => {
return this.#slots
.getClient(firstKey)
.multiExecutor(commands, chainId);
},
this.#options
routing
);
}
@@ -199,4 +204,8 @@ export default class RedisCluster<M extends RedisModules = {}, S extends RedisLu
}
}
extendWithDefaultCommands(RedisCluster, RedisCluster.prototype.commandsExecutor);
extendWithCommands({
BaseClass: RedisCluster,
commands: COMMANDS,
executor: RedisCluster.prototype.commandsExecutor
});

View File

@@ -0,0 +1,112 @@
import COMMANDS from './commands';
import { RedisCommand, RedisCommandArguments, RedisCommandRawReply, RedisModules, RedisPlugins, RedisScript, RedisScripts } from '../commands';
import RedisMultiCommand, { RedisMultiQueuedCommand } from '../multi-command';
import { extendWithCommands, extendWithModulesAndScripts } from '../commander';
import RedisCluster from '.';
type RedisClusterMultiCommandSignature<C extends RedisCommand, M extends RedisModules, S extends RedisScripts> =
(...args: Parameters<C['transformArguments']>) => RedisClusterMultiCommandType<M, S>;
type WithCommands<M extends RedisModules, S extends RedisScripts> = {
[P in keyof typeof COMMANDS]: RedisClusterMultiCommandSignature<(typeof COMMANDS)[P], M, S>
};
type WithModules<M extends RedisModules, S extends RedisScripts> = {
[P in keyof M]: {
[C in keyof M[P]]: RedisClusterMultiCommandSignature<M[P][C], M, S>;
};
};
type WithScripts<M extends RedisModules, S extends RedisScripts> = {
[P in keyof S]: RedisClusterMultiCommandSignature<S[P], M, S>
};
export type RedisClusterMultiCommandType<M extends RedisModules = {}, S extends RedisScripts = {}> =
RedisClusterMultiCommand & WithCommands<M, S> & WithModules<M, S> & WithScripts<M, S>;
export type RedisClusterMultiExecutor = (queue: Array<RedisMultiQueuedCommand>, firstKey?: string | Buffer, chainId?: symbol) => Promise<Array<RedisCommandRawReply>>;
export default class RedisClusterMultiCommand {
readonly #multi = new RedisMultiCommand();
readonly #executor: RedisClusterMultiExecutor;
#firstKey: string | Buffer | undefined;
static extend<M extends RedisModules, S extends RedisScripts>(
plugins?: RedisPlugins<M, S>
): new (...args: ConstructorParameters<typeof RedisMultiCommand>) => RedisClusterMultiCommandType<M, S> {
return <any>extendWithModulesAndScripts({
BaseClass: RedisClusterMultiCommand,
modules: plugins?.modules,
modulesCommandsExecutor: RedisClusterMultiCommand.prototype.commandsExecutor,
scripts: plugins?.scripts,
scriptsExecutor: RedisClusterMultiCommand.prototype.scriptsExecutor
});
}
constructor(executor: RedisClusterMultiExecutor, firstKey?: string | Buffer) {
this.#executor = executor;
this.#firstKey = firstKey;
}
commandsExecutor(command: RedisCommand, args: Array<unknown>): this {
const transformedArguments = command.transformArguments(...args);
if (!this.#firstKey) {
this.#firstKey = RedisCluster.extractFirstKey(command, args, transformedArguments);
}
return this.addCommand(
undefined,
transformedArguments,
command.transformReply
);
}
addCommand(
firstKey: string | Buffer | undefined,
args: RedisCommandArguments,
transformReply?: RedisCommand['transformReply']
): this {
if (!this.#firstKey) {
this.#firstKey = firstKey;
}
this.#multi.addCommand(args, transformReply);
return this;
}
scriptsExecutor(script: RedisScript, args: Array<unknown>): this {
const transformedArguments = this.#multi.addScript(script, args);
if (!this.#firstKey) {
this.#firstKey = RedisCluster.extractFirstKey(script, args, transformedArguments);
}
return this.addCommand(undefined, transformedArguments);
}
async exec(execAsPipeline = false): Promise<Array<RedisCommandRawReply>> {
if (execAsPipeline) {
return this.execAsPipeline();
}
const commands = this.#multi.exec();
if (!commands) return [];
return this.#multi.handleExecReplies(
await this.#executor(commands, this.#firstKey, RedisMultiCommand.generateChainId())
);
}
EXEC = this.exec;
async execAsPipeline(): Promise<Array<RedisCommandRawReply>> {
return this.#multi.transformReplies(
await this.#executor(this.#multi.queue, this.#firstKey)
);
}
}
extendWithCommands({
BaseClass: RedisClusterMultiCommand,
commands: COMMANDS,
executor: RedisClusterMultiCommand.prototype.commandsExecutor
});

View File

@@ -1,37 +1,32 @@
import COMMANDS, { RedisCommand, RedisModules, TransformArgumentsReply } from './commands';
import { RedisLuaScript, RedisLuaScripts } from './lua-script';
import { CommandOptions, isCommandOptions } from './command-options';
import { RedisCommand, RedisCommandArguments, RedisCommandRawReply, RedisCommandReply, RedisCommands, RedisModules, RedisScript, RedisScripts } from './commands';
type Instantiable<T = any> = new(...args: Array<any>) => T;
type CommandExecutor<T extends Instantiable = Instantiable> = (this: InstanceType<T>, command: RedisCommand, args: Array<unknown>) => unknown;
interface ExtendWithCommandsConfig<T extends Instantiable> {
BaseClass: T;
commands: RedisCommands;
executor(command: RedisCommand, args: Array<unknown>): unknown;
}
export function extendWithDefaultCommands<T extends Instantiable>(BaseClass: T, executor: CommandExecutor<T>): void {
for (const [name, command] of Object.entries(COMMANDS)) {
export function extendWithCommands<T extends Instantiable>({ BaseClass, commands, executor }: ExtendWithCommandsConfig<T>): void {
for (const [name, command] of Object.entries(commands)) {
BaseClass.prototype[name] = function (...args: Array<unknown>): unknown {
return executor.call(this, command, args);
};
}
}
interface ExtendWithModulesAndScriptsConfig<
T extends Instantiable,
M extends RedisModules,
S extends RedisLuaScripts
> {
interface ExtendWithModulesAndScriptsConfig<T extends Instantiable> {
BaseClass: T;
modules: M | undefined;
modulesCommandsExecutor: CommandExecutor<T>;
scripts: S | undefined;
scriptsExecutor(this: InstanceType<T>, script: RedisLuaScript, args: Array<unknown>): unknown;
modules?: RedisModules;
modulesCommandsExecutor(this: InstanceType<T>, command: RedisCommand, args: Array<unknown>): unknown;
scripts?: RedisScripts;
scriptsExecutor(this: InstanceType<T>, script: RedisScript, args: Array<unknown>): unknown;
}
export function extendWithModulesAndScripts<
T extends Instantiable,
M extends RedisModules,
S extends RedisLuaScripts,
>(config: ExtendWithModulesAndScriptsConfig<T, M, S>): T {
export function extendWithModulesAndScripts<T extends Instantiable>(config: ExtendWithModulesAndScriptsConfig<T>): T {
let Commander: T | undefined;
if (config.modules) {
@@ -39,7 +34,7 @@ export function extendWithModulesAndScripts<
constructor(...args: Array<any>) {
super(...args);
for (const module of Object.keys(config.modules as RedisModules)) {
for (const module of Object.keys(config.modules!)) {
this[module] = new this[module](this);
}
}
@@ -79,7 +74,7 @@ export function transformCommandArguments<T = unknown>(
command: RedisCommand,
args: Array<unknown>
): {
args: TransformArgumentsReply;
args: RedisCommandArguments;
options: CommandOptions<T> | undefined;
} {
let options;
@@ -96,7 +91,7 @@ export function transformCommandArguments<T = unknown>(
const DELIMITER = '\r\n';
export function* encodeCommand(args: TransformArgumentsReply): IterableIterator<string | Buffer> {
export function* encodeCommand(args: RedisCommandArguments): IterableIterator<string | Buffer> {
yield `*${args.length}${DELIMITER}`;
for (const arg of args) {
@@ -106,3 +101,15 @@ export function* encodeCommand(args: TransformArgumentsReply): IterableIterator<
yield DELIMITER;
}
}
export function transformCommandReply(
command: RedisCommand,
rawReply: RedisCommandRawReply,
preserved: unknown
): RedisCommandReply<typeof command> {
if (!command.transformReply) {
return rawReply;
}
return command.transformReply(rawReply, preserved);
}

View File

@@ -1,5 +1,3 @@
import { transformReplyStringArray } from './generic-transformers';
export function transformArguments(categoryName?: string): Array<string> {
const args = ['ACL', 'CAT'];
@@ -10,4 +8,4 @@ export function transformArguments(categoryName?: string): Array<string> {
return args;
}
export const transformReply = transformReplyStringArray;
export declare function transformReply(): Array<string>;

View File

@@ -1,8 +1,8 @@
import { TransformArgumentsReply } from '.';
import { pushVerdictArguments, transformReplyNumber } from './generic-transformers';
import { RedisCommandArguments } from '.';
import { pushVerdictArguments } from './generic-transformers';
export function transformArguments(username: string | Array<string>): TransformArgumentsReply {
export function transformArguments(username: string | Array<string>): RedisCommandArguments {
return pushVerdictArguments(['ACL', 'DELUSER'], username);
}
export const transformReply = transformReplyNumber;
export declare const transformReply: (reply: number) => number;

View File

@@ -1,5 +1,3 @@
import { transformReplyString } from './generic-transformers';
export function transformArguments(bits?: number): Array<string> {
const args = ['ACL', 'GENPASS'];
@@ -10,4 +8,4 @@ export function transformArguments(bits?: number): Array<string> {
return args;
}
export const transformReply = transformReplyString;
export declare function transformReply(): string;

View File

@@ -1,7 +1,5 @@
import { transformReplyStringArray } from './generic-transformers';
export function transformArguments(): Array<string> {
return ['ACL', 'LIST'];
}
export const transformReply = transformReplyStringArray;
export declare function transformReply(): Array<string>;

View File

@@ -1,7 +1,5 @@
import { transformReplyString } from './generic-transformers';
export function transformArguments(): Array<string> {
return ['ACL', 'LOAD'];
}
export const transformReply = transformReplyString;
export declare function transformReply(): string;

View File

@@ -1,7 +1,5 @@
import { transformReplyString } from './generic-transformers';
export function transformArguments(): Array<string> {
return ['ACL', 'LOG', 'RESET'];
}
export const transformReply = transformReplyString;
export declare function transformReply(): string;

View File

@@ -1,7 +1,5 @@
import { transformReplyString } from './generic-transformers';
export function transformArguments(): Array<string> {
return ['ACL', 'SAVE'];
}
export const transformReply = transformReplyString;
export declare function transformReply(): string;

View File

@@ -1,8 +1,8 @@
import { TransformArgumentsReply } from '.';
import { pushVerdictArguments, transformReplyString } from './generic-transformers';
import { RedisCommandArguments } from '.';
import { pushVerdictArguments } from './generic-transformers';
export function transformArguments(username: string, rule: string | Array<string>): TransformArgumentsReply {
export function transformArguments(username: string, rule: string | Array<string>): RedisCommandArguments {
return pushVerdictArguments(['ACL', 'SETUSER', username], rule);
}
export const transformReply = transformReplyString;
export declare function transformReply(): string;

View File

@@ -1,7 +1,5 @@
import { transformReplyStringArray } from './generic-transformers';
export function transformArguments(): Array<string> {
return ['ACL', 'USERS'];
}
export const transformReply = transformReplyStringArray;
export declare function transformReply(): Array<string>;

View File

@@ -1,7 +1,5 @@
import { transformReplyString } from './generic-transformers';
export function transformArguments(): Array<string> {
return ['ACL', 'WHOAMI'];
}
export const transformReply = transformReplyString;
export declare function transformReply(): string;

View File

@@ -1,9 +1,7 @@
import { transformReplyString } from './generic-transformers';
export const FIRST_KEY_INDEX = 1;
export function transformArguments(key: string, value: string): Array<string> {
return ['APPEND', key, value];
}
export const transformReply = transformReplyString;
export declare function transformReply(): string;

View File

@@ -1,7 +1,5 @@
import { transformReplyString } from './generic-transformers';
export function transformArguments(): Array<string> {
return ['ASKING'];
}
export const transformReply = transformReplyString;
export declare function transformReply(): string;

View File

@@ -1,5 +1,3 @@
import { transformReplyString } from './generic-transformers';
export interface AuthOptions {
username?: string;
password: string;
@@ -13,4 +11,4 @@ export function transformArguments({username, password}: AuthOptions): Array<str
return ['AUTH', username, password];
}
export const transformReply = transformReplyString;
export declare function transformReply(): string;

View File

@@ -1,7 +1,5 @@
import { transformReplyString } from './generic-transformers';
export function transformArguments(): Array<string> {
return ['BGREWRITEAOF'];
}
export const transformReply = transformReplyString;
export declare function transformReply(): string;

View File

@@ -1,5 +1,3 @@
import { transformReplyString } from './generic-transformers';
interface BgSaveOptions {
SCHEDULE?: true;
}
@@ -14,4 +12,4 @@ export function transformArguments(options?: BgSaveOptions): Array<string> {
return args;
}
export const transformReply = transformReplyString;
export declare function transformReply(): string;

View File

@@ -1,5 +1,3 @@
import { transformReplyNumber } from './generic-transformers';
export const FIRST_KEY_INDEX = 1;
export const IS_READ_ONLY = true;
@@ -22,4 +20,4 @@ export function transformArguments(key: string, range?: BitCountRange): Array<st
return args;
}
export const transformReply = transformReplyNumber;
export declare function transformReply(): number;

View File

@@ -1,5 +1,3 @@
import { transformReplyNumberNullArray } from './generic-transformers';
export const FIRST_KEY_INDEX = 1;
export const IS_READ_ONLY = true;
@@ -66,7 +64,7 @@ export function transformArguments(key: string, operations: BitFieldOperations):
options.type,
options.offset.toString(),
options.increment.toString()
)
);
break;
case 'OVERFLOW':
@@ -81,4 +79,4 @@ export function transformArguments(key: string, operations: BitFieldOperations):
return args;
}
export const transformReply = transformReplyNumberNullArray;
export declare function transformReply(): Array<number | null>;

View File

@@ -1,12 +1,12 @@
import { TransformArgumentsReply } from '.';
import { pushVerdictArguments, transformReplyNumber } from './generic-transformers';
import { RedisCommandArguments } from '.';
import { pushVerdictArguments } from './generic-transformers';
export const FIRST_KEY_INDEX = 2;
type BitOperations = 'AND' | 'OR' | 'XOR' | 'NOT';
export function transformArguments(operation: BitOperations, destKey: string, key: string | Array<string>): TransformArgumentsReply {
export function transformArguments(operation: BitOperations, destKey: string, key: string | Array<string>): RedisCommandArguments {
return pushVerdictArguments(['BITOP', operation, destKey], key);
}
export const transformReply = transformReplyNumber;
export declare function transformReply(): number;

View File

@@ -1,4 +1,4 @@
import { BitValue, transformReplyNumber } from './generic-transformers';
import { BitValue } from './generic-transformers';
export const FIRST_KEY_INDEX = 1;
@@ -18,4 +18,4 @@ export function transformArguments(key: string, bit: BitValue, start?: number, e
return args;
}
export const transformReply = transformReplyNumber;
export declare function transformReply(): number;

View File

@@ -1,4 +1,3 @@
import { transformReplyStringNull } from './generic-transformers';
import { LMoveSide } from './LMOVE';
export const FIRST_KEY_INDEX = 1;
@@ -20,4 +19,4 @@ export function transformArguments(
];
}
export const transformReply = transformReplyStringNull;
export declare function transformReply(): string | null;

View File

@@ -1,9 +1,9 @@
import { TransformArgumentsReply } from '.';
import { RedisCommandArguments } from '.';
import { pushVerdictArguments } from './generic-transformers';
export const FIRST_KEY_INDEX = 1;
export function transformArguments(keys: string | Buffer | Array<string | Buffer>, timeout: number): TransformArgumentsReply {
export function transformArguments(keys: string | Buffer | Array<string | Buffer>, timeout: number): RedisCommandArguments {
const args = pushVerdictArguments(['BLPOP'], keys);
args.push(timeout.toString());

View File

@@ -1,9 +1,9 @@
import { TransformArgumentsReply } from '.';
import { RedisCommandArguments } from '.';
import { pushVerdictArguments } from './generic-transformers';
export const FIRST_KEY_INDEX = 1;
export function transformArguments(key: string | Array<string>, timeout: number): TransformArgumentsReply {
export function transformArguments(key: string | Array<string>, timeout: number): RedisCommandArguments {
const args = pushVerdictArguments(['BRPOP'], key);
args.push(timeout.toString());

View File

@@ -1,9 +1,7 @@
import { transformReplyNumberNull } from './generic-transformers';
export const FIRST_KEY_INDEX = 1;
export function transformArguments(source: string, destination: string, timeout: number): Array<string> {
return ['BRPOPLPUSH', source, destination, timeout.toString()];
}
export const transformReply = transformReplyNumberNull;
export declare function transformReply(): number | null;

View File

@@ -2,7 +2,6 @@ import { strict as assert } from 'assert';
import { TestRedisServers, itWithClient } from '../test-utils';
import { transformArguments, transformReply } from './BZPOPMAX';
import { commandOptions } from '../../index';
import { describe } from 'mocha';
describe('BZPOPMAX', () => {
describe('transformArguments', () => {

View File

@@ -1,9 +1,9 @@
import { TransformArgumentsReply } from '.';
import { RedisCommandArguments } from '.';
import { pushVerdictArguments, transformReplyNumberInfinity, ZMember } from './generic-transformers';
export const FIRST_KEY_INDEX = 1;
export function transformArguments(key: string | Array<string>, timeout: number): TransformArgumentsReply {
export function transformArguments(key: string | Array<string>, timeout: number): RedisCommandArguments {
const args = pushVerdictArguments(['BZPOPMAX'], key);
args.push(timeout.toString());

View File

@@ -1,9 +1,9 @@
import { TransformArgumentsReply } from '.';
import { RedisCommandArguments } from '.';
import { pushVerdictArguments, transformReplyNumberInfinity, ZMember } from './generic-transformers';
export const FIRST_KEY_INDEX = 1;
export function transformArguments(key: string | Array<string>, timeout: number): TransformArgumentsReply {
export function transformArguments(key: string | Array<string>, timeout: number): RedisCommandArguments {
const args = pushVerdictArguments(['BZPOPMIN'], key);
args.push(timeout.toString());

View File

@@ -1,9 +1,7 @@
import { transformReplyNumber } from './generic-transformers';
export const IS_READ_ONLY = true;
export function transformArguments(): Array<string> {
return ['CLIENT', 'ID'];
}
export const transformReply = transformReplyNumber;
export declare function transformReply(): number;

View File

@@ -1,5 +1,3 @@
import { transformReplyString } from './generic-transformers';
export function transformArguments(slots: number | Array<number>): Array<string> {
const args = ['CLUSTER', 'ADDSLOTS'];
@@ -12,4 +10,4 @@ export function transformArguments(slots: number | Array<number>): Array<string>
return args;
}
export const transformReply = transformReplyString;
export declare function transformReply(): string;

View File

@@ -1,7 +1,5 @@
import { transformReplyString } from './generic-transformers';
export function transformArguments(): Array<string> {
return ['CLUSTER', 'FLUSHSLOTS'];
}
export const transformReply = transformReplyString;
export declare function transformReply(): string;

View File

@@ -1,7 +1,5 @@
import { transformReplyString } from './generic-transformers';
export function transformArguments(slot: number, count: number): Array<string> {
return ['CLUSTER', 'GETKEYSINSLOT', slot.toString(), count.toString()];
}
export const transformReply = transformReplyString;
export declare function transformReply(): string;

View File

@@ -1,5 +1,4 @@
import { strict as assert } from 'assert';
import { itWithCluster, TestRedisClusters } from '../test-utils';
import { transformArguments, transformReply } from './CLUSTER_INFO';
describe('CLUSTER INFO', () => {
@@ -44,21 +43,4 @@ describe('CLUSTER INFO', () => {
}
);
});
itWithCluster(TestRedisClusters.OPEN, 'cluster.clusterInfo', async cluster => {
const info = await cluster.clusterInfo();
assert.equal(info.state, 'ok');
assert.deepEqual(info.slots, {
assigned: 16384,
ok: 16384,
pfail: 0,
fail: 0
});
assert.equal(info.knownNodes, 3);
assert.equal(info.size, 3);
assert.equal(typeof info.currentEpoch, 'number');
assert.equal(typeof info.myEpoch, 'number');
assert.equal(typeof info.stats.messagesReceived, 'number');
assert.equal(typeof info.stats.messagesSent, 'number');
});
});

View File

@@ -1,7 +1,5 @@
import { transformReplyString } from './generic-transformers';
export function transformArguments(ip: string, port: number): Array<string> {
return ['CLUSTER', 'MEET', ip, port.toString()];
}
export const transformReply = transformReplyString;
export declare function transformReply(): string;

View File

@@ -1,5 +1,4 @@
import { strict as assert } from 'assert';
import { itWithCluster, TestRedisClusters } from '../test-utils';
import { RedisClusterNodeLinkStates, transformArguments, transformReply } from './CLUSTER_NODES';
describe('CLUSTER NODES', () => {
@@ -93,24 +92,4 @@ describe('CLUSTER NODES', () => {
);
});
});
itWithCluster(TestRedisClusters.OPEN, 'cluster.clusterNodes', async cluster => {
for (const node of (await cluster.clusterNodes())) {
assert.equal(typeof node.id, 'string');
assert.equal(typeof node.url, 'string');
assert.equal(typeof node.host, 'string');
assert.equal(typeof node.port, 'number');
assert.equal(typeof node.cport, 'number');
assert.ok(Array.isArray(node.flags));
assert.equal(typeof node.pingSent, 'number');
assert.equal(typeof node.pongRecv, 'number');
assert.equal(typeof node.configEpoch, 'number');
assert.equal(typeof node.linkState, 'string');
for (const slot of node.slots) {
assert.equal(typeof slot.from, 'number');
assert.equal(typeof slot.to, 'number');
}
}
});
});

View File

@@ -1,5 +1,3 @@
import { transformReplyString } from './generic-transformers';
export type ClusterResetModes = 'HARD' | 'SOFT';
export function transformArguments(mode?: ClusterResetModes): Array<string> {
@@ -12,4 +10,4 @@ export function transformArguments(mode?: ClusterResetModes): Array<string> {
return args;
}
export const transformReply = transformReplyString;
export declare function transformReply(): string;

View File

@@ -1,5 +1,3 @@
import { transformReplyString } from './generic-transformers';
export enum ClusterSlotStates {
IMPORTING = 'IMPORTING',
MIGRATING = 'MIGRATING',
@@ -17,4 +15,4 @@ export function transformArguments(slot: number, state: ClusterSlotStates, nodeI
return args;
}
export const transformReply = transformReplyString;
export declare function transformReply(): string;

View File

@@ -1,6 +1,6 @@
import { TransformArgumentsReply } from '.';
import { RedisCommandArguments } from '.';
export function transformArguments(): TransformArgumentsReply {
export function transformArguments(): RedisCommandArguments {
return ['CLUSTER', 'SLOTS'];
}

View File

@@ -0,0 +1,30 @@
import { strict as assert } from 'assert';
import { itWithClient, TestRedisServers } from '../test-utils';
import { transformArguments } from './COMMAND';
import { CommandCategories, CommandFlags } from './generic-transformers';
describe('COMMAND', () => {
it('transformArguments', () => {
assert.deepEqual(
transformArguments(),
['COMMAND']
);
});
itWithClient(TestRedisServers.OPEN, 'client.command', async client => {
assert.deepEqual(
(await client.command()).find(command => command.name === 'ping'),
{
name: 'ping',
arity: -1,
flags: new Set([CommandFlags.STALE, CommandFlags.FAST]),
firstKeyIndex: 0,
lastKeyIndex: 0,
step: 0,
categories: new Set([CommandCategories.FAST, CommandCategories.CONNECTION])
}
);
}, {
minimumRedisVersion: [6]
});
});

12
lib/commands/COMMAND.ts Normal file
View File

@@ -0,0 +1,12 @@
import { RedisCommandArguments } from '.';
import { CommandRawReply, CommandReply, transformCommandReply } from './generic-transformers';
export const IS_READ_ONLY = true;
export function transformArguments(): RedisCommandArguments {
return ['COMMAND'];
}
export function transformReply(reply: Array<CommandRawReply>): Array<CommandReply> {
return reply.map(transformCommandReply);
}

View File

@@ -0,0 +1,19 @@
import { strict as assert } from 'assert';
import { TestRedisServers, itWithClient } from '../test-utils';
import { transformArguments } from './COMMAND_COUNT';
describe('COMMAND COUNT', () => {
it('transformArguments', () => {
assert.deepEqual(
transformArguments(),
['COMMAND', 'COUNT']
);
});
itWithClient(TestRedisServers.OPEN, 'client.commandCount', async client => {
assert.equal(
typeof await client.commandCount(),
'number'
);
});
});

View File

@@ -0,0 +1,9 @@
import { RedisCommandArguments } from '.';
export const IS_READ_ONLY = true;
export function transformArguments(): RedisCommandArguments {
return ['COMMAND', 'COUNT'];
}
declare function transformReply(): number;

View File

@@ -0,0 +1,19 @@
import { strict as assert } from 'assert';
import { TestRedisServers, itWithClient } from '../test-utils';
import { transformArguments } from './COMMAND_GETKEYS';
describe('COMMAND GETKEYS', () => {
it('transformArguments', () => {
assert.deepEqual(
transformArguments(['GET', 'key']),
['COMMAND', 'GETKEYS', 'GET', 'key']
);
});
itWithClient(TestRedisServers.OPEN, 'client.commandGetKeys', async client => {
assert.deepEqual(
await client.commandGetKeys(['GET', 'key']),
['key']
);
});
});

View File

@@ -0,0 +1,9 @@
import { RedisCommandArguments } from '.';
export const IS_READ_ONLY = true;
export function transformArguments(args: Array<string>): RedisCommandArguments {
return ['COMMAND', 'GETKEYS', ...args];
}
declare function transformReply(): Array<string>;

View File

@@ -0,0 +1,30 @@
import { strict as assert } from 'assert';
import { itWithClient, TestRedisServers } from '../test-utils';
import { transformArguments } from './COMMAND_INFO';
import { CommandCategories, CommandFlags } from './generic-transformers';
describe('COMMAND INFO', () => {
it('transformArguments', () => {
assert.deepEqual(
transformArguments(['PING']),
['COMMAND', 'INFO', 'PING']
);
});
itWithClient(TestRedisServers.OPEN, 'client.commandInfo', async client => {
assert.deepEqual(
await client.commandInfo(['PING']),
[{
name: 'ping',
arity: -1,
flags: new Set([CommandFlags.STALE, CommandFlags.FAST]),
firstKeyIndex: 0,
lastKeyIndex: 0,
step: 0,
categories: new Set([CommandCategories.FAST, CommandCategories.CONNECTION])
}]
);
}, {
minimumRedisVersion: [6]
});
});

View File

@@ -0,0 +1,12 @@
import { RedisCommandArguments } from '.';
import { CommandRawReply, CommandReply, transformCommandReply } from './generic-transformers';
export const IS_READ_ONLY = true;
export function transformArguments(commands: Array<string>): RedisCommandArguments {
return ['COMMAND', 'INFO', ...commands];
}
export function transformReply(reply: Array<CommandRawReply | null>): Array<CommandReply | null> {
return reply.map(command => command ? transformCommandReply(command) : null);
}

View File

@@ -1,7 +1,5 @@
import { transformReplyString } from './generic-transformers';
export function transformArguments(): Array<string> {
return ['CONFIG', 'RESETSTAT'];
}
export const transformReply = transformReplyString;
export declare function transformReply(): string;

View File

@@ -1,7 +1,5 @@
import { transformReplyString } from './generic-transformers';
export function transformArguments(): Array<string> {
return ['CONFIG', 'REWRITE'];
}
export const transformReply = transformReplyString;
export declare function transformReply(): string;

View File

@@ -1,7 +1,5 @@
import { transformReplyString } from './generic-transformers';
export function transformArguments(parameter: string, value: string): Array<string> {
return ['CONFIG', 'SET', parameter, value];
}
export const transformReply = transformReplyString;
export declare function transformReply(): string;

View File

@@ -1,5 +1,5 @@
import { strict as assert } from 'assert';
import { TestRedisServers, itWithClient, TestRedisClusters, itWithCluster } from '../test-utils';
import { TestRedisServers, itWithClient } from '../test-utils';
import { transformArguments } from './DBSIZE';
describe('DBSIZE', () => {
@@ -16,11 +16,4 @@ describe('DBSIZE', () => {
0
);
});
itWithCluster(TestRedisClusters.OPEN, 'cluster.dbSize', async cluster => {
assert.equal(
await cluster.dbSize(),
0
);
});
});

View File

@@ -1,9 +1,7 @@
import { transformReplyNumber } from './generic-transformers';
export const IS_READ_ONLY = true;
export function transformArguments(): Array<string> {
return ['DBSIZE'];
}
export const transformReply = transformReplyNumber;
export declare function transformReply(): number;

View File

@@ -1,9 +1,7 @@
import { transformReplyNumber } from './generic-transformers';
export const FIRST_KEY_INDEX = 1;
export function transformArguments(key: string): Array<string> {
return ['DECR', key];
}
export const transformReply = transformReplyNumber;
export declare function transformReply(): number;

View File

@@ -1,9 +1,7 @@
import { transformReplyNumber } from './generic-transformers';
export const FIRST_KEY_INDEX = 1;
export function transformArguments(key: string, decrement: number): Array<string> {
return ['DECRBY', key, decrement.toString()];
}
export const transformReply = transformReplyNumber;
export declare function transformReply(): number;

View File

@@ -1,8 +1,8 @@
import { TransformArgumentsReply } from '.';
import { pushVerdictArguments, transformReplyNumber } from './generic-transformers';
import { RedisCommandArguments } from '.';
import { pushVerdictArguments } from './generic-transformers';
export function transformArguments(keys: string | Array<string>): TransformArgumentsReply {
export function transformArguments(keys: string | Array<string>): RedisCommandArguments {
return pushVerdictArguments(['DEL'], keys);
}
export const transformReply = transformReplyNumber;
export declare function transformReply(): number;

View File

@@ -1,7 +1,5 @@
import { transformReplyString } from './generic-transformers';
export function transformArguments(): Array<string> {
return ['DISCARD'];
}
export const transformReply = transformReplyString;
export declare function transformReply(): string;

View File

@@ -1,7 +1,5 @@
import { transformReplyString } from './generic-transformers';
export function transformArguments(key: string): Array<string> {
return ['DUMP', key];
}
export const transformReply = transformReplyString;
export declare function transformReply(): string;

View File

@@ -1,5 +1,5 @@
import { strict as assert } from 'assert';
import { TestRedisServers, itWithClient, TestRedisClusters, itWithCluster } from '../test-utils';
import { TestRedisServers, itWithClient } from '../test-utils';
import { transformArguments } from './ECHO';
describe('ECHO', () => {
@@ -16,11 +16,4 @@ describe('ECHO', () => {
'message'
);
});
itWithCluster(TestRedisClusters.OPEN, 'cluster.echo', async cluster => {
assert.equal(
await cluster.echo('message'),
'message'
);
});
});

View File

@@ -1,9 +1,7 @@
import { transformReplyString } from './generic-transformers';
export const IS_READ_ONLY = true;
export function transformArguments(message: string): Array<string> {
return ['ECHO', message];
}
export const transformReply = transformReplyString;
export declare function transformReply(): string;

View File

@@ -3,7 +3,3 @@ import { EvalOptions, pushEvalArguments } from './generic-transformers';
export function transformArguments(script: string, options?: EvalOptions): Array<string> {
return pushEvalArguments(['EVAL', script], options);
}
export function transformReply(reply: unknown): unknown {
return reply;
}

View File

@@ -3,7 +3,3 @@ import { EvalOptions, pushEvalArguments } from './generic-transformers';
export function transformArguments(sha1: string, options?: EvalOptions): Array<string> {
return pushEvalArguments(['EVALSHA', sha1], options);
}
export function transformReply(reply: unknown): unknown {
return reply;
}

View File

@@ -1,11 +1,11 @@
import { TransformArgumentsReply } from '.';
import { RedisCommandArguments } from '.';
import { pushVerdictArguments, transformReplyBoolean } from './generic-transformers';
export const FIRST_KEY_INDEX = 1;
export const IS_READ_ONLY = true;
export function transformArguments(keys: string | Array<string>): TransformArgumentsReply {
export function transformArguments(keys: string | Array<string>): RedisCommandArguments {
return pushVerdictArguments(['EXISTS'], keys);
}

View File

@@ -1,5 +1,3 @@
import { transformReplyString } from './generic-transformers';
interface FailoverOptions {
TO?: {
host: string;
@@ -32,4 +30,4 @@ export function transformArguments(options?: FailoverOptions): Array<string> {
return args;
}
export const transformReply = transformReplyString;
export declare function transformReply(): string;

View File

@@ -1,5 +1,3 @@
import { transformReplyString } from './generic-transformers';
export enum RedisFlushModes {
ASYNC = 'ASYNC',
SYNC = 'SYNC'
@@ -15,4 +13,4 @@ export function transformArguments(mode?: RedisFlushModes): Array<string> {
return args;
}
export const transformReply = transformReplyString;
export declare function transformReply(): string;

View File

@@ -1,5 +1,4 @@
import { RedisFlushModes } from './FLUSHALL';
import { transformReplyString } from './generic-transformers';
export function transformArguments(mode?: RedisFlushModes): Array<string> {
const args = ['FLUSHDB'];
@@ -11,4 +10,4 @@ export function transformArguments(mode?: RedisFlushModes): Array<string> {
return args;
}
export const transformReply = transformReplyString;
export declare function transformReply(): string;

View File

@@ -1,4 +1,4 @@
import { GeoCoordinates, transformReplyNumber } from './generic-transformers';
import { GeoCoordinates } from './generic-transformers';
interface GeoMember extends GeoCoordinates {
member: string;
@@ -46,4 +46,4 @@ export function transformArguments(key: string, toAdd: GeoMember | Array<GeoMemb
return args;
}
export const transformReply = transformReplyNumber;
export declare function transformReply(): number;

View File

@@ -19,13 +19,35 @@ describe('GEODIST', () => {
});
});
itWithClient(TestRedisServers.OPEN, 'client.geoDist', async client => {
describe('client.geoDist', () => {
itWithClient(TestRedisServers.OPEN, 'null', async client => {
assert.equal(
await client.geoDist('key', '1', '2'),
null
);
});
itWithClient(TestRedisServers.OPEN, 'with value', async client => {
const [, dist] = await Promise.all([
client.geoAdd('key', [{
member: '1',
longitude: 1,
latitude: 1
}, {
member: '2',
longitude: 2,
latitude: 2
}]),
client.geoDist('key', '1', '2')
]);
assert.equal(
dist,
157270.0561
);
});
});
itWithCluster(TestRedisClusters.OPEN, 'cluster.geoDist', async cluster => {
assert.equal(
await cluster.geoDist('key', '1', '2'),

View File

@@ -1,12 +1,12 @@
import { TransformArgumentsReply } from '.';
import { pushVerdictArguments, transformReplyStringArray } from './generic-transformers';
import { RedisCommandArguments } from '.';
import { pushVerdictArguments } from './generic-transformers';
export const FIRST_KEY_INDEX = 1;
export const IS_READ_ONLY = true;
export function transformArguments(key: string, member: string | Array<string>): TransformArgumentsReply {
export function transformArguments(key: string, member: string | Array<string>): RedisCommandArguments {
return pushVerdictArguments(['GEOHASH', key], member);
}
export const transformReply = transformReplyStringArray;
export declare function transformReply(): Array<string>;

View File

@@ -1,11 +1,11 @@
import { TransformArgumentsReply } from '.';
import { RedisCommandArguments } from '.';
import { pushVerdictArguments } from './generic-transformers';
export const FIRST_KEY_INDEX = 1;
export const IS_READ_ONLY = true;
export function transformArguments(key: string, member: string | Array<string>): TransformArgumentsReply {
export function transformArguments(key: string, member: string | Array<string>): RedisCommandArguments {
return pushVerdictArguments(['GEOPOS', key], member);
}

View File

@@ -1,4 +1,4 @@
import { GeoSearchFrom, GeoSearchBy, GeoSearchOptions, pushGeoSearchArguments, transformReplyStringArray } from './generic-transformers';
import { GeoSearchFrom, GeoSearchBy, GeoSearchOptions, pushGeoSearchArguments } from './generic-transformers';
export const FIRST_KEY_INDEX = 1;
@@ -13,4 +13,4 @@ export function transformArguments(
return pushGeoSearchArguments(['GEOSEARCH'], key, from, by, options);
}
export const transformReply = transformReplyStringArray;
export declare function transformReply(): Array<string>;

View File

@@ -1,5 +1,5 @@
import { strict as assert } from 'assert';
import { TransformArgumentsReply } from '.';
import { RedisCommandArguments } from '.';
import { TestRedisServers, itWithClient, TestRedisClusters, itWithCluster, describeHandleMinimumRedisVersion } from '../test-utils';
import { GeoReplyWith } from './generic-transformers';
import { transformArguments } from './GEOSEARCH_WITH';
@@ -8,7 +8,7 @@ describe('GEOSEARCH WITH', () => {
describeHandleMinimumRedisVersion([6, 2]);
it('transformArguments', () => {
const expectedReply: TransformArgumentsReply = ['GEOSEARCH', 'key', 'FROMMEMBER', 'member', 'BYRADIUS', '1', 'm', 'WITHDIST']
const expectedReply: RedisCommandArguments = ['GEOSEARCH', 'key', 'FROMMEMBER', 'member', 'BYRADIUS', '1', 'm', 'WITHDIST']
expectedReply.preserve = ['WITHDIST'];
assert.deepEqual(

View File

@@ -1,4 +1,4 @@
import { TransformArgumentsReply } from '.';
import { RedisCommandArguments } from '.';
import { GeoSearchFrom, GeoSearchBy, GeoReplyWith, GeoSearchOptions, transformGeoMembersWithReply } from './generic-transformers';
import { transformArguments as geoSearchTransformArguments } from './GEOSEARCH';
@@ -10,8 +10,8 @@ export function transformArguments(
by: GeoSearchBy,
replyWith: Array<GeoReplyWith>,
options?: GeoSearchOptions
): TransformArgumentsReply {
const args: TransformArgumentsReply = geoSearchTransformArguments(key, from, by, options);
): RedisCommandArguments {
const args: RedisCommandArguments = geoSearchTransformArguments(key, from, by, options);
args.push(...replyWith);

View File

@@ -1,12 +1,11 @@
import { TransformArgumentsReply } from '.';
import { transformReplyStringNull } from './generic-transformers';
import { RedisCommandArguments } from '.';
export const FIRST_KEY_INDEX = 1;
export const IS_READ_ONLY = true;
export function transformArguments(key: string | Buffer): TransformArgumentsReply {
export function transformArguments(key: string | Buffer): RedisCommandArguments {
return ['GET', key];
}
export const transformReply = transformReplyStringNull;
export declare function transformReply(): string | null;

View File

@@ -1,4 +1,4 @@
import { transformReplyBit } from './generic-transformers';
import { BitValue } from './generic-transformers';
export const FIRST_KEY_INDEX = 1;
@@ -8,4 +8,4 @@ export function transformArguments(key: string, offset: number): Array<string> {
return ['GETBIT', key, offset.toString()];
}
export const transformReply = transformReplyBit;
export declare function transformReply(): BitValue;

View File

@@ -1,9 +1,7 @@
import { transformReplyStringNull } from './generic-transformers';
export const FIRST_KEY_INDEX = 1;
export function transformArguments(key: string): Array<string> {
return ['GETDEL', key];
}
export const transformReply = transformReplyStringNull;
export declare function transformReply(): string | null;

View File

@@ -1,5 +1,5 @@
import { TransformArgumentsReply } from '.';
import { transformEXAT, transformPXAT, transformReplyStringNull } from './generic-transformers';
import { RedisCommandArguments } from '.';
import { transformEXAT, transformPXAT } from './generic-transformers';
export const FIRST_KEY_INDEX = 1;
@@ -15,7 +15,7 @@ type GetExModes = {
PERSIST: true;
};
export function transformArguments(key: string, mode: GetExModes): TransformArgumentsReply {
export function transformArguments(key: string, mode: GetExModes): RedisCommandArguments {
const args = ['GETEX', key];
if ('EX' in mode) {
@@ -33,4 +33,4 @@ export function transformArguments(key: string, mode: GetExModes): TransformArgu
return args;
}
export const transformReply = transformReplyStringNull;
export declare function transformReply(): string | null;

View File

@@ -1,5 +1,3 @@
import { transformReplyString } from './generic-transformers';
export const FIRST_KEY_INDEX = 1;
export const IS_READ_ONLY = true;
@@ -8,4 +6,4 @@ export function transformArguments(key: string, start: number, end: number): Arr
return ['GETRANGE', key, start.toString(), end.toString()];
}
export const transformReply = transformReplyString;
export declare function transformReply(): string;

View File

@@ -1,9 +1,7 @@
import { transformReplyStringNull } from './generic-transformers';
export const FIRST_KEY_INDEX = 1;
export function transformArguments(key: string, value: string): Array<string> {
return ['GETSET', key, value];
}
export const transformReply = transformReplyStringNull;
export declare function transformReply(): string | null;

View File

@@ -1,7 +1,5 @@
import { transformReplyBufferNull } from './generic-transformers';
export { FIRST_KEY_INDEX, IS_READ_ONLY, transformArguments } from './GET';
export const BUFFER_MODE = true;
export const transformReply = transformReplyBufferNull;
export declare function transformReply(): Buffer | null;

View File

@@ -1,10 +1,10 @@
import { TransformArgumentsReply } from '.';
import { pushVerdictArguments, transformReplyNumber } from './generic-transformers';
import { RedisCommandArguments } from '.';
import { pushVerdictArguments } from './generic-transformers';
export const FIRST_KEY_INDEX = 1;
export function transformArguments(key: string, field: string | Array<string>): TransformArgumentsReply {
export function transformArguments(key: string, field: string | Array<string>): RedisCommandArguments {
return pushVerdictArguments(['HDEL', key], field);
}
export const transformReply = transformReplyNumber;
export declare function transformReply(): number;

View File

@@ -12,7 +12,7 @@ export function transformArguments(options?: HelloOptions): Array<string> {
if (options) {
args.push(options.protover.toString());
if (options?.auth) {
if (options.auth) {
args.push('AUTH', options.auth.username, options.auth.password);
}

Some files were not shown because too many files have changed in this diff Show More