Skip to content

Commit 8e6b980

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 4d158f9 + 6ad4c68 commit 8e6b980

File tree

27 files changed

+175
-106
lines changed

27 files changed

+175
-106
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
fail-fast: false
2323
matrix:
2424
node-version: ["18", "20", "22"]
25-
redis-version: ["rs-7.4.0-v1", "8.0.2", "8.2"]
25+
redis-version: ["rs-7.4.0-v1", "8.0.2", "8.2", "8.2.1-pre"]
2626
steps:
2727
- uses: actions/checkout@v4
2828
with:

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ await client.sendCommand(["SET", "key", "value", "NX"]); // 'OK'
143143
await client.sendCommand(["HGETALL", "key"]); // ['key1', 'field1', 'key2', 'field2']
144144
```
145145

146+
_Note: the [API is different when using a cluster](https://github.com/redis/node-redis/blob/master/docs/clustering.md#unsupported-redis-commands)._
147+
146148
### Transactions (Multi/Exec)
147149

148150
Start a [transaction](https://redis.io/topics/transactions) by calling `.multi()`, then chaining your commands. When
@@ -196,9 +198,8 @@ See the [Pub/Sub overview](https://github.com/redis/node-redis/blob/master/docs/
196198
using [async iterators](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator):
197199

198200
```typescript
199-
for await (const key of client.scanIterator()) {
200-
// use the key!
201-
await client.get(key);
201+
for await (const keys of client.scanIterator()) {
202+
console.log(keys, await client.mGet(keys));
202203
}
203204
```
204205

docs/clustering.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,25 @@ await cluster.close();
3838
| scripts | | Script definitions (see [Lua Scripts](./programmability.md#lua-scripts)) |
3939
| functions | | Function definitions (see [Functions](./programmability.md#functions)) |
4040

41+
## Usage
42+
43+
Most redis commands are the same as with individual clients.
44+
45+
### Unsupported Redis Commands
46+
47+
If you want to run commands and/or use arguments that Node Redis doesn't know about (yet!) use `.sendCommand()`.
48+
49+
When clustering, `sendCommand` takes 3 arguments to help with routing to the correct redis node:
50+
* `firstKey`: the key that is being operated on, or `undefined` to route to a random node.
51+
* `isReadOnly`: determines if the command needs to go to the master or may go to a replica.
52+
* `args`: the command and all arguments (including the key), as an array of strings.
53+
54+
```javascript
55+
await cluster.sendCommand("key", false, ["SET", "key", "value", "NX"]); // 'OK'
56+
57+
await cluster.sendCommand("key", true, ["HGETALL", "key"]); // ['key1', 'field1', 'key2', 'field2']
58+
```
59+
4160
## Auth with password and username
4261

4362
Specifying the password in the URL or a root node will only affect the connection to that specific node. In case you want to set the password for all the connections being created from a cluster instance, use the `defaults` option.
@@ -114,3 +133,4 @@ Admin commands such as `MEMORY STATS`, `FLUSHALL`, etc. are not attached to the
114133
### "Forwarded Commands"
115134

116135
Certain commands (e.g. `PUBLISH`) are forwarded to other cluster nodes by the Redis server. The client sends these commands to a random node in order to spread the load across the cluster.
136+

package-lock.json

Lines changed: 17 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/bloom/lib/test-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import RedisBloomModules from '.';
44
export default TestUtils.createFromConfig({
55
dockerImageName: 'redislabs/client-libs-test',
66
dockerImageVersionArgument: 'redis-version',
7-
defaultDockerVersion: '8.2'
7+
defaultDockerVersion: '8.2.1-pre'
88
});
99

1010
export const GLOBAL = {

packages/bloom/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@redis/bloom",
3-
"version": "5.8.1",
3+
"version": "5.8.2",
44
"license": "MIT",
55
"main": "./dist/lib/index.js",
66
"types": "./dist/lib/index.d.ts",
@@ -13,7 +13,7 @@
1313
"release": "release-it"
1414
},
1515
"peerDependencies": {
16-
"@redis/client": "^5.8.1"
16+
"@redis/client": "^5.8.2"
1717
},
1818
"devDependencies": {
1919
"@redis/test-utils": "*"

packages/client/lib/client/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,14 @@ export interface RedisClientOptions<
146146
clientInfoTag?: string;
147147
}
148148

149-
type WithCommands<
149+
export type WithCommands<
150150
RESP extends RespVersions,
151151
TYPE_MAPPING extends TypeMapping
152152
> = {
153153
[P in keyof typeof COMMANDS]: CommandSignature<(typeof COMMANDS)[P], RESP, TYPE_MAPPING>;
154154
};
155155

156-
type WithModules<
156+
export type WithModules<
157157
M extends RedisModules,
158158
RESP extends RespVersions,
159159
TYPE_MAPPING extends TypeMapping
@@ -163,7 +163,7 @@ type WithModules<
163163
};
164164
};
165165

166-
type WithFunctions<
166+
export type WithFunctions<
167167
F extends RedisFunctions,
168168
RESP extends RespVersions,
169169
TYPE_MAPPING extends TypeMapping
@@ -173,7 +173,7 @@ type WithFunctions<
173173
};
174174
};
175175

176-
type WithScripts<
176+
export type WithScripts<
177177
S extends RedisScripts,
178178
RESP extends RespVersions,
179179
TYPE_MAPPING extends TypeMapping
@@ -498,7 +498,7 @@ export default class RedisClient<
498498

499499
if (options?.url) {
500500
const parsedOptions = RedisClient.parseOptions(options);
501-
501+
502502
if (parsedOptions?.database) {
503503
this._self.#selectedDB = parsedOptions.database;
504504
}

packages/client/lib/cluster/index.ts

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { RedisClientOptions, RedisClientType } from '../client';
22
import { CommandOptions } from '../client/commands-queue';
3-
import { Command, CommandArguments, CommanderConfig, CommandSignature, /*CommandPolicies, CommandWithPoliciesSignature,*/ TypeMapping, RedisArgument, RedisFunction, RedisFunctions, RedisModules, RedisScript, RedisScripts, ReplyUnion, RespVersions } from '../RESP/types';
3+
import { Command, CommandArguments, CommanderConfig, TypeMapping, RedisArgument, RedisFunction, RedisFunctions, RedisModules, RedisScript, RedisScripts, ReplyUnion, RespVersions } from '../RESP/types';
44
import COMMANDS from '../commands';
55
import { EventEmitter } from 'node:events';
66
import { attachConfig, functionArgumentsPrefix, getTransformReply, scriptArgumentsPrefix } from '../commander';
@@ -13,6 +13,8 @@ import { ClientSideCacheConfig, PooledClientSideCacheProvider } from '../client/
1313
import { BasicCommandParser } from '../client/parser';
1414
import { ASKING_CMD } from '../commands/ASKING';
1515
import SingleEntryCache from '../single-entry-cache'
16+
import { WithCommands, WithFunctions, WithModules, WithScripts } from '../client';
17+
1618
interface ClusterCommander<
1719
M extends RedisModules,
1820
F extends RedisFunctions,
@@ -103,50 +105,6 @@ export interface RedisClusterOptions<
103105
clientSideCache?: PooledClientSideCacheProvider | ClientSideCacheConfig;
104106
}
105107

106-
// remove once request & response policies are ready
107-
type ClusterCommand<
108-
NAME extends PropertyKey,
109-
COMMAND extends Command
110-
> = COMMAND['NOT_KEYED_COMMAND'] extends true ? (
111-
COMMAND['IS_FORWARD_COMMAND'] extends true ? NAME : never
112-
) : NAME;
113-
114-
// CommandWithPoliciesSignature<(typeof COMMANDS)[P], RESP, TYPE_MAPPING, POLICIES>
115-
type WithCommands<
116-
RESP extends RespVersions,
117-
TYPE_MAPPING extends TypeMapping
118-
> = {
119-
[P in keyof typeof COMMANDS as ClusterCommand<P, (typeof COMMANDS)[P]>]: CommandSignature<(typeof COMMANDS)[P], RESP, TYPE_MAPPING>;
120-
};
121-
122-
type WithModules<
123-
M extends RedisModules,
124-
RESP extends RespVersions,
125-
TYPE_MAPPING extends TypeMapping
126-
> = {
127-
[P in keyof M]: {
128-
[C in keyof M[P] as ClusterCommand<C, M[P][C]>]: CommandSignature<M[P][C], RESP, TYPE_MAPPING>;
129-
};
130-
};
131-
132-
type WithFunctions<
133-
F extends RedisFunctions,
134-
RESP extends RespVersions,
135-
TYPE_MAPPING extends TypeMapping
136-
> = {
137-
[L in keyof F]: {
138-
[C in keyof F[L] as ClusterCommand<C, F[L][C]>]: CommandSignature<F[L][C], RESP, TYPE_MAPPING>;
139-
};
140-
};
141-
142-
type WithScripts<
143-
S extends RedisScripts,
144-
RESP extends RespVersions,
145-
TYPE_MAPPING extends TypeMapping
146-
> = {
147-
[P in keyof S as ClusterCommand<P, S[P]>]: CommandSignature<S[P], RESP, TYPE_MAPPING>;
148-
};
149-
150108
export type RedisClusterType<
151109
M extends RedisModules = {},
152110
F extends RedisFunctions = {},

packages/client/lib/commands/XTRIM.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ describe('XTRIM', () => {
1818
parseArgs(XTRIM, 'key', 'MINID', 123),
1919
['XTRIM', 'key', 'MINID', '123']
2020
);
21+
22+
assert.deepEqual(
23+
parseArgs(XTRIM, 'key', 'MINID', '0-0'),
24+
['XTRIM', 'key', 'MINID', '0-0']
25+
);
2126
});
2227

2328
it('with strategyModifier', () => {
@@ -89,6 +94,16 @@ describe('XTRIM', () => {
8994
cluster: GLOBAL.CLUSTERS.OPEN,
9095
});
9196

97+
testUtils.testAll('xTrim with string MINID', async client => {
98+
assert.equal(
99+
typeof await client.xTrim('key', 'MINID', '0-0'),
100+
'number'
101+
);
102+
}, {
103+
client: GLOBAL.SERVERS.OPEN,
104+
cluster: GLOBAL.CLUSTERS.OPEN,
105+
});
106+
92107
testUtils.testAll(
93108
'xTrim with LIMIT',
94109
async (client) => {

packages/client/lib/commands/XTRIM.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default {
3737
parser: CommandParser,
3838
key: RedisArgument,
3939
strategy: 'MAXLEN' | 'MINID',
40-
threshold: number,
40+
threshold: number | string,
4141
options?: XTrimOptions
4242
) {
4343
parser.push('XTRIM')

0 commit comments

Comments
 (0)