1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +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,50 +1,52 @@
import { RedisCommandArgument, RedisCommandArguments } from '.';
import { ArrayReply, TuplesToMapReply, BlobStringReply, NumberReply, DoubleReply, UnwrapReply, Resp2Reply, Command, TypeMapping } from '../RESP/types';
import { transformDoubleReply } from './generic-transformers';
export function transformArguments(count?: number): RedisCommandArguments {
export type AclLogReply = ArrayReply<TuplesToMapReply<[
[BlobStringReply<'count'>, NumberReply],
[BlobStringReply<'reason'>, BlobStringReply],
[BlobStringReply<'context'>, BlobStringReply],
[BlobStringReply<'object'>, BlobStringReply],
[BlobStringReply<'username'>, BlobStringReply],
[BlobStringReply<'age-seconds'>, DoubleReply],
[BlobStringReply<'client-info'>, BlobStringReply],
/** added in 7.0 */
[BlobStringReply<'entry-id'>, NumberReply],
/** added in 7.0 */
[BlobStringReply<'timestamp-created'>, NumberReply],
/** added in 7.0 */
[BlobStringReply<'timestamp-last-updated'>, NumberReply]
]>>;
export default {
FIRST_KEY_INDEX: undefined,
IS_READ_ONLY: true,
transformArguments(count?: number) {
const args = ['ACL', 'LOG'];
if (count) {
args.push(count.toString());
if (count !== undefined) {
args.push(count.toString());
}
return args;
}
type AclLogRawReply = [
_: RedisCommandArgument,
count: number,
_: RedisCommandArgument,
reason: RedisCommandArgument,
_: RedisCommandArgument,
context: RedisCommandArgument,
_: RedisCommandArgument,
object: RedisCommandArgument,
_: RedisCommandArgument,
username: RedisCommandArgument,
_: RedisCommandArgument,
ageSeconds: RedisCommandArgument,
_: RedisCommandArgument,
clientInfo: RedisCommandArgument
];
interface AclLog {
count: number;
reason: RedisCommandArgument;
context: RedisCommandArgument;
object: RedisCommandArgument;
username: RedisCommandArgument;
ageSeconds: number;
clientInfo: RedisCommandArgument;
}
export function transformReply(reply: Array<AclLogRawReply>): Array<AclLog> {
return reply.map(log => ({
count: log[1],
reason: log[3],
context: log[5],
object: log[7],
username: log[9],
ageSeconds: Number(log[11]),
clientInfo: log[13]
}));
}
},
transformReply: {
2: (reply: UnwrapReply<Resp2Reply<AclLogReply>>, preserve?: any, typeMapping?: TypeMapping) => {
return reply.map(item => {
const inferred = item as unknown as UnwrapReply<typeof item>;
return {
count: inferred[1],
reason: inferred[3],
context: inferred[5],
object: inferred[7],
username: inferred[9],
'age-seconds': transformDoubleReply[2](inferred[11], preserve, typeMapping),
'client-info': inferred[13],
'entry-id': inferred[15],
'timestamp-created': inferred[17],
'timestamp-last-updated': inferred[19]
};
})
},
3: undefined as unknown as () => AclLogReply
}
} as const satisfies Command;