1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00

comment cluster request & response policies (keep v4 behaver)

This commit is contained in:
Leibale
2023-09-18 17:16:41 -04:00
parent 67900a50fa
commit 4be30ccd0f
14 changed files with 546 additions and 492 deletions

View File

@@ -1,4 +1,4 @@
import { VerbatimStringReply, Command } from '@redis/client/dist/lib/RESP/types';
import { VerbatimStringReply, Command } from '../RESP/types';
export default {
FIRST_KEY_INDEX: undefined,

View File

@@ -1,4 +1,4 @@
import { VerbatimStringReply, Command } from '@redis/client/dist/lib/RESP/types';
import { VerbatimStringReply, Command } from '../RESP/types';
export default {
FIRST_KEY_INDEX: undefined,

View File

@@ -1,4 +1,4 @@
import { RedisArgument, VerbatimStringReply, Command } from '@redis/client/dist/lib/RESP/types';
import { RedisArgument, VerbatimStringReply, Command } from '../RESP/types';
export default {
FIRST_KEY_INDEX: undefined,

View File

@@ -17,13 +17,14 @@ describe('FCALL', () => {
});
testUtils.testWithClient('client.fCall', async client => {
await loadMathFunction(client);
const [,, reply] = await Promise.all([
loadMathFunction(client),
client.set('key', '2'),
client.fCall(MATH_FUNCTION.library.square.NAME, {
arguments: ['key']
})
]);
assert.equal(
await client.fCall(MATH_FUNCTION.library.square.NAME, {
arguments: ['2']
}),
4
);
assert.equal(reply, 4);
}, GLOBAL.SERVERS.OPEN);
});

View File

@@ -17,13 +17,14 @@ describe('FCALL_RO', () => {
});
testUtils.testWithClient('client.fCallRo', async client => {
await loadMathFunction(client);
const [,, reply] = await Promise.all([
loadMathFunction(client),
client.set('key', '2'),
client.fCallRo(MATH_FUNCTION.library.square.NAME, {
arguments: ['key']
})
]);
assert.equal(
await client.fCallRo(MATH_FUNCTION.library.square.NAME, {
arguments: ['2']
}),
4
);
assert.equal(reply, 4);
}, GLOBAL.SERVERS.OPEN);
});

View File

@@ -11,16 +11,20 @@ export const MATH_FUNCTION = {
`#!LUA name=math
redis.register_function {
function_name = "square",
callback = function(keys, args) return args[1] * args[1] end,
callback = function(keys, args) {
local number = redis.call('GET', keys[1])
return number * number
},
flags = { "no-writes" }
}`,
library: {
square: {
NAME: 'square',
IS_READ_ONLY: true,
NUMBER_OF_KEYS: 0,
transformArguments(number: number) {
return [number.toString()];
NUMBER_OF_KEYS: 1,
FIRST_KEY_INDEX: 0,
transformArguments(key: string) {
return [key];
},
transformReply: undefined as unknown as () => NumberReply
}

View File

@@ -3,6 +3,7 @@ import { RedisArgument, NumberReply, Command } from '../RESP/types';
export default {
FIRST_KEY_INDEX: undefined,
IS_READ_ONLY: true,
IS_FORWARD_COMMAND: true,
transformArguments(channel: RedisArgument, message: RedisArgument) {
return ['PUBLISH', channel, message];
},