You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-04 15:02:09 +03:00
fix legacy mode resp encoder (#2118)
* fix legacy mode resp encoder * Update encoder.ts
This commit is contained in:
@@ -5,23 +5,21 @@ const CRLF = '\r\n';
|
||||
export default function encodeCommand(args: RedisCommandArguments): Array<RedisCommandArgument> {
|
||||
const toWrite: Array<RedisCommandArgument> = [];
|
||||
|
||||
let strings = `*${args.length}${CRLF}`;
|
||||
let strings = '*' + args.length + CRLF;
|
||||
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
const arg = args[i];
|
||||
if (typeof arg === 'string') {
|
||||
const byteLength = Buffer.byteLength(arg);
|
||||
strings += `$${byteLength}${CRLF}`;
|
||||
strings += arg;
|
||||
strings += '$' + Buffer.byteLength(arg) + CRLF + arg + CRLF;
|
||||
} else if (arg instanceof Buffer) {
|
||||
toWrite.push(`${strings}$${arg.length}${CRLF}`);
|
||||
strings = '';
|
||||
toWrite.push(arg);
|
||||
toWrite.push(
|
||||
strings + '$' + arg.length.toString() + CRLF,
|
||||
arg
|
||||
);
|
||||
strings = CRLF;
|
||||
} else {
|
||||
throw new TypeError('Invalid argument type');
|
||||
}
|
||||
|
||||
strings += CRLF;
|
||||
}
|
||||
|
||||
toWrite.push(strings);
|
||||
|
@@ -123,7 +123,11 @@ export function transformCommandArguments<T>(
|
||||
}
|
||||
|
||||
export function transformLegacyCommandArguments(args: Array<any>): Array<any> {
|
||||
return args.flat().map(x => x?.toString?.());
|
||||
return args.flat().map(arg => {
|
||||
return typeof arg === 'number' || arg instanceof Date ?
|
||||
arg.toString() :
|
||||
arg;
|
||||
});
|
||||
}
|
||||
|
||||
export function transformCommandReply<C extends RedisCommand>(
|
||||
|
Reference in New Issue
Block a user