diff --git a/packages/client/lib/commands/BLMPOP.spec.ts b/packages/client/lib/commands/BLMPOP.spec.ts index 510549fd48..730306ba9b 100644 --- a/packages/client/lib/commands/BLMPOP.spec.ts +++ b/packages/client/lib/commands/BLMPOP.spec.ts @@ -8,17 +8,14 @@ describe('BLMPOP', () => { describe('transformArguments', () => { it('simple', () => { assert.deepEqual( - transformArguments(0, 'key', { - SIDE: 'LEFT' - }), + transformArguments(0, 'key', 'LEFT'), ['BLMPOP', '0', '1', 'key', 'LEFT'] ); }); - it('with score and count', () => { + it('with COUNT', () => { assert.deepEqual( - transformArguments(0, 'key', { - SIDE: 'LEFT', + transformArguments(0, 'key', 'LEFT', { COUNT: 2 }), ['BLMPOP', '0', '1', 'key', 'LEFT', 'COUNT', '2'] @@ -28,9 +25,7 @@ describe('BLMPOP', () => { testUtils.testWithClient('client.zmScore', async client => { assert.deepEqual( - await client.blmPop(0, 'key', { - SIDE: 'LEFT' - }), + await client.blmPop(0, 'key', 'RIGHT'), null ); }, GLOBAL.SERVERS.OPEN); diff --git a/packages/client/lib/commands/BLMPOP.ts b/packages/client/lib/commands/BLMPOP.ts index 343f077b3e..11bfad8b99 100644 --- a/packages/client/lib/commands/BLMPOP.ts +++ b/packages/client/lib/commands/BLMPOP.ts @@ -1,14 +1,20 @@ -import { RedisCommandArguments } from '.'; -import { transformLMPopArguments, LMPopOptions } from './generic-transformers'; +import { RedisCommandArgument, RedisCommandArguments } from '.'; +import { transformLMPopArguments, LMPopOptions, ListSide } from './generic-transformers'; export const FIRST_KEY_INDEX = 3; export function transformArguments( timeout: number, - keys: string | Array, - options: LMPopOptions + keys: RedisCommandArgument | Array, + side: ListSide, + options?: LMPopOptions ): RedisCommandArguments { - return transformLMPopArguments(['BLMPOP', timeout.toString()], keys, options); + return transformLMPopArguments( + ['BLMPOP', timeout.toString()], + keys, + side, + options + ); } export { transformReply } from './LMPOP'; diff --git a/packages/client/lib/commands/BZMPOP.spec.ts b/packages/client/lib/commands/BZMPOP.spec.ts index 8fd0b34184..7385d898bc 100644 --- a/packages/client/lib/commands/BZMPOP.spec.ts +++ b/packages/client/lib/commands/BZMPOP.spec.ts @@ -8,17 +8,14 @@ describe('BZMPOP', () => { describe('transformArguments', () => { it('simple', () => { assert.deepEqual( - transformArguments(0, 'key', { - SCORE: 'MIN' - }), + transformArguments(0, 'key', 'MIN'), ['BZMPOP', '0', '1', 'key', 'MIN'] ); }); - it('with score and count', () => { + it('with COUNT', () => { assert.deepEqual( - transformArguments(0, 'key', { - SCORE: 'MIN', + transformArguments(0, '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( - await client.bzmPop(0, 'key', { - SCORE: 'MAX' - }), + await client.bzmPop(0, 'key', 'MAX'), null ); }, GLOBAL.SERVERS.OPEN); diff --git a/packages/client/lib/commands/BZMPOP.ts b/packages/client/lib/commands/BZMPOP.ts index 25336b8ae5..e4e9699cbd 100644 --- a/packages/client/lib/commands/BZMPOP.ts +++ b/packages/client/lib/commands/BZMPOP.ts @@ -1,14 +1,20 @@ -import { RedisCommandArguments } from '.'; -import { transformZMPopArguments, ZMPopOptions } from './generic-transformers'; +import { RedisCommandArgument, RedisCommandArguments } from '.'; +import { SortedSetSide, transformZMPopArguments, ZMPopOptions } from './generic-transformers'; export const FIRST_KEY_INDEX = 3; export function transformArguments( timeout: number, - keys: string | Array, - options: ZMPopOptions + keys: RedisCommandArgument | Array, + side: SortedSetSide, + options?: ZMPopOptions ): RedisCommandArguments { - return transformZMPopArguments(['BZMPOP', timeout.toString()], keys, options); + return transformZMPopArguments( + ['BZMPOP', timeout.toString()], + keys, + side, + options + ); } export { transformReply } from './ZMPOP'; diff --git a/packages/client/lib/commands/LMOVE.ts b/packages/client/lib/commands/LMOVE.ts index 7332d1a007..849c6385f5 100644 --- a/packages/client/lib/commands/LMOVE.ts +++ b/packages/client/lib/commands/LMOVE.ts @@ -1,14 +1,13 @@ import { RedisCommandArgument, RedisCommandArguments } from '.'; +import { ListSide } from './generic-transformers'; export const FIRST_KEY_INDEX = 1; -export type LMoveSide = 'LEFT' | 'RIGHT'; - export function transformArguments( source: RedisCommandArgument, destination: RedisCommandArgument, - sourceSide: LMoveSide, - destinationSide: LMoveSide + sourceSide: ListSide, + destinationSide: ListSide ): RedisCommandArguments { return [ 'LMOVE', diff --git a/packages/client/lib/commands/LMPOP.spec.ts b/packages/client/lib/commands/LMPOP.spec.ts index 80ebfeabca..a3c36f9021 100644 --- a/packages/client/lib/commands/LMPOP.spec.ts +++ b/packages/client/lib/commands/LMPOP.spec.ts @@ -8,17 +8,14 @@ describe('LMPOP', () => { describe('transformArguments', () => { it('simple', () => { assert.deepEqual( - transformArguments('key', { - SIDE: 'LEFT' - }), + transformArguments('key', 'LEFT'), ['LMPOP', '1', 'key', 'LEFT'] ); }); - it('with score and count', () => { + it('with COUNT', () => { assert.deepEqual( - transformArguments('key', { - SIDE: 'LEFT', + transformArguments('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( - await client.lmPop('key', { - SIDE: 'RIGHT' - }), + await client.lmPop('key', 'RIGHT'), null ); }, GLOBAL.SERVERS.OPEN); diff --git a/packages/client/lib/commands/LMPOP.ts b/packages/client/lib/commands/LMPOP.ts index e9034a1dc5..29d868b982 100644 --- a/packages/client/lib/commands/LMPOP.ts +++ b/packages/client/lib/commands/LMPOP.ts @@ -1,20 +1,22 @@ -import { RedisCommandArguments } from '.'; -import { transformLMPopArguments, LMPopOptions } from './generic-transformers'; +import { RedisCommandArgument, RedisCommandArguments } from '.'; +import { transformLMPopArguments, LMPopOptions, ListSide } from './generic-transformers'; export const FIRST_KEY_INDEX = 2; -export const IS_READ_ONLY = true; - export function transformArguments( - keys: string | Array, - options: LMPopOptions + keys: RedisCommandArgument | Array, + side: ListSide, + options?: LMPopOptions ): RedisCommandArguments { - return transformLMPopArguments(['LMPOP'], keys, options); + return transformLMPopArguments( + ['LMPOP'], + keys, + side, + options + ); } -type LMPopReply = null | [ - key: string, - elements: Array +export declare function transformReply(): null | [ + key: string, + elements: Array ]; - -export declare function transformReply(): LMPopReply; diff --git a/packages/client/lib/commands/ZMPOP.spec.ts b/packages/client/lib/commands/ZMPOP.spec.ts index 7a82641c43..5e16909e4f 100644 --- a/packages/client/lib/commands/ZMPOP.spec.ts +++ b/packages/client/lib/commands/ZMPOP.spec.ts @@ -8,17 +8,14 @@ describe('ZMPOP', () => { describe('transformArguments', () => { it('simple', () => { assert.deepEqual( - transformArguments('key', { - SCORE: 'MIN' - }), + transformArguments('key', 'MIN'), ['ZMPOP', '1', 'key', 'MIN'] ); }); it('with score and count', () => { assert.deepEqual( - transformArguments('key', { - SCORE: 'MIN', + transformArguments('key', 'MIN', { COUNT: 2 }), ['ZMPOP', '1', 'key', 'MIN', 'COUNT', '2'] @@ -28,9 +25,7 @@ describe('ZMPOP', () => { testUtils.testWithClient('client.zmScore', async client => { assert.deepEqual( - await client.zmPop('key', { - SCORE: 'MAX' - }), + await client.zmPop('key', 'MIN'), null ); }, GLOBAL.SERVERS.OPEN); diff --git a/packages/client/lib/commands/ZMPOP.ts b/packages/client/lib/commands/ZMPOP.ts index 556722fc51..0baa46bbf0 100644 --- a/packages/client/lib/commands/ZMPOP.ts +++ b/packages/client/lib/commands/ZMPOP.ts @@ -1,26 +1,34 @@ 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 IS_READ_ONLY = true; - export function transformArguments( - keys: string | Array, - options: ZMPopOptions + keys: RedisCommandArgument | Array, + side: SortedSetSide, + options?: ZMPopOptions ): RedisCommandArguments { - return transformZMPopArguments(['ZMPOP'], keys, options); + return transformZMPopArguments( + ['ZMPOP'], + keys, + side, + options + ); } -type ZMPopRawReply = null | [string, Array<[RedisCommandArgument, RedisCommandArgument]>]; - -type ZMPopReply = null | [ - key: string, - elements: Array +type ZMPopRawReply = null | [ + key: string, + elements: Array<[RedisCommandArgument, RedisCommandArgument]> ]; -export function transformReply(reply: ZMPopRawReply): ZMPopReply { - if (reply == null) return null; +type ZMPopReply = null | { + key: string, + elements: Array +}; - 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) + }; } diff --git a/packages/client/lib/commands/generic-transformers.ts b/packages/client/lib/commands/generic-transformers.ts index 24bfd0d5de..e881822fb4 100644 --- a/packages/client/lib/commands/generic-transformers.ts +++ b/packages/client/lib/commands/generic-transformers.ts @@ -157,20 +157,21 @@ export function transformSortedSetWithScoresReply(reply: Array, - options: ZMPopOptions + keys: RedisCommandArgument | Array, + side: SortedSetSide, + options?: ZMPopOptions ): RedisCommandArguments { pushVerdictArgument(args, keys); - args.push(options.SCORE); + args.push(side); if (options?.COUNT) { args.push('COUNT', options.COUNT.toString()); @@ -179,19 +180,21 @@ export function transformZMPopArguments( return args; } +export type ListSide = 'LEFT' | 'RIGHT'; + export interface LMPopOptions { - SIDE: 'LEFT' | 'RIGHT'; COUNT?: number; } export function transformLMPopArguments( args: RedisCommandArguments, - keys: string | Array, - options: LMPopOptions + keys: RedisCommandArgument | Array, + side: ListSide, + options?: LMPopOptions ): RedisCommandArguments { pushVerdictArgument(args, keys); - args.push(options.SIDE); + args.push(side); if (options?.COUNT) { args.push('COUNT', options.COUNT.toString());