Skip to content

Commit dec9f67

Browse files
committed
pass down command name and search policy
1 parent 3700e5d commit dec9f67

File tree

2 files changed

+44
-7
lines changed

2 files changed

+44
-7
lines changed

packages/client/lib/cluster/index.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,12 @@ export default class RedisCluster<
188188
return async function (this: ProxyCluster, ...args: Array<unknown>) {
189189
const parser = new BasicCommandParser();
190190
command.parseCommand(parser, ...args);
191-
console.log(parser, parser.redisArgs[0]);
192191

193192
return this._self._execute(
194193
parser.firstKey,
195194
command.IS_READ_ONLY,
196195
this._commandOptions,
196+
parser.commandName!,
197197
(client, opts) => client._executeCommand(command, parser, opts, transformReply)
198198
);
199199
};
@@ -210,6 +210,7 @@ export default class RedisCluster<
210210
parser.firstKey,
211211
command.IS_READ_ONLY,
212212
this._self._commandOptions,
213+
parser.commandName!,
213214
(client, opts) => client._executeCommand(command, parser, opts, transformReply)
214215
);
215216
};
@@ -228,6 +229,7 @@ export default class RedisCluster<
228229
parser.firstKey,
229230
fn.IS_READ_ONLY,
230231
this._self._commandOptions,
232+
parser.commandName!,
231233
(client, opts) => client._executeCommand(fn, parser, opts, transformReply)
232234
);
233235
};
@@ -246,6 +248,7 @@ export default class RedisCluster<
246248
parser.firstKey,
247249
script.IS_READ_ONLY,
248250
this._commandOptions,
251+
parser.commandName!,
249252
(client, opts) => client._executeScript(script, parser, opts, transformReply)
250253
);
251254
};
@@ -459,12 +462,16 @@ export default class RedisCluster<
459462
firstKey: RedisArgument | undefined,
460463
isReadonly: boolean | undefined,
461464
options: ClusterCommandOptions | undefined,
465+
commandName: string,
462466
fn: (client: RedisClientType<M, F, S, RESP, TYPE_MAPPING>, opts?: ClusterCommandOptions) => Promise<T>
463467
): Promise<T> {
464-
console.log(`executing command `, firstKey, isReadonly, options);
465468
const maxCommandRedirections = this._options.maxCommandRedirections ?? 16;
466-
const p = this._policyResolver.resolvePolicy("ping")
467-
console.log(`ping policy `, p);
469+
const policyResult = this._policyResolver.resolvePolicy(commandName)
470+
if(policyResult.ok) {
471+
//TODO
472+
} else {
473+
//TODO
474+
}
468475

469476
let client = await this._slots.getClient(firstKey, isReadonly);
470477
let i = 0;
@@ -521,6 +528,7 @@ export default class RedisCluster<
521528
firstKey,
522529
isReadonly,
523530
options,
531+
args[0] instanceof Buffer ? args[0].toString() : args[0],
524532
(client, opts) => client.sendCommand(args, opts)
525533
);
526534
}
Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,38 @@
11
import testUtils, { GLOBAL } from '../../test-utils';
2+
import RediSearch from '@redis/search';
3+
4+
import RedisBloomModules from '@redis/bloom';
5+
import RedisJSON from '@redis/json';
6+
import RedisTimeSeries from '@redis/time-series';
27

38
describe('Cluster Request-Response Policies', () => {
4-
testUtils.testWithCluster('should resolve policies correctly', async cluster => {
9+
testUtils.testWithClient('should resolve policies correctly', async client => {
10+
await client.ft.SUGADD('index', 'string', 1);
11+
await client.ft.dictAdd('index', 'foo');
12+
}, {
13+
...GLOBAL.SERVERS.OPEN,
14+
clientOptions: {
15+
modules: {
16+
ft: RediSearch
17+
}
18+
}
19+
});
520

6-
await cluster.get('foo')
21+
testUtils.testWithCluster('should resolve policies correctly', async cluster => {
722

8-
}, GLOBAL.CLUSTERS.OPEN);
23+
await cluster.ft.SUGADD('index', 'string', 1);
24+
await cluster.ft.DICTADD('index', 'foo');
25+
await cluster.sendCommand(undefined, true, ['ft.dictadd', 'index', 'string']);
26+
27+
}, {
28+
...GLOBAL.CLUSTERS.OPEN,
29+
clusterConfiguration: {
30+
modules: {
31+
ft: RediSearch,
32+
// ...RedisBloomModules,
33+
// json: RedisJSON,
34+
// ts: RedisTimeSeries
35+
},
36+
}
37+
});
938
});

0 commit comments

Comments
 (0)