You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-07 13:22:56 +03:00
some tests
This commit is contained in:
@@ -1,32 +1,29 @@
|
||||
import { RedisArgument, NumberReply, DoubleReply, Command } from '../RESP/types';
|
||||
import { ZMember, transformDoubleArgument, transformDoubleReply } from './generic-transformers';
|
||||
|
||||
interface NX {
|
||||
export interface ZAddOptions {
|
||||
condition?: 'NX' | 'XX';
|
||||
/**
|
||||
* @deprecated Use `{ condition: 'NX' }` instead.
|
||||
*/
|
||||
NX?: boolean;
|
||||
}
|
||||
|
||||
interface XX {
|
||||
/**
|
||||
* @deprecated Use `{ condition: 'XX' }` instead.
|
||||
*/
|
||||
XX?: boolean;
|
||||
}
|
||||
|
||||
interface LT {
|
||||
comparison?: 'LT' | 'GT';
|
||||
/**
|
||||
* @deprecated Use `{ comparison: 'LT' }` instead.
|
||||
*/
|
||||
LT?: boolean;
|
||||
}
|
||||
|
||||
interface GT {
|
||||
/**
|
||||
* @deprecated Use `{ comparison: 'GT' }` instead.
|
||||
*/
|
||||
GT?: boolean;
|
||||
}
|
||||
|
||||
interface CH {
|
||||
CH?: boolean;
|
||||
}
|
||||
|
||||
interface INCR {
|
||||
INCR?: boolean;
|
||||
}
|
||||
|
||||
export type ZAddOptions = (NX | (XX & LT & GT)) & CH & INCR;
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
transformArguments(
|
||||
@@ -36,35 +33,36 @@ export default {
|
||||
) {
|
||||
const args = ['ZADD', key];
|
||||
|
||||
if ((<NX>options)?.NX) {
|
||||
if (options?.condition) {
|
||||
args.push(options.condition);
|
||||
} else if (options?.NX) {
|
||||
args.push('NX');
|
||||
} else {
|
||||
if ((<XX>options)?.XX) {
|
||||
args.push('XX');
|
||||
}
|
||||
} else if (options?.XX) {
|
||||
args.push('XX');
|
||||
}
|
||||
|
||||
if ((<GT>options)?.GT) {
|
||||
args.push('GT');
|
||||
}
|
||||
|
||||
if ((<LT>options)?.LT) {
|
||||
args.push('LT');
|
||||
}
|
||||
if (options?.comparison) {
|
||||
args.push(options.comparison);
|
||||
} else if (options?.LT) {
|
||||
args.push('LT');
|
||||
} else if (options?.GT) {
|
||||
args.push('GT');
|
||||
}
|
||||
|
||||
if ((<CH>options)?.CH) {
|
||||
if (options?.CH) {
|
||||
args.push('CH');
|
||||
}
|
||||
|
||||
if ((<INCR>options)?.INCR) {
|
||||
if (options?.INCR) {
|
||||
args.push('INCR');
|
||||
}
|
||||
|
||||
for (const { score, value } of (Array.isArray(members) ? members : [members])) {
|
||||
args.push(
|
||||
transformDoubleArgument(score),
|
||||
value
|
||||
);
|
||||
if (Array.isArray(members)) {
|
||||
for (const member of members) {
|
||||
pushMember(args, member);
|
||||
}
|
||||
} else {
|
||||
pushMember(args, members);
|
||||
}
|
||||
|
||||
return args;
|
||||
@@ -74,3 +72,10 @@ export default {
|
||||
3: undefined as unknown as () => NumberReply | DoubleReply
|
||||
}
|
||||
} as const satisfies Command;
|
||||
|
||||
function pushMember(args: Array<RedisArgument>, member: ZMember) {
|
||||
args.push(
|
||||
transformDoubleArgument(member.score),
|
||||
member.value
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user