1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-07 13:22:56 +03:00

some commands

This commit is contained in:
Leibale
2023-05-09 14:04:26 +03:00
parent a6c0d1dbb3
commit d59254e497
21 changed files with 295 additions and 235 deletions

View File

@@ -1,5 +1,5 @@
import { RedisArgument, ArrayReply, BlobStringReply, Command } from '../RESP/types';
import { transformDoubleArgument } from './generic-transformers';
import { ZKeys, pushZKeysArguments } from './generic-transformers';
export type ZInterKeyAndWeight = {
key: RedisArgument;
@@ -14,38 +14,10 @@ export interface ZInterOptions {
export function pushZInterArguments(
args: Array<RedisArgument>,
keys: ZInterKeys<RedisArgument> | ZInterKeys<ZInterKeyAndWeight>,
keys: ZKeys,
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)
);
}
}
pushZKeysArguments(args, keys);
if (options?.AGGREGATE) {
args.push('AGGREGATE', options.AGGREGATE);
@@ -54,14 +26,6 @@ export function pushZInterArguments(
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,