1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00

fix ZUNION

This commit is contained in:
dovi
2023-05-02 17:27:57 -04:00
parent afa394e35d
commit e1727d16a1
4 changed files with 82 additions and 74 deletions

View File

@@ -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
});
});

View File

@@ -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<number>;
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<number>;
// AGGREGATE?: 'SUM' | 'MIN' | 'MAX';
// }
if (options?.WEIGHTS) {
args.push('WEIGHTS', ...options.WEIGHTS.map(weight => weight.toString()));
}
// export function transformArguments(
// keys: Array<RedisCommandArgument> | 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<RedisCommandArgument>;
return args;
},
transformReply: undefined as unknown as () => ArrayReply<BlobStringReply>
} as const satisfies Command;

View File

@@ -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<string, Command>;

15
todo.md
View File

@@ -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