You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-13 10:02:24 +03:00
V5 branch (#2491)
* wip * Worked on phrasing etc for v5 doc changes. * Removed quite repetition of 'Rather' * Update v4-to-v5.md * Update v4-to-v5.md * Update v4-to-v5.md * WIP * WIP * clean SET command * some more commands, multi.exec<'typed'> * "typed" multi * WIP * upgrade deps * wip * wip * fix #2469 * wip * npm update * wip * wip * wip * wip * some tests * tests.yml * wip * wip * merge master into v5 * some more commands * some more commands * WIP * Release client@2.0.0-next.1 --------- Co-authored-by: Simon Prickett <simon@redislabs.com>
This commit is contained in:
@@ -1,33 +1,75 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { pushVerdictArgument } from './generic-transformers';
|
||||
import { RedisArgument, ArrayReply, BlobStringReply, Command } from '../RESP/types';
|
||||
import { transformDoubleArgument } from './generic-transformers';
|
||||
|
||||
export const FIRST_KEY_INDEX = 2;
|
||||
export type ZInterKeyAndWeight = {
|
||||
key: RedisArgument;
|
||||
weight: number;
|
||||
};
|
||||
|
||||
export const IS_READ_ONLY = true;
|
||||
export type ZInterKeys<T> = T | [T, ...Array<T>];
|
||||
|
||||
interface ZInterOptions {
|
||||
WEIGHTS?: Array<number>;
|
||||
AGGREGATE?: 'SUM' | 'MIN' | 'MAX';
|
||||
export interface ZInterOptions {
|
||||
AGGREGATE?: 'SUM' | 'MIN' | 'MAX';
|
||||
}
|
||||
|
||||
export function transformArguments(
|
||||
keys: Array<RedisCommandArgument> | RedisCommandArgument,
|
||||
export function pushZInterArguments(
|
||||
args: Array<RedisArgument>,
|
||||
keys: ZInterKeys<RedisArgument> | ZInterKeys<ZInterKeyAndWeight>,
|
||||
options?: ZInterOptions
|
||||
) {
|
||||
if (Array.isArray(keys)) {
|
||||
args.push(keys.length.toString());
|
||||
|
||||
if (keys.length) {
|
||||
if (isPlainKeys(keys)) {
|
||||
args = args.concat(keys);
|
||||
} else {
|
||||
const start = args.length;
|
||||
args[start + keys.length] = 'WEIGHTS';
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
const index = start + i;
|
||||
args[index] = keys[i].key;
|
||||
args[index + 1 + keys.length] = transformDoubleArgument(keys[i].weight);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
args.push('1');
|
||||
|
||||
if (isPlainKey(keys)) {
|
||||
args.push(keys);
|
||||
} else {
|
||||
args.push(
|
||||
keys.key,
|
||||
'WEIGHTS',
|
||||
transformDoubleArgument(keys.weight)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (options?.AGGREGATE) {
|
||||
args.push('AGGREGATE', options.AGGREGATE);
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
function isPlainKey(key: RedisArgument | ZInterKeyAndWeight): key is RedisArgument {
|
||||
return typeof key === 'string' || Buffer.isBuffer(key);
|
||||
}
|
||||
|
||||
function isPlainKeys(keys: Array<RedisArgument> | Array<ZInterKeyAndWeight>): keys is Array<RedisArgument> {
|
||||
return isPlainKey(keys[0]);
|
||||
}
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 2,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(
|
||||
keys: ZInterKeys<RedisArgument> | ZInterKeys<ZInterKeyAndWeight>,
|
||||
options?: ZInterOptions
|
||||
): RedisCommandArguments {
|
||||
const args = pushVerdictArgument(['ZINTER'], keys);
|
||||
|
||||
if (options?.WEIGHTS) {
|
||||
args.push(
|
||||
'WEIGHTS',
|
||||
...options.WEIGHTS.map(weight => weight.toString())
|
||||
);
|
||||
}
|
||||
|
||||
if (options?.AGGREGATE) {
|
||||
args.push('AGGREGATE', options.AGGREGATE);
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
export declare function transformReply(): Array<RedisCommandArgument>;
|
||||
) {
|
||||
return pushZInterArguments(['ZINTER'], keys, options);
|
||||
},
|
||||
transformReply: undefined as unknown as () => ArrayReply<BlobStringReply>
|
||||
} as const satisfies Command;
|
||||
|
Reference in New Issue
Block a user