1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-10 11:43:01 +03:00
Files
node-redis/packages/client/lib/commands/HRANDFIELD_COUNT_WITHVALUES.ts
Leibale 9faa3e77c4 WIP
2023-04-23 07:56:15 -04:00

36 lines
934 B
TypeScript

import { RedisArgument, ArrayReply, BlobStringReply, Command } from '../RESP/types';
export type HRandFieldCountWithValuesReply = Array<{
field: BlobStringReply;
value: BlobStringReply;
}>;
export default {
FIRST_KEY_INDEX: 1,
IS_READ_ONLY: true,
transformArguments(key: RedisArgument, count: number) {
return ['HRANDFIELD', key, count.toString(), 'WITHVALUES'];
},
transformReply: {
2: (rawReply: ArrayReply<BlobStringReply>) => {
const reply: HRandFieldCountWithValuesReply = [];
let i = 0;
while (i < rawReply.length) {
reply.push({
field: rawReply[i++],
value: rawReply[i++]
});
}
return reply;
},
3: (reply: ArrayReply<[BlobStringReply, BlobStringReply]>) => {
return reply.map(([field, value]) => ({
field,
value
})) satisfies HRandFieldCountWithValuesReply;
}
}
} as const satisfies Command;