You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
import { RedisArgument, ArrayReply, TuplesReply, BlobStringReply, UnwrapReply, 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: UnwrapReply<ArrayReply<BlobStringReply>>) => {
|
|
const reply: HRandFieldCountWithValuesReply = [];
|
|
|
|
let i = 0;
|
|
while (i < rawReply.length) {
|
|
reply.push({
|
|
field: rawReply[i++],
|
|
value: rawReply[i++]
|
|
});
|
|
}
|
|
|
|
return reply;
|
|
},
|
|
3: (reply: UnwrapReply<ArrayReply<TuplesReply<[BlobStringReply, BlobStringReply]>>>) => {
|
|
return reply.map(entry => {
|
|
const [field, value] = entry as unknown as UnwrapReply<typeof entry>;
|
|
return {
|
|
field,
|
|
value
|
|
};
|
|
}) satisfies HRandFieldCountWithValuesReply;
|
|
}
|
|
}
|
|
} as const satisfies Command;
|
|
|