diff --git a/packages/client/lib/commands/ZUNION.spec.ts b/packages/client/lib/commands/ZUNION.spec.ts index b988290604..a8aad53803 100644 --- a/packages/client/lib/commands/ZUNION.spec.ts +++ b/packages/client/lib/commands/ZUNION.spec.ts @@ -1,48 +1,51 @@ -// import { strict as assert } from 'assert'; -// import testUtils, { GLOBAL } from '../test-utils'; -// import { transformArguments } from './ZUNION'; +import { strict as assert } from 'assert'; +import testUtils, { GLOBAL } from '../test-utils'; +import ZUNION from './ZUNION'; -// describe('ZUNION', () => { -// testUtils.isVersionGreaterThanHook([6, 2]); +describe('ZUNION', () => { + testUtils.isVersionGreaterThanHook([6, 2]); -// describe('transformArguments', () => { -// it('key (string)', () => { -// assert.deepEqual( -// transformArguments('key'), -// ['ZUNION', '1', 'key'] -// ); -// }); + describe('transformArguments', () => { + it('key (string)', () => { + assert.deepEqual( + ZUNION.transformArguments('key'), + ['ZUNION', '1', 'key'] + ); + }); -// it('keys (array)', () => { -// assert.deepEqual( -// transformArguments(['1', '2']), -// ['ZUNION', '2', '1', '2'] -// ); -// }); + it('keys (array)', () => { + assert.deepEqual( + ZUNION.transformArguments(['1', '2']), + ['ZUNION', '2', '1', '2'] + ); + }); -// it('with WEIGHTS', () => { -// assert.deepEqual( -// transformArguments('key', { -// WEIGHTS: [1] -// }), -// ['ZUNION', '1', 'key', 'WEIGHTS', '1'] -// ); -// }); + it('with WEIGHTS', () => { + assert.deepEqual( + ZUNION.transformArguments('key', { + WEIGHTS: [1] + }), + ['ZUNION', '1', 'key', 'WEIGHTS', '1'] + ); + }); -// it('with AGGREGATE', () => { -// assert.deepEqual( -// transformArguments('key', { -// AGGREGATE: 'SUM' -// }), -// ['ZUNION', '1', 'key', 'AGGREGATE', 'SUM'] -// ); -// }); -// }); + it('with AGGREGATE', () => { + assert.deepEqual( + ZUNION.transformArguments('key', { + AGGREGATE: 'SUM' + }), + ['ZUNION', '1', 'key', 'AGGREGATE', 'SUM'] + ); + }); + }); -// testUtils.testWithClient('client.zUnion', async client => { -// assert.deepEqual( -// await client.zUnion('key'), -// [] -// ); -// }, GLOBAL.SERVERS.OPEN); -// }); + testUtils.testAll('client.zUnion', async client => { + assert.deepEqual( + await client.zUnion('key'), + [] + ); + }, { + client: GLOBAL.SERVERS.OPEN, + cluster: GLOBAL.CLUSTERS.OPEN + }); +}); diff --git a/packages/client/lib/commands/ZUNION.ts b/packages/client/lib/commands/ZUNION.ts index 537aecc850..f9eb06fbdf 100644 --- a/packages/client/lib/commands/ZUNION.ts +++ b/packages/client/lib/commands/ZUNION.ts @@ -1,30 +1,29 @@ -// import { RedisCommandArgument, RedisCommandArguments } from '.'; -// import { pushVariadicArgument } from './generic-transformers'; +import { ArrayReply, BlobStringReply, Command } from '../RESP/types'; +import { RedisVariadicArgument, pushVariadicArgument } from './generic-transformers'; -// export const FIRST_KEY_INDEX = 2; +export interface ZUnionOptions { + WEIGHTS?: Array; + AGGREGATE?: 'SUM' | 'MIN' | 'MAX'; +} -// export const IS_READ_ONLY = true; +export default { + FIRST_KEY_INDEX: 2, + IS_READ_ONLY: true, + transformArguments( + keys: RedisVariadicArgument, + options?: ZUnionOptions + ) { + const args = pushVariadicArgument(['ZUNION'], keys); -// interface ZUnionOptions { -// WEIGHTS?: Array; -// AGGREGATE?: 'SUM' | 'MIN' | 'MAX'; -// } + if (options?.WEIGHTS) { + args.push('WEIGHTS', ...options.WEIGHTS.map(weight => weight.toString())); + } -// export function transformArguments( -// keys: Array | RedisCommandArgument, -// options?: ZUnionOptions -// ): RedisCommandArguments { -// const args = pushVariadicArgument(['ZUNION'], keys); + if (options?.AGGREGATE) { + args.push('AGGREGATE', options.AGGREGATE); + } -// 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; + return args; + }, + transformReply: undefined as unknown as () => ArrayReply +} as const satisfies Command; diff --git a/packages/client/lib/commands/index.ts b/packages/client/lib/commands/index.ts index 491e0b3224..0d435c6a4c 100644 --- a/packages/client/lib/commands/index.ts +++ b/packages/client/lib/commands/index.ts @@ -170,6 +170,7 @@ import ZREM from './ZREM'; import ZREVRANK from './ZREVRANK'; import ZSCAN from './ZSCAN'; import ZSCORE from './ZSCORE'; +import ZUNION from './ZUNION'; import { Command } from '../RESP/types'; export default { @@ -517,5 +518,7 @@ export default { ZSCAN, zScan: ZSCAN, ZSCORE, - zScore: ZSCORE + zScore: ZSCORE, + ZUNION, + zUnion: ZUNION } as const satisfies Record; diff --git a/todo.md b/todo.md index 3be2364f5c..adb88fe025 100644 --- a/todo.md +++ b/todo.md @@ -1,6 +1,7 @@ # return type \ missing documentation - `XAUTOCLAIM` - `XSETID` +- `ZUNION` # create commands @@ -12,14 +13,8 @@ # waiting List -- `BZMPOP.ts` -- `BZPOPMAX.ts` -- `BZPOPMIN.ts` - `ZRANGEBYSCORE.ts` - `ZRANGEBYLEX.ts` -- `ZPOPMIN.ts` -- `ZPOPMAX.ts` -- `ZMPOP.ts` - `ZUNION.ts` - `ZREMRANGEBYLEX.ts` - `ZREMRANGEBYRANK.ts` @@ -27,6 +22,14 @@ - `ZUNION.ts` - `ZUNIONSTORE.ts` +# fot leiba +- `BZMPOP.ts` +- `BZPOPMAX.ts` +- `BZPOPMIN.ts` +- `ZMPOP.ts` +- `ZPOPMAX.ts` +- `ZPOPMIN.ts` + # other