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

V5 bringing RESP3, Sentinel and TypeMapping to node-redis

RESP3 Support
   - Some commands responses in RESP3 aren't stable yet and therefore return an "untyped" ReplyUnion.
 
Sentinel

TypeMapping

Correctly types Multi commands

Note: some API changes to be further documented in v4-to-v5.md
This commit is contained in:
Shaya Potter
2024-10-15 17:46:52 +03:00
committed by GitHub
parent 2fc79bdfb3
commit b2d35c5286
1174 changed files with 45931 additions and 36274 deletions

View File

@@ -1,36 +1,77 @@
import { strict as assert } from 'assert';
import { strict as assert } from 'node:assert';
import testUtils, { GLOBAL } from '../test-utils';
import { MATH_FUNCTION } from '../client/index.spec';
import { transformArguments } from './FUNCTION_LOAD';
import FUNCTION_LOAD from './FUNCTION_LOAD';
import { RedisClientType } from '../client';
import { NumberReply, RedisFunctions, RedisModules, RedisScripts, RespVersions } from '../RESP/types';
export const MATH_FUNCTION = {
name: 'math',
engine: 'LUA',
code:
`#!LUA name=math
redis.register_function {
function_name = "square",
callback = function(keys, args)
local number = redis.call('GET', keys[1])
return number * number
end,
flags = { "no-writes" }
}`,
library: {
square: {
NAME: 'square',
IS_READ_ONLY: true,
NUMBER_OF_KEYS: 1,
FIRST_KEY_INDEX: 0,
transformArguments(key: string) {
return [key];
},
transformReply: undefined as unknown as () => NumberReply
}
}
};
export function loadMathFunction<
M extends RedisModules,
F extends RedisFunctions,
S extends RedisScripts,
RESP extends RespVersions
>(
client: RedisClientType<M, F, S, RESP>
) {
return client.functionLoad(
MATH_FUNCTION.code,
{ REPLACE: true }
);
}
describe('FUNCTION LOAD', () => {
testUtils.isVersionGreaterThanHook([7]);
testUtils.isVersionGreaterThanHook([7]);
describe('transformArguments', () => {
it('simple', () => {
assert.deepEqual(
transformArguments( 'code'),
['FUNCTION', 'LOAD', 'code']
);
});
it('with REPLACE', () => {
assert.deepEqual(
transformArguments('code', {
REPLACE: true
}),
['FUNCTION', 'LOAD', 'REPLACE', 'code']
);
});
describe('transformArguments', () => {
it('simple', () => {
assert.deepEqual(
FUNCTION_LOAD.transformArguments('code'),
['FUNCTION', 'LOAD', 'code']
);
});
testUtils.testWithClient('client.functionLoad', async client => {
assert.equal(
await client.functionLoad(
MATH_FUNCTION.code,
{ REPLACE: true }
),
MATH_FUNCTION.name
);
}, GLOBAL.SERVERS.OPEN);
it('with REPLACE', () => {
assert.deepEqual(
FUNCTION_LOAD.transformArguments('code', {
REPLACE: true
}),
['FUNCTION', 'LOAD', 'REPLACE', 'code']
);
});
});
testUtils.testWithClient('client.functionLoad', async client => {
assert.equal(
await loadMathFunction(client),
MATH_FUNCTION.name
);
}, GLOBAL.SERVERS.OPEN);
});