You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-10 11:43:01 +03:00
clean code
This commit is contained in:
@@ -8,17 +8,14 @@ describe('BLMPOP', () => {
|
|||||||
describe('transformArguments', () => {
|
describe('transformArguments', () => {
|
||||||
it('simple', () => {
|
it('simple', () => {
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
transformArguments(0, 'key', {
|
transformArguments(0, 'key', 'LEFT'),
|
||||||
SIDE: 'LEFT'
|
|
||||||
}),
|
|
||||||
['BLMPOP', '0', '1', 'key', 'LEFT']
|
['BLMPOP', '0', '1', 'key', 'LEFT']
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('with score and count', () => {
|
it('with COUNT', () => {
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
transformArguments(0, 'key', {
|
transformArguments(0, 'key', 'LEFT', {
|
||||||
SIDE: 'LEFT',
|
|
||||||
COUNT: 2
|
COUNT: 2
|
||||||
}),
|
}),
|
||||||
['BLMPOP', '0', '1', 'key', 'LEFT', 'COUNT', '2']
|
['BLMPOP', '0', '1', 'key', 'LEFT', 'COUNT', '2']
|
||||||
@@ -28,9 +25,7 @@ describe('BLMPOP', () => {
|
|||||||
|
|
||||||
testUtils.testWithClient('client.zmScore', async client => {
|
testUtils.testWithClient('client.zmScore', async client => {
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
await client.blmPop(0, 'key', {
|
await client.blmPop(0, 'key', 'RIGHT'),
|
||||||
SIDE: 'LEFT'
|
|
||||||
}),
|
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
}, GLOBAL.SERVERS.OPEN);
|
}, GLOBAL.SERVERS.OPEN);
|
||||||
|
@@ -1,14 +1,20 @@
|
|||||||
import { RedisCommandArguments } from '.';
|
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||||
import { transformLMPopArguments, LMPopOptions } from './generic-transformers';
|
import { transformLMPopArguments, LMPopOptions, ListSide } from './generic-transformers';
|
||||||
|
|
||||||
export const FIRST_KEY_INDEX = 3;
|
export const FIRST_KEY_INDEX = 3;
|
||||||
|
|
||||||
export function transformArguments(
|
export function transformArguments(
|
||||||
timeout: number,
|
timeout: number,
|
||||||
keys: string | Array<string>,
|
keys: RedisCommandArgument | Array<RedisCommandArgument>,
|
||||||
options: LMPopOptions
|
side: ListSide,
|
||||||
|
options?: LMPopOptions
|
||||||
): RedisCommandArguments {
|
): RedisCommandArguments {
|
||||||
return transformLMPopArguments(['BLMPOP', timeout.toString()], keys, options);
|
return transformLMPopArguments(
|
||||||
|
['BLMPOP', timeout.toString()],
|
||||||
|
keys,
|
||||||
|
side,
|
||||||
|
options
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export { transformReply } from './LMPOP';
|
export { transformReply } from './LMPOP';
|
||||||
|
@@ -8,17 +8,14 @@ describe('BZMPOP', () => {
|
|||||||
describe('transformArguments', () => {
|
describe('transformArguments', () => {
|
||||||
it('simple', () => {
|
it('simple', () => {
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
transformArguments(0, 'key', {
|
transformArguments(0, 'key', 'MIN'),
|
||||||
SCORE: 'MIN'
|
|
||||||
}),
|
|
||||||
['BZMPOP', '0', '1', 'key', 'MIN']
|
['BZMPOP', '0', '1', 'key', 'MIN']
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('with score and count', () => {
|
it('with COUNT', () => {
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
transformArguments(0, 'key', {
|
transformArguments(0, 'key', 'MIN', {
|
||||||
SCORE: 'MIN',
|
|
||||||
COUNT: 2
|
COUNT: 2
|
||||||
}),
|
}),
|
||||||
['BZMPOP', '0', '1', 'key', 'MIN', 'COUNT', '2']
|
['BZMPOP', '0', '1', 'key', 'MIN', 'COUNT', '2']
|
||||||
@@ -26,11 +23,9 @@ describe('BZMPOP', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
testUtils.testWithClient('client.zmScore', async client => {
|
testUtils.testWithClient('client.bzmPop', async client => {
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
await client.bzmPop(0, 'key', {
|
await client.bzmPop(0, 'key', 'MAX'),
|
||||||
SCORE: 'MAX'
|
|
||||||
}),
|
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
}, GLOBAL.SERVERS.OPEN);
|
}, GLOBAL.SERVERS.OPEN);
|
||||||
|
@@ -1,14 +1,20 @@
|
|||||||
import { RedisCommandArguments } from '.';
|
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||||
import { transformZMPopArguments, ZMPopOptions } from './generic-transformers';
|
import { SortedSetSide, transformZMPopArguments, ZMPopOptions } from './generic-transformers';
|
||||||
|
|
||||||
export const FIRST_KEY_INDEX = 3;
|
export const FIRST_KEY_INDEX = 3;
|
||||||
|
|
||||||
export function transformArguments(
|
export function transformArguments(
|
||||||
timeout: number,
|
timeout: number,
|
||||||
keys: string | Array<string>,
|
keys: RedisCommandArgument | Array<RedisCommandArgument>,
|
||||||
options: ZMPopOptions
|
side: SortedSetSide,
|
||||||
|
options?: ZMPopOptions
|
||||||
): RedisCommandArguments {
|
): RedisCommandArguments {
|
||||||
return transformZMPopArguments(['BZMPOP', timeout.toString()], keys, options);
|
return transformZMPopArguments(
|
||||||
|
['BZMPOP', timeout.toString()],
|
||||||
|
keys,
|
||||||
|
side,
|
||||||
|
options
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export { transformReply } from './ZMPOP';
|
export { transformReply } from './ZMPOP';
|
||||||
|
@@ -1,14 +1,13 @@
|
|||||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||||
|
import { ListSide } from './generic-transformers';
|
||||||
|
|
||||||
export const FIRST_KEY_INDEX = 1;
|
export const FIRST_KEY_INDEX = 1;
|
||||||
|
|
||||||
export type LMoveSide = 'LEFT' | 'RIGHT';
|
|
||||||
|
|
||||||
export function transformArguments(
|
export function transformArguments(
|
||||||
source: RedisCommandArgument,
|
source: RedisCommandArgument,
|
||||||
destination: RedisCommandArgument,
|
destination: RedisCommandArgument,
|
||||||
sourceSide: LMoveSide,
|
sourceSide: ListSide,
|
||||||
destinationSide: LMoveSide
|
destinationSide: ListSide
|
||||||
): RedisCommandArguments {
|
): RedisCommandArguments {
|
||||||
return [
|
return [
|
||||||
'LMOVE',
|
'LMOVE',
|
||||||
|
@@ -8,17 +8,14 @@ describe('LMPOP', () => {
|
|||||||
describe('transformArguments', () => {
|
describe('transformArguments', () => {
|
||||||
it('simple', () => {
|
it('simple', () => {
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
transformArguments('key', {
|
transformArguments('key', 'LEFT'),
|
||||||
SIDE: 'LEFT'
|
|
||||||
}),
|
|
||||||
['LMPOP', '1', 'key', 'LEFT']
|
['LMPOP', '1', 'key', 'LEFT']
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('with score and count', () => {
|
it('with COUNT', () => {
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
transformArguments('key', {
|
transformArguments('key', 'LEFT', {
|
||||||
SIDE: 'LEFT',
|
|
||||||
COUNT: 2
|
COUNT: 2
|
||||||
}),
|
}),
|
||||||
['LMPOP', '1', 'key', 'LEFT', 'COUNT', '2']
|
['LMPOP', '1', 'key', 'LEFT', 'COUNT', '2']
|
||||||
@@ -26,11 +23,9 @@ describe('LMPOP', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
testUtils.testWithClient('client.zmScore', async client => {
|
testUtils.testWithClient('client.lmPop', async client => {
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
await client.lmPop('key', {
|
await client.lmPop('key', 'RIGHT'),
|
||||||
SIDE: 'RIGHT'
|
|
||||||
}),
|
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
}, GLOBAL.SERVERS.OPEN);
|
}, GLOBAL.SERVERS.OPEN);
|
||||||
|
@@ -1,20 +1,22 @@
|
|||||||
import { RedisCommandArguments } from '.';
|
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||||
import { transformLMPopArguments, LMPopOptions } from './generic-transformers';
|
import { transformLMPopArguments, LMPopOptions, ListSide } from './generic-transformers';
|
||||||
|
|
||||||
export const FIRST_KEY_INDEX = 2;
|
export const FIRST_KEY_INDEX = 2;
|
||||||
|
|
||||||
export const IS_READ_ONLY = true;
|
|
||||||
|
|
||||||
export function transformArguments(
|
export function transformArguments(
|
||||||
keys: string | Array<string>,
|
keys: RedisCommandArgument | Array<RedisCommandArgument>,
|
||||||
options: LMPopOptions
|
side: ListSide,
|
||||||
|
options?: LMPopOptions
|
||||||
): RedisCommandArguments {
|
): RedisCommandArguments {
|
||||||
return transformLMPopArguments(['LMPOP'], keys, options);
|
return transformLMPopArguments(
|
||||||
|
['LMPOP'],
|
||||||
|
keys,
|
||||||
|
side,
|
||||||
|
options
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
type LMPopReply = null | [
|
export declare function transformReply(): null | [
|
||||||
key: string,
|
key: string,
|
||||||
elements: Array<String>
|
elements: Array<string>
|
||||||
];
|
];
|
||||||
|
|
||||||
export declare function transformReply(): LMPopReply;
|
|
||||||
|
@@ -8,17 +8,14 @@ describe('ZMPOP', () => {
|
|||||||
describe('transformArguments', () => {
|
describe('transformArguments', () => {
|
||||||
it('simple', () => {
|
it('simple', () => {
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
transformArguments('key', {
|
transformArguments('key', 'MIN'),
|
||||||
SCORE: 'MIN'
|
|
||||||
}),
|
|
||||||
['ZMPOP', '1', 'key', 'MIN']
|
['ZMPOP', '1', 'key', 'MIN']
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('with score and count', () => {
|
it('with score and count', () => {
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
transformArguments('key', {
|
transformArguments('key', 'MIN', {
|
||||||
SCORE: 'MIN',
|
|
||||||
COUNT: 2
|
COUNT: 2
|
||||||
}),
|
}),
|
||||||
['ZMPOP', '1', 'key', 'MIN', 'COUNT', '2']
|
['ZMPOP', '1', 'key', 'MIN', 'COUNT', '2']
|
||||||
@@ -28,9 +25,7 @@ describe('ZMPOP', () => {
|
|||||||
|
|
||||||
testUtils.testWithClient('client.zmScore', async client => {
|
testUtils.testWithClient('client.zmScore', async client => {
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
await client.zmPop('key', {
|
await client.zmPop('key', 'MIN'),
|
||||||
SCORE: 'MAX'
|
|
||||||
}),
|
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
}, GLOBAL.SERVERS.OPEN);
|
}, GLOBAL.SERVERS.OPEN);
|
||||||
|
@@ -1,26 +1,34 @@
|
|||||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||||
import { transformSortedSetMemberReply, transformZMPopArguments, ZMember, ZMPopOptions } from './generic-transformers';
|
import { SortedSetSide, transformSortedSetMemberReply, transformZMPopArguments, ZMember, ZMPopOptions } from './generic-transformers';
|
||||||
|
|
||||||
export const FIRST_KEY_INDEX = 2;
|
export const FIRST_KEY_INDEX = 2;
|
||||||
|
|
||||||
export const IS_READ_ONLY = true;
|
|
||||||
|
|
||||||
export function transformArguments(
|
export function transformArguments(
|
||||||
keys: string | Array<string>,
|
keys: RedisCommandArgument | Array<RedisCommandArgument>,
|
||||||
options: ZMPopOptions
|
side: SortedSetSide,
|
||||||
|
options?: ZMPopOptions
|
||||||
): RedisCommandArguments {
|
): RedisCommandArguments {
|
||||||
return transformZMPopArguments(['ZMPOP'], keys, options);
|
return transformZMPopArguments(
|
||||||
|
['ZMPOP'],
|
||||||
|
keys,
|
||||||
|
side,
|
||||||
|
options
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
type ZMPopRawReply = null | [string, Array<[RedisCommandArgument, RedisCommandArgument]>];
|
type ZMPopRawReply = null | [
|
||||||
|
key: string,
|
||||||
type ZMPopReply = null | [
|
elements: Array<[RedisCommandArgument, RedisCommandArgument]>
|
||||||
key: string,
|
|
||||||
elements: Array<ZMember>
|
|
||||||
];
|
];
|
||||||
|
|
||||||
export function transformReply(reply: ZMPopRawReply): ZMPopReply {
|
type ZMPopReply = null | {
|
||||||
if (reply == null) return null;
|
key: string,
|
||||||
|
elements: Array<ZMember>
|
||||||
|
};
|
||||||
|
|
||||||
return [reply[0], reply[1].map(transformSortedSetMemberReply)];
|
export function transformReply(reply: ZMPopRawReply): ZMPopReply {
|
||||||
|
return reply === null ? null : {
|
||||||
|
key: reply[0],
|
||||||
|
elements: reply[1].map(transformSortedSetMemberReply)
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
@@ -157,20 +157,21 @@ export function transformSortedSetWithScoresReply(reply: Array<RedisCommandArgum
|
|||||||
return members;
|
return members;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type SortedSetSide = 'MIN' | 'MAX';
|
||||||
|
|
||||||
export interface ZMPopOptions {
|
export interface ZMPopOptions {
|
||||||
SCORE: 'MIN' | 'MAX';
|
|
||||||
COUNT?: number;
|
COUNT?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function transformZMPopArguments(
|
export function transformZMPopArguments(
|
||||||
args: RedisCommandArguments,
|
args: RedisCommandArguments,
|
||||||
keys: string | Array<string>,
|
keys: RedisCommandArgument | Array<RedisCommandArgument>,
|
||||||
options: ZMPopOptions
|
side: SortedSetSide,
|
||||||
|
options?: ZMPopOptions
|
||||||
): RedisCommandArguments {
|
): RedisCommandArguments {
|
||||||
pushVerdictArgument(args, keys);
|
pushVerdictArgument(args, keys);
|
||||||
|
|
||||||
args.push(options.SCORE);
|
args.push(side);
|
||||||
|
|
||||||
if (options?.COUNT) {
|
if (options?.COUNT) {
|
||||||
args.push('COUNT', options.COUNT.toString());
|
args.push('COUNT', options.COUNT.toString());
|
||||||
@@ -179,19 +180,21 @@ export function transformZMPopArguments(
|
|||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type ListSide = 'LEFT' | 'RIGHT';
|
||||||
|
|
||||||
export interface LMPopOptions {
|
export interface LMPopOptions {
|
||||||
SIDE: 'LEFT' | 'RIGHT';
|
|
||||||
COUNT?: number;
|
COUNT?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function transformLMPopArguments(
|
export function transformLMPopArguments(
|
||||||
args: RedisCommandArguments,
|
args: RedisCommandArguments,
|
||||||
keys: string | Array<string>,
|
keys: RedisCommandArgument | Array<RedisCommandArgument>,
|
||||||
options: LMPopOptions
|
side: ListSide,
|
||||||
|
options?: LMPopOptions
|
||||||
): RedisCommandArguments {
|
): RedisCommandArguments {
|
||||||
pushVerdictArgument(args, keys);
|
pushVerdictArgument(args, keys);
|
||||||
|
|
||||||
args.push(options.SIDE);
|
args.push(side);
|
||||||
|
|
||||||
if (options?.COUNT) {
|
if (options?.COUNT) {
|
||||||
args.push('COUNT', options.COUNT.toString());
|
args.push('COUNT', options.COUNT.toString());
|
||||||
|
Reference in New Issue
Block a user