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

some tests

This commit is contained in:
Leibale
2023-04-27 17:43:29 -04:00
parent 7bacad2e69
commit 53ac48f298
42 changed files with 1405 additions and 1259 deletions

View File

@@ -1,127 +1,158 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './ZADD'; import ZADD from './ZADD';
describe('ZADD', () => { describe('ZADD', () => {
describe('transformArguments', () => { describe('transformArguments', () => {
it('single member', () => { it('single member', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key', { ZADD.transformArguments('key', {
value: '1', value: '1',
score: 1 score: 1
}), }),
['ZADD', 'key', '1', '1'] ['ZADD', 'key', '1', '1']
); );
});
it('multiple members', () => {
assert.deepEqual(
transformArguments('key', [{
value: '1',
score: 1
}, {
value: '2',
score: 2
}]),
['ZADD', 'key', '1', '1', '2', '2']
);
});
it('with NX', () => {
assert.deepEqual(
transformArguments('key', {
value: '1',
score: 1
}, {
NX: true
}),
['ZADD', 'key', 'NX', '1', '1']
);
});
it('with XX', () => {
assert.deepEqual(
transformArguments('key', {
value: '1',
score: 1
}, {
XX: true
}),
['ZADD', 'key', 'XX', '1', '1']
);
});
it('with GT', () => {
assert.deepEqual(
transformArguments('key', {
value: '1',
score: 1
}, {
GT: true
}),
['ZADD', 'key', 'GT', '1', '1']
);
});
it('with LT', () => {
assert.deepEqual(
transformArguments('key', {
value: '1',
score: 1
}, {
LT: true
}),
['ZADD', 'key', 'LT', '1', '1']
);
});
it('with CH', () => {
assert.deepEqual(
transformArguments('key', {
value: '1',
score: 1
}, {
CH: true
}),
['ZADD', 'key', 'CH', '1', '1']
);
});
it('with INCR', () => {
assert.deepEqual(
transformArguments('key', {
value: '1',
score: 1
}, {
INCR: true
}),
['ZADD', 'key', 'INCR', '1', '1']
);
});
it('with XX, GT, CH, INCR', () => {
assert.deepEqual(
transformArguments('key', {
value: '1',
score: 1
}, {
XX: true,
GT: true,
CH: true,
INCR: true
}),
['ZADD', 'key', 'XX', 'GT', 'CH', 'INCR', '1', '1']
);
});
}); });
testUtils.testWithClient('client.zAdd', async client => { it('multiple members', () => {
assert.equal( assert.deepEqual(
await client.zAdd('key', { ZADD.transformArguments('key', [{
value: '1', value: '1',
score: 1 score: 1
}), }, {
1 value: '2',
score: 2
}]),
['ZADD', 'key', '1', '1', '2', '2']
);
});
describe('with condition', () => {
it('condition property', () => {
assert.deepEqual(
ZADD.transformArguments('key', {
value: '1',
score: 1
}, {
condition: 'NX'
}),
['ZADD', 'key', 'NX', '1', '1']
); );
}, GLOBAL.SERVERS.OPEN); });
it('with NX (backwards compatibility)', () => {
assert.deepEqual(
ZADD.transformArguments('key', {
value: '1',
score: 1
}, {
NX: true
}),
['ZADD', 'key', 'NX', '1', '1']
);
});
it('with XX (backwards compatibility)', () => {
assert.deepEqual(
ZADD.transformArguments('key', {
value: '1',
score: 1
}, {
XX: true
}),
['ZADD', 'key', 'XX', '1', '1']
);
});
});
describe('with comparison', () => {
it('with LT', () => {
assert.deepEqual(
ZADD.transformArguments('key', {
value: '1',
score: 1
}, {
comparison: 'LT'
}),
['ZADD', 'key', 'LT', '1', '1']
);
});
it('with LT (backwards compatibility)', () => {
assert.deepEqual(
ZADD.transformArguments('key', {
value: '1',
score: 1
}, {
LT: true
}),
['ZADD', 'key', 'LT', '1', '1']
);
});
it('with GT (backwards compatibility)', () => {
assert.deepEqual(
ZADD.transformArguments('key', {
value: '1',
score: 1
}, {
GT: true
}),
['ZADD', 'key', 'GT', '1', '1']
);
});
});
it('with CH', () => {
assert.deepEqual(
ZADD.transformArguments('key', {
value: '1',
score: 1
}, {
CH: true
}),
['ZADD', 'key', 'CH', '1', '1']
);
});
it('with INCR', () => {
assert.deepEqual(
ZADD.transformArguments('key', {
value: '1',
score: 1
}, {
INCR: true
}),
['ZADD', 'key', 'INCR', '1', '1']
);
});
it('with condition, comparison, CH, INCR', () => {
assert.deepEqual(
ZADD.transformArguments('key', {
value: '1',
score: 1
}, {
condition: 'XX',
comparison: 'LT',
CH: true,
INCR: true
}),
['ZADD', 'key', 'XX', 'LT', 'CH', 'INCR', '1', '1']
);
});
});
testUtils.testAll('zAdd', async client => {
assert.equal(
await client.zAdd('key', {
value: '1',
score: 1
}),
1
);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
}); });

View File

@@ -1,32 +1,29 @@
import { RedisArgument, NumberReply, DoubleReply, Command } from '../RESP/types'; import { RedisArgument, NumberReply, DoubleReply, Command } from '../RESP/types';
import { ZMember, transformDoubleArgument, transformDoubleReply } from './generic-transformers'; import { ZMember, transformDoubleArgument, transformDoubleReply } from './generic-transformers';
interface NX { export interface ZAddOptions {
condition?: 'NX' | 'XX';
/**
* @deprecated Use `{ condition: 'NX' }` instead.
*/
NX?: boolean; NX?: boolean;
} /**
* @deprecated Use `{ condition: 'XX' }` instead.
interface XX { */
XX?: boolean; XX?: boolean;
} comparison?: 'LT' | 'GT';
/**
interface LT { * @deprecated Use `{ comparison: 'LT' }` instead.
*/
LT?: boolean; LT?: boolean;
} /**
* @deprecated Use `{ comparison: 'GT' }` instead.
interface GT { */
GT?: boolean; GT?: boolean;
}
interface CH {
CH?: boolean; CH?: boolean;
}
interface INCR {
INCR?: boolean; INCR?: boolean;
} }
export type ZAddOptions = (NX | (XX & LT & GT)) & CH & INCR;
export default { export default {
FIRST_KEY_INDEX: 1, FIRST_KEY_INDEX: 1,
transformArguments( transformArguments(
@@ -36,35 +33,36 @@ export default {
) { ) {
const args = ['ZADD', key]; const args = ['ZADD', key];
if ((<NX>options)?.NX) { if (options?.condition) {
args.push(options.condition);
} else if (options?.NX) {
args.push('NX'); args.push('NX');
} else { } else if (options?.XX) {
if ((<XX>options)?.XX) { args.push('XX');
args.push('XX'); }
}
if ((<GT>options)?.GT) { if (options?.comparison) {
args.push('GT'); args.push(options.comparison);
} } else if (options?.LT) {
args.push('LT');
if ((<LT>options)?.LT) { } else if (options?.GT) {
args.push('LT'); args.push('GT');
}
} }
if ((<CH>options)?.CH) { if (options?.CH) {
args.push('CH'); args.push('CH');
} }
if ((<INCR>options)?.INCR) { if (options?.INCR) {
args.push('INCR'); args.push('INCR');
} }
for (const { score, value } of (Array.isArray(members) ? members : [members])) { if (Array.isArray(members)) {
args.push( for (const member of members) {
transformDoubleArgument(score), pushMember(args, member);
value }
); } else {
pushMember(args, members);
} }
return args; return args;
@@ -74,3 +72,10 @@ export default {
3: undefined as unknown as () => NumberReply | DoubleReply 3: undefined as unknown as () => NumberReply | DoubleReply
} }
} as const satisfies Command; } as const satisfies Command;
function pushMember(args: Array<RedisArgument>, member: ZMember) {
args.push(
transformDoubleArgument(member.score),
member.value
);
}

View File

@@ -1,19 +1,22 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './ZCARD'; import ZCARD from './ZCARD';
describe('ZCARD', () => { describe('ZCARD', () => {
it('transformArguments', () => { it('transformArguments', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key'), ZCARD.transformArguments('key'),
['ZCARD', 'key'] ['ZCARD', 'key']
); );
}); });
testUtils.testWithClient('client.zCard', async client => { testUtils.testAll('zCard', async client => {
assert.equal( assert.equal(
await client.zCard('key'), await client.zCard('key'),
0 0
); );
}, GLOBAL.SERVERS.OPEN); }, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
}); });

View File

@@ -1,19 +1,22 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './ZCOUNT'; import ZCOUNT from './ZCOUNT';
describe('ZCOUNT', () => { describe('ZCOUNT', () => {
it('transformArguments', () => { it('transformArguments', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key', 0, 1), ZCOUNT.transformArguments('key', 0, 1),
['ZCOUNT', 'key', '0', '1'] ['ZCOUNT', 'key', '0', '1']
); );
}); });
testUtils.testWithClient('client.zCount', async client => { testUtils.testAll('zCount', async client => {
assert.equal( assert.equal(
await client.zCount('key', 0, 1), await client.zCount('key', 0, 1),
0 0
); );
}, GLOBAL.SERVERS.OPEN); }, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.SERVERS.OPEN
});
}); });

View File

@@ -1,30 +1,33 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './ZDIFF'; import ZDIFF from './ZDIFF';
describe('ZDIFF', () => { describe('ZDIFF', () => {
testUtils.isVersionGreaterThanHook([6, 2]); testUtils.isVersionGreaterThanHook([6, 2]);
describe('transformArguments', () => { describe('transformArguments', () => {
it('string', () => { it('string', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key'), ZDIFF.transformArguments('key'),
['ZDIFF', '1', 'key'] ['ZDIFF', '1', 'key']
); );
});
it('array', () => {
assert.deepEqual(
transformArguments(['1', '2']),
['ZDIFF', '2', '1', '2']
);
});
}); });
testUtils.testWithClient('client.zDiff', async client => { it('array', () => {
assert.deepEqual( assert.deepEqual(
await client.zDiff('key'), ZDIFF.transformArguments(['1', '2']),
[] ['ZDIFF', '2', '1', '2']
); );
}, GLOBAL.SERVERS.OPEN); });
});
testUtils.testAll('zDiff', async client => {
assert.deepEqual(
await client.zDiff('key'),
[]
);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
}); });

View File

@@ -1,30 +1,33 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './ZDIFFSTORE'; import ZDIFFSTORE from './ZDIFFSTORE';
describe('ZDIFFSTORE', () => { describe('ZDIFFSTORE', () => {
testUtils.isVersionGreaterThanHook([6, 2]); testUtils.isVersionGreaterThanHook([6, 2]);
describe('transformArguments', () => { describe('transformArguments', () => {
it('string', () => { it('string', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('destination', 'key'), ZDIFFSTORE.transformArguments('destination', 'key'),
['ZDIFFSTORE', 'destination', '1', 'key'] ['ZDIFFSTORE', 'destination', '1', 'key']
); );
});
it('array', () => {
assert.deepEqual(
transformArguments('destination', ['1', '2']),
['ZDIFFSTORE', 'destination', '2', '1', '2']
);
});
}); });
testUtils.testWithClient('client.zDiffStore', async client => { it('array', () => {
assert.equal( assert.deepEqual(
await client.zDiffStore('destination', 'key'), ZDIFFSTORE.transformArguments('destination', ['1', '2']),
0 ['ZDIFFSTORE', 'destination', '2', '1', '2']
); );
}, GLOBAL.SERVERS.OPEN); });
});
testUtils.testAll('zDiffStore', async client => {
assert.equal(
await client.zDiffStore('{tag}destination', '{tag}key'),
0
);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
}); });

View File

@@ -1,30 +1,33 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './ZDIFF_WITHSCORES'; import ZDIFF_WITHSCORES from './ZDIFF_WITHSCORES';
describe('ZDIFF WITHSCORES', () => { describe('ZDIFF WITHSCORES', () => {
testUtils.isVersionGreaterThanHook([6, 2]); testUtils.isVersionGreaterThanHook([6, 2]);
describe('transformArguments', () => { describe('transformArguments', () => {
it('string', () => { it('string', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key'), ZDIFF_WITHSCORES.transformArguments('key'),
['ZDIFF', '1', 'key', 'WITHSCORES'] ['ZDIFF', '1', 'key', 'WITHSCORES']
); );
});
it('array', () => {
assert.deepEqual(
transformArguments(['1', '2']),
['ZDIFF', '2', '1', '2', 'WITHSCORES']
);
});
}); });
testUtils.testWithClient('client.zDiffWithScores', async client => { it('array', () => {
assert.deepEqual( assert.deepEqual(
await client.zDiffWithScores('key'), ZDIFF_WITHSCORES.transformArguments(['1', '2']),
[] ['ZDIFF', '2', '1', '2', 'WITHSCORES']
); );
}, GLOBAL.SERVERS.OPEN); });
});
testUtils.testAll('zDiffWithScores', async client => {
assert.deepEqual(
await client.zDiffWithScores('key'),
[]
);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
}); });

View File

@@ -1,19 +1,22 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './ZINCRBY'; import ZINCRBY from './ZINCRBY';
describe('ZINCRBY', () => { describe('ZINCRBY', () => {
it('transformArguments', () => { it('transformArguments', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key', 1, 'member'), ZINCRBY.transformArguments('key', 1, 'member'),
['ZINCRBY', 'key', '1', 'member'] ['ZINCRBY', 'key', '1', 'member']
); );
}); });
testUtils.testWithClient('client.zIncrBy', async client => { testUtils.testAll('zIncrBy', async client => {
assert.equal( assert.equal(
await client.zIncrBy('destination', 1, 'member'), await client.zIncrBy('destination', 1, 'member'),
1 1
); );
}, GLOBAL.SERVERS.OPEN); }, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
}); });

View File

@@ -1,58 +1,65 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './ZINTER'; import ZINTER from './ZINTER';
describe('ZINTER', () => { describe('ZINTER', () => {
testUtils.isVersionGreaterThanHook([6, 2]); testUtils.isVersionGreaterThanHook([6, 2]);
describe('transformArguments', () => { describe('transformArguments', () => {
it('key (string)', () => { it('key (string)', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key'), ZINTER.transformArguments('key'),
['ZINTER', '1', 'key'] ['ZINTER', '1', 'key']
); );
});
it('keys (array)', () => {
assert.deepEqual(
transformArguments(['1', '2']),
['ZINTER', '2', '1', '2']
);
});
it('with WEIGHTS', () => {
assert.deepEqual(
transformArguments('key', {
WEIGHTS: [1]
}),
['ZINTER', '1', 'key', 'WEIGHTS', '1']
);
});
it('with AGGREGATE', () => {
assert.deepEqual(
transformArguments('key', {
AGGREGATE: 'SUM'
}),
['ZINTER', '1', 'key', 'AGGREGATE', 'SUM']
);
});
it('with WEIGHTS, AGGREGATE', () => {
assert.deepEqual(
transformArguments('key', {
WEIGHTS: [1],
AGGREGATE: 'SUM'
}),
['ZINTER', '1', 'key', 'WEIGHTS', '1', 'AGGREGATE', 'SUM']
);
});
}); });
testUtils.testWithClient('client.zInter', async client => { it('keys (Array<string>)', () => {
assert.deepEqual( assert.deepEqual(
await client.zInter('key'), ZINTER.transformArguments(['1', '2']),
[] ['ZINTER', '2', '1', '2']
); );
}, GLOBAL.SERVERS.OPEN); });
it('key & weight', () => {
assert.deepEqual(
ZINTER.transformArguments({
key: 'key',
weight: 1
}),
['ZINTER', '1', 'key', 'WEIGHTS', '1']
);
});
it('keys & weights', () => {
assert.deepEqual(
ZINTER.transformArguments([{
key: 'a',
weight: 1
}, {
key: 'b',
weight: 2
}]),
['ZINTER', '2', 'a', 'b', 'WEIGHTS', '1', '2']
);
});
it('with AGGREGATE', () => {
assert.deepEqual(
ZINTER.transformArguments('key', {
AGGREGATE: 'SUM'
}),
['ZINTER', '1', 'key', 'AGGREGATE', 'SUM']
);
});
});
testUtils.testAll('zInter', async client => {
assert.deepEqual(
await client.zInter('key'),
[]
);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
}); });

View File

@@ -1,30 +1,33 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './ZINTERCARD'; import ZINTERCARD from './ZINTERCARD';
describe('ZINTERCARD', () => { describe('ZINTERCARD', () => {
testUtils.isVersionGreaterThanHook([7]); testUtils.isVersionGreaterThanHook([7]);
describe('transformArguments', () => { describe('transformArguments', () => {
it('simple', () => { it('simple', () => {
assert.deepEqual( assert.deepEqual(
transformArguments(['1', '2']), ZINTERCARD.transformArguments(['1', '2']),
['ZINTERCARD', '2', '1', '2'] ['ZINTERCARD', '2', '1', '2']
); );
});
it('with limit', () => {
assert.deepEqual(
transformArguments(['1', '2'], 1),
['ZINTERCARD', '2', '1', '2', 'LIMIT', '1']
);
});
}); });
testUtils.testWithClient('client.zInterCard', async client => { it('with limit', () => {
assert.deepEqual( assert.deepEqual(
await client.zInterCard('key'), ZINTERCARD.transformArguments(['1', '2'], 1),
0 ['ZINTERCARD', '2', '1', '2', 'LIMIT', '1']
); );
}, GLOBAL.SERVERS.OPEN); });
});
testUtils.testAll('zInterCard', async client => {
assert.deepEqual(
await client.zInterCard('key'),
0
);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
}); });

View File

@@ -1,56 +1,63 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './ZINTERSTORE'; import ZINTERSTORE from './ZINTERSTORE';
describe('ZINTERSTORE', () => { describe('ZINTERSTORE', () => {
describe('transformArguments', () => { describe('transformArguments', () => {
it('key (string)', () => { it('key (string)', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('destination', 'key'), ZINTERSTORE.transformArguments('destination', 'key'),
['ZINTERSTORE', 'destination', '1', 'key'] ['ZINTERSTORE', 'destination', '1', 'key']
); );
});
it('keys (array)', () => {
assert.deepEqual(
transformArguments('destination', ['1', '2']),
['ZINTERSTORE', 'destination', '2', '1', '2']
);
});
it('with WEIGHTS', () => {
assert.deepEqual(
transformArguments('destination', 'key', {
WEIGHTS: [1]
}),
['ZINTERSTORE', 'destination', '1', 'key', 'WEIGHTS', '1']
);
});
it('with AGGREGATE', () => {
assert.deepEqual(
transformArguments('destination', 'key', {
AGGREGATE: 'SUM'
}),
['ZINTERSTORE', 'destination', '1', 'key', 'AGGREGATE', 'SUM']
);
});
it('with WEIGHTS, AGGREGATE', () => {
assert.deepEqual(
transformArguments('destination', 'key', {
WEIGHTS: [1],
AGGREGATE: 'SUM'
}),
['ZINTERSTORE', 'destination', '1', 'key', 'WEIGHTS', '1', 'AGGREGATE', 'SUM']
);
});
}); });
testUtils.testWithClient('client.zInterStore', async client => { it('keys (Array<string>)', () => {
assert.equal( assert.deepEqual(
await client.zInterStore('destination', 'key'), ZINTERSTORE.transformArguments('destination', ['1', '2']),
0 ['ZINTERSTORE', 'destination', '2', '1', '2']
); );
}, GLOBAL.SERVERS.OPEN); });
it('key & weight', () => {
assert.deepEqual(
ZINTERSTORE.transformArguments('destination', {
key: 'key',
weight: 1
}),
['ZINTERSTORE', 'destination', '1', 'key', 'WEIGHTS', '1']
);
});
it('keys & weights', () => {
assert.deepEqual(
ZINTERSTORE.transformArguments('destination', [{
key: 'a',
weight: 1
}, {
key: 'b',
weight: 2
}]),
['ZINTERSTORE', 'destination', '2', 'a', 'b', 'WEIGHTS', '1', '2']
);
});
it('with AGGREGATE', () => {
assert.deepEqual(
ZINTERSTORE.transformArguments('destination', 'key', {
AGGREGATE: 'SUM'
}),
['ZINTERSTORE', 'destination', '1', 'key', 'AGGREGATE', 'SUM']
);
});
});
testUtils.testAll('zInterStore', async client => {
assert.equal(
await client.zInterStore('{tag}destination', '{tag}key'),
0
);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
}); });

View File

@@ -1,58 +1,65 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './ZINTER_WITHSCORES'; import ZINTER_WITHSCORES from './ZINTER_WITHSCORES';
describe('ZINTER WITHSCORES', () => { describe('ZINTER WITHSCORES', () => {
testUtils.isVersionGreaterThanHook([6, 2]); testUtils.isVersionGreaterThanHook([6, 2]);
describe('transformArguments', () => { describe('transformArguments', () => {
it('key (string)', () => { it('key (string)', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key'), ZINTER_WITHSCORES.transformArguments('key'),
['ZINTER', '1', 'key', 'WITHSCORES'] ['ZINTER', '1', 'key', 'WITHSCORES']
); );
});
it('keys (array)', () => {
assert.deepEqual(
transformArguments(['1', '2']),
['ZINTER', '2', '1', '2', 'WITHSCORES']
);
});
it('with WEIGHTS', () => {
assert.deepEqual(
transformArguments('key', {
WEIGHTS: [1]
}),
['ZINTER', '1', 'key', 'WEIGHTS', '1', 'WITHSCORES']
);
});
it('with AGGREGATE', () => {
assert.deepEqual(
transformArguments('key', {
AGGREGATE: 'SUM'
}),
['ZINTER', '1', 'key', 'AGGREGATE', 'SUM', 'WITHSCORES']
);
});
it('with WEIGHTS, AGGREGATE', () => {
assert.deepEqual(
transformArguments('key', {
WEIGHTS: [1],
AGGREGATE: 'SUM'
}),
['ZINTER', '1', 'key', 'WEIGHTS', '1', 'AGGREGATE', 'SUM', 'WITHSCORES']
);
});
}); });
testUtils.testWithClient('client.zInterWithScores', async client => { it('keys (Array<string>)', () => {
assert.deepEqual( assert.deepEqual(
await client.zInterWithScores('key'), ZINTER_WITHSCORES.transformArguments(['1', '2']),
[] ['ZINTER', '2', '1', '2', 'WITHSCORES']
); );
}, GLOBAL.SERVERS.OPEN); });
it('key & weight', () => {
assert.deepEqual(
ZINTER_WITHSCORES.transformArguments({
key: 'key',
weight: 1
}),
['ZINTER', '1', 'key', 'WEIGHTS', '1', 'WITHSCORES']
);
});
it('keys & weights', () => {
assert.deepEqual(
ZINTER_WITHSCORES.transformArguments([{
key: 'a',
weight: 1
}, {
key: 'b',
weight: 2
}]),
['ZINTER', '2', 'a', 'b', 'WEIGHTS', '1', '2', 'WITHSCORES']
);
});
it('with AGGREGATE', () => {
assert.deepEqual(
ZINTER_WITHSCORES.transformArguments('key', {
AGGREGATE: 'SUM'
}),
['ZINTER', '1', 'key', 'AGGREGATE', 'SUM', 'WITHSCORES']
);
});
});
testUtils.testAll('zInterWithScores', async client => {
assert.deepEqual(
await client.zInterWithScores('key'),
[]
);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
}); });

View File

@@ -1,19 +1,22 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './ZLEXCOUNT'; import ZLEXCOUNT from './ZLEXCOUNT';
describe('ZLEXCOUNT', () => { describe('ZLEXCOUNT', () => {
it('transformArguments', () => { it('transformArguments', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key', '[a', '[b'), ZLEXCOUNT.transformArguments('key', '[a', '[b'),
['ZLEXCOUNT', 'key', '[a', '[b'] ['ZLEXCOUNT', 'key', '[a', '[b']
); );
}); });
testUtils.testWithClient('client.zLexCount', async client => { testUtils.testAll('zLexCount', async client => {
assert.equal( assert.equal(
await client.zLexCount('key', '[a', '[b'), await client.zLexCount('key', '[a', '[b'),
0 0
); );
}, GLOBAL.SERVERS.OPEN); }, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
}); });

View File

@@ -1,32 +1,32 @@
import { strict as assert } from 'assert'; // import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; // import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './ZMPOP'; // import { transformArguments } from './ZMPOP';
describe('ZMPOP', () => { // describe('ZMPOP', () => {
testUtils.isVersionGreaterThanHook([7]); // testUtils.isVersionGreaterThanHook([7]);
describe('transformArguments', () => { // describe('transformArguments', () => {
it('simple', () => { // it('simple', () => {
assert.deepEqual( // assert.deepEqual(
transformArguments('key', 'MIN'), // transformArguments('key', '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', 'MIN', { // transformArguments('key', 'MIN', {
COUNT: 2 // COUNT: 2
}), // }),
['ZMPOP', '1', 'key', 'MIN', 'COUNT', '2'] // ['ZMPOP', '1', 'key', 'MIN', 'COUNT', '2']
); // );
}); // });
}); // });
testUtils.testWithClient('client.zmPop', async client => { // testUtils.testWithClient('client.zmPop', async client => {
assert.deepEqual( // assert.deepEqual(
await client.zmPop('key', 'MIN'), // await client.zmPop('key', 'MIN'),
null // null
); // );
}, GLOBAL.SERVERS.OPEN); // }, GLOBAL.SERVERS.OPEN);
}); // });

View File

@@ -1,30 +1,33 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './ZMSCORE'; import ZMSCORE from './ZMSCORE';
describe('ZMSCORE', () => { describe('ZMSCORE', () => {
testUtils.isVersionGreaterThanHook([6, 2]); testUtils.isVersionGreaterThanHook([6, 2]);
describe('transformArguments', () => { describe('transformArguments', () => {
it('string', () => { it('string', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key', 'member'), ZMSCORE.transformArguments('key', 'member'),
['ZMSCORE', 'key', 'member'] ['ZMSCORE', 'key', 'member']
); );
});
it('array', () => {
assert.deepEqual(
transformArguments('key', ['1', '2']),
['ZMSCORE', 'key', '1', '2']
);
});
}); });
testUtils.testWithClient('client.zmScore', async client => { it('array', () => {
assert.deepEqual( assert.deepEqual(
await client.zmScore('key', 'member'), ZMSCORE.transformArguments('key', ['1', '2']),
[null] ['ZMSCORE', 'key', '1', '2']
); );
}, GLOBAL.SERVERS.OPEN); });
});
testUtils.testAll('zmScore', async client => {
assert.deepEqual(
await client.zmScore('key', 'member'),
[null]
);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
}); });

View File

@@ -1,5 +1,5 @@
import { RedisArgument, ArrayReply, NullReply, BlobStringReply, DoubleReply, Command } from '../RESP/types'; import { RedisArgument, ArrayReply, NullReply, BlobStringReply, DoubleReply, Command } from '../RESP/types';
import { pushVariadicArgument, RedisVariadicArgument } from './generic-transformers'; import { pushVariadicArguments, RedisVariadicArgument } from './generic-transformers';
export default { export default {
FIRST_KEY_INDEX: 1, FIRST_KEY_INDEX: 1,
@@ -8,7 +8,7 @@ export default {
key: RedisArgument, key: RedisArgument,
member: RedisVariadicArgument member: RedisVariadicArgument
) { ) {
return pushVariadicArgument(['ZMSCORE', key], member); return pushVariadicArguments(['ZMSCORE', key], member);
}, },
transformReply: { transformReply: {
2: (reply: ArrayReply<NullReply | BlobStringReply>) => { 2: (reply: ArrayReply<NullReply | BlobStringReply>) => {

View File

@@ -1,41 +1,41 @@
import { strict as assert } from 'assert'; // import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; // import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments, transformReply } from './ZPOPMAX'; // import { transformArguments, transformReply } from './ZPOPMAX';
describe('ZPOPMAX', () => { // describe('ZPOPMAX', () => {
it('transformArguments', () => { // it('transformArguments', () => {
assert.deepEqual( // assert.deepEqual(
transformArguments('key'), // transformArguments('key'),
['ZPOPMAX', 'key'] // ['ZPOPMAX', 'key']
); // );
}); // });
it('transformReply', () => { // it('transformReply', () => {
assert.deepEqual( // assert.deepEqual(
transformReply(['value', '1']), // transformReply(['value', '1']),
{ // {
value: 'value', // value: 'value',
score: 1 // score: 1
} // }
); // );
}); // });
describe('client.zPopMax', () => { // describe('client.zPopMax', () => {
testUtils.testWithClient('null', async client => { // testUtils.testWithClient('null', async client => {
assert.equal( // assert.equal(
await client.zPopMax('key'), // await client.zPopMax('key'),
null // null
); // );
}, GLOBAL.SERVERS.OPEN); // }, GLOBAL.SERVERS.OPEN);
testUtils.testWithClient('member', async client => { // testUtils.testWithClient('member', async client => {
const member = { score: 1, value: 'value' }, // const member = { score: 1, value: 'value' },
[, zPopMaxReply] = await Promise.all([ // [, zPopMaxReply] = await Promise.all([
client.zAdd('key', member), // client.zAdd('key', member),
client.zPopMax('key') // client.zPopMax('key')
]); // ]);
assert.deepEqual(zPopMaxReply, member); // assert.deepEqual(zPopMaxReply, member);
}, GLOBAL.SERVERS.OPEN); // }, GLOBAL.SERVERS.OPEN);
}); // });
}); // });

View File

@@ -1,19 +1,19 @@
import { strict as assert } from 'assert'; // import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; // import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './ZPOPMAX_COUNT'; // import { transformArguments } from './ZPOPMAX_COUNT';
describe('ZPOPMAX COUNT', () => { // describe('ZPOPMAX COUNT', () => {
it('transformArguments', () => { // it('transformArguments', () => {
assert.deepEqual( // assert.deepEqual(
transformArguments('key', 1), // transformArguments('key', 1),
['ZPOPMAX', 'key', '1'] // ['ZPOPMAX', 'key', '1']
); // );
}); // });
testUtils.testWithClient('client.zPopMaxCount', async client => { // testUtils.testWithClient('client.zPopMaxCount', async client => {
assert.deepEqual( // assert.deepEqual(
await client.zPopMaxCount('key', 1), // await client.zPopMaxCount('key', 1),
[] // []
); // );
}, GLOBAL.SERVERS.OPEN); // }, GLOBAL.SERVERS.OPEN);
}); // });

View File

@@ -1,41 +1,41 @@
import { strict as assert } from 'assert'; // import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; // import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments, transformReply } from './ZPOPMIN'; // import { transformArguments, transformReply } from './ZPOPMIN';
describe('ZPOPMIN', () => { // describe('ZPOPMIN', () => {
it('transformArguments', () => { // it('transformArguments', () => {
assert.deepEqual( // assert.deepEqual(
transformArguments('key'), // transformArguments('key'),
['ZPOPMIN', 'key'] // ['ZPOPMIN', 'key']
); // );
}); // });
it('transformReply', () => { // it('transformReply', () => {
assert.deepEqual( // assert.deepEqual(
transformReply(['value', '1']), // transformReply(['value', '1']),
{ // {
value: 'value', // value: 'value',
score: 1 // score: 1
} // }
); // );
}); // });
describe('client.zPopMin', () => { // describe('client.zPopMin', () => {
testUtils.testWithClient('null', async client => { // testUtils.testWithClient('null', async client => {
assert.equal( // assert.equal(
await client.zPopMin('key'), // await client.zPopMin('key'),
null // null
); // );
}, GLOBAL.SERVERS.OPEN); // }, GLOBAL.SERVERS.OPEN);
testUtils.testWithClient('member', async client => { // testUtils.testWithClient('member', async client => {
const member = { score: 1, value: 'value' }, // const member = { score: 1, value: 'value' },
[, zPopMinReply] = await Promise.all([ // [, zPopMinReply] = await Promise.all([
client.zAdd('key', member), // client.zAdd('key', member),
client.zPopMin('key') // client.zPopMin('key')
]); // ]);
assert.deepEqual(zPopMinReply, member); // assert.deepEqual(zPopMinReply, member);
}, GLOBAL.SERVERS.OPEN); // }, GLOBAL.SERVERS.OPEN);
}); // });
}); // });

View File

@@ -1,19 +1,19 @@
import { strict as assert } from 'assert'; // import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; // import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './ZPOPMIN_COUNT'; // import { transformArguments } from './ZPOPMIN_COUNT';
describe('ZPOPMIN COUNT', () => { // describe('ZPOPMIN COUNT', () => {
it('transformArguments', () => { // it('transformArguments', () => {
assert.deepEqual( // assert.deepEqual(
transformArguments('key', 1), // transformArguments('key', 1),
['ZPOPMIN', 'key', '1'] // ['ZPOPMIN', 'key', '1']
); // );
}); // });
testUtils.testWithClient('client.zPopMinCount', async client => { // testUtils.testWithClient('client.zPopMinCount', async client => {
assert.deepEqual( // assert.deepEqual(
await client.zPopMinCount('key', 1), // await client.zPopMinCount('key', 1),
[] // []
); // );
}, GLOBAL.SERVERS.OPEN); // }, GLOBAL.SERVERS.OPEN);
}); // });

View File

@@ -1,21 +1,24 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './ZRANDMEMBER'; import ZRANDMEMBER from './ZRANDMEMBER';
describe('ZRANDMEMBER', () => { describe('ZRANDMEMBER', () => {
testUtils.isVersionGreaterThanHook([6, 2]); testUtils.isVersionGreaterThanHook([6, 2]);
it('transformArguments', () => { it('transformArguments', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key'), ZRANDMEMBER.transformArguments('key'),
['ZRANDMEMBER', 'key'] ['ZRANDMEMBER', 'key']
); );
}); });
testUtils.testWithClient('client.zRandMember', async client => { testUtils.testAll('zRandMember', async client => {
assert.equal( assert.equal(
await client.zRandMember('key'), await client.zRandMember('key'),
null null
); );
}, GLOBAL.SERVERS.OPEN); }, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
}); });

View File

@@ -1,21 +1,24 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './ZRANDMEMBER_COUNT'; import ZRANDMEMBER_COUNT from './ZRANDMEMBER_COUNT';
describe('ZRANDMEMBER COUNT', () => { describe('ZRANDMEMBER COUNT', () => {
testUtils.isVersionGreaterThanHook([6, 2, 5]); testUtils.isVersionGreaterThanHook([6, 2, 5]);
it('transformArguments', () => { it('transformArguments', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key', 1), ZRANDMEMBER_COUNT.transformArguments('key', 1),
['ZRANDMEMBER', 'key', '1'] ['ZRANDMEMBER', 'key', '1']
); );
}); });
testUtils.testWithClient('client.zRandMemberCount', async client => { testUtils.testAll('zRandMemberCount', async client => {
assert.deepEqual( assert.deepEqual(
await client.zRandMemberCount('key', 1), await client.zRandMemberCount('key', 1),
[] []
); );
}, GLOBAL.SERVERS.OPEN); }, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
}); });

View File

@@ -1,21 +1,24 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './ZRANDMEMBER_COUNT_WITHSCORES'; import ZRANDMEMBER_COUNT_WITHSCORES from './ZRANDMEMBER_COUNT_WITHSCORES';
describe('ZRANDMEMBER COUNT WITHSCORES', () => { describe('ZRANDMEMBER COUNT WITHSCORES', () => {
testUtils.isVersionGreaterThanHook([6, 2, 5]); testUtils.isVersionGreaterThanHook([6, 2, 5]);
it('transformArguments', () => { it('transformArguments', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key', 1), ZRANDMEMBER_COUNT_WITHSCORES.transformArguments('key', 1),
['ZRANDMEMBER', 'key', '1', 'WITHSCORES'] ['ZRANDMEMBER', 'key', '1', 'WITHSCORES']
); );
}); });
testUtils.testWithClient('client.zRandMemberCountWithScores', async client => { testUtils.testAll('zRandMemberCountWithScores', async client => {
assert.deepEqual( assert.deepEqual(
await client.zRandMemberCountWithScores('key', 1), await client.zRandMemberCountWithScores('key', 1),
[] []
); );
}, GLOBAL.SERVERS.OPEN); }, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
}); });

View File

@@ -1,74 +1,77 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './ZRANGE'; import ZRANGE from './ZRANGE';
describe('ZRANGE', () => { describe('ZRANGE', () => {
describe('transformArguments', () => { describe('transformArguments', () => {
it('simple', () => { it('simple', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('src', 0, 1), ZRANGE.transformArguments('src', 0, 1),
['ZRANGE', 'src', '0', '1'] ['ZRANGE', 'src', '0', '1']
); );
});
it('with BYSCORE', () => {
assert.deepEqual(
transformArguments('src', 0, 1, {
BY: 'SCORE'
}),
['ZRANGE', 'src', '0', '1', 'BYSCORE']
);
});
it('with BYLEX', () => {
assert.deepEqual(
transformArguments('src', 0, 1, {
BY: 'LEX'
}),
['ZRANGE', 'src', '0', '1', 'BYLEX']
);
});
it('with REV', () => {
assert.deepEqual(
transformArguments('src', 0, 1, {
REV: true
}),
['ZRANGE', 'src', '0', '1', 'REV']
);
});
it('with LIMIT', () => {
assert.deepEqual(
transformArguments('src', 0, 1, {
LIMIT: {
offset: 0,
count: 1
}
}),
['ZRANGE', 'src', '0', '1', 'LIMIT', '0', '1']
);
});
it('with BY & REV & LIMIT', () => {
assert.deepEqual(
transformArguments('src', 0, 1, {
BY: 'SCORE',
REV: true,
LIMIT: {
offset: 0,
count: 1
}
}),
['ZRANGE', 'src', '0', '1', 'BYSCORE', 'REV', 'LIMIT', '0', '1']
);
});
}); });
testUtils.testWithClient('client.zRange', async client => { it('with BYSCORE', () => {
assert.deepEqual( assert.deepEqual(
await client.zRange('src', 0, 1), ZRANGE.transformArguments('src', 0, 1, {
[] BY: 'SCORE'
); }),
}, GLOBAL.SERVERS.OPEN); ['ZRANGE', 'src', '0', '1', 'BYSCORE']
);
});
it('with BYLEX', () => {
assert.deepEqual(
ZRANGE.transformArguments('src', 0, 1, {
BY: 'LEX'
}),
['ZRANGE', 'src', '0', '1', 'BYLEX']
);
});
it('with REV', () => {
assert.deepEqual(
ZRANGE.transformArguments('src', 0, 1, {
REV: true
}),
['ZRANGE', 'src', '0', '1', 'REV']
);
});
it('with LIMIT', () => {
assert.deepEqual(
ZRANGE.transformArguments('src', 0, 1, {
LIMIT: {
offset: 0,
count: 1
}
}),
['ZRANGE', 'src', '0', '1', 'LIMIT', '0', '1']
);
});
it('with BY & REV & LIMIT', () => {
assert.deepEqual(
ZRANGE.transformArguments('src', 0, 1, {
BY: 'SCORE',
REV: true,
LIMIT: {
offset: 0,
count: 1
}
}),
['ZRANGE', 'src', '0', '1', 'BYSCORE', 'REV', 'LIMIT', '0', '1']
);
});
});
testUtils.testAll('zRange', async client => {
assert.deepEqual(
await client.zRange('src', 0, 1),
[]
);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
}); });

View File

@@ -1,7 +1,7 @@
import { RedisArgument, ArrayReply, BlobStringReply, Command } from '../RESP/types'; import { RedisArgument, ArrayReply, BlobStringReply, Command } from '../RESP/types';
import { transformStringDoubleArgument } from './generic-transformers'; import { transformStringDoubleArgument } from './generic-transformers';
interface ZRangeOptions { export interface ZRangeOptions {
BY?: 'SCORE' | 'LEX'; BY?: 'SCORE' | 'LEX';
REV?: boolean; REV?: boolean;
LIMIT?: { LIMIT?: {

View File

@@ -1,33 +1,33 @@
import { strict as assert } from 'assert'; // import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; // import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './ZRANGEBYLEX'; // import { transformArguments } from './ZRANGEBYLEX';
describe('ZRANGEBYLEX', () => { // describe('ZRANGEBYLEX', () => {
describe('transformArguments', () => { // describe('transformArguments', () => {
it('simple', () => { // it('simple', () => {
assert.deepEqual( // assert.deepEqual(
transformArguments('src', '-', '+'), // transformArguments('src', '-', '+'),
['ZRANGEBYLEX', 'src', '-', '+'] // ['ZRANGEBYLEX', 'src', '-', '+']
); // );
}); // });
it('with LIMIT', () => { // it('with LIMIT', () => {
assert.deepEqual( // assert.deepEqual(
transformArguments('src', '-', '+', { // transformArguments('src', '-', '+', {
LIMIT: { // LIMIT: {
offset: 0, // offset: 0,
count: 1 // count: 1
} // }
}), // }),
['ZRANGEBYLEX', 'src', '-', '+', 'LIMIT', '0', '1'] // ['ZRANGEBYLEX', 'src', '-', '+', 'LIMIT', '0', '1']
); // );
}); // });
}); // });
testUtils.testWithClient('client.zRangeByLex', async client => { // testUtils.testWithClient('client.zRangeByLex', async client => {
assert.deepEqual( // assert.deepEqual(
await client.zRangeByLex('src', '-', '+'), // await client.zRangeByLex('src', '-', '+'),
[] // []
); // );
}, GLOBAL.SERVERS.OPEN); // }, GLOBAL.SERVERS.OPEN);
}); // });

View File

@@ -1,33 +1,33 @@
import { strict as assert } from 'assert'; // import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; // import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './ZRANGEBYSCORE'; // import { transformArguments } from './ZRANGEBYSCORE';
describe('ZRANGEBYSCORE', () => { // describe('ZRANGEBYSCORE', () => {
describe('transformArguments', () => { // describe('transformArguments', () => {
it('simple', () => { // it('simple', () => {
assert.deepEqual( // assert.deepEqual(
transformArguments('src', 0, 1), // transformArguments('src', 0, 1),
['ZRANGEBYSCORE', 'src', '0', '1'] // ['ZRANGEBYSCORE', 'src', '0', '1']
); // );
}); // });
it('with LIMIT', () => { // it('with LIMIT', () => {
assert.deepEqual( // assert.deepEqual(
transformArguments('src', 0, 1, { // transformArguments('src', 0, 1, {
LIMIT: { // LIMIT: {
offset: 0, // offset: 0,
count: 1 // count: 1
} // }
}), // }),
['ZRANGEBYSCORE', 'src', '0', '1', 'LIMIT', '0', '1'] // ['ZRANGEBYSCORE', 'src', '0', '1', 'LIMIT', '0', '1']
); // );
}); // });
}); // });
testUtils.testWithClient('client.zRangeByScore', async client => { // testUtils.testWithClient('client.zRangeByScore', async client => {
assert.deepEqual( // assert.deepEqual(
await client.zRangeByScore('src', 0, 1), // await client.zRangeByScore('src', 0, 1),
[] // []
); // );
}, GLOBAL.SERVERS.OPEN); // }, GLOBAL.SERVERS.OPEN);
}); // });

View File

@@ -1,33 +1,33 @@
import { strict as assert } from 'assert'; // import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; // import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './ZRANGEBYSCORE_WITHSCORES'; // import { transformArguments } from './ZRANGEBYSCORE_WITHSCORES';
describe('ZRANGEBYSCORE WITHSCORES', () => { // describe('ZRANGEBYSCORE WITHSCORES', () => {
describe('transformArguments', () => { // describe('transformArguments', () => {
it('simple', () => { // it('simple', () => {
assert.deepEqual( // assert.deepEqual(
transformArguments('src', 0, 1), // transformArguments('src', 0, 1),
['ZRANGEBYSCORE', 'src', '0', '1', 'WITHSCORES'] // ['ZRANGEBYSCORE', 'src', '0', '1', 'WITHSCORES']
); // );
}); // });
it('with LIMIT', () => { // it('with LIMIT', () => {
assert.deepEqual( // assert.deepEqual(
transformArguments('src', 0, 1, { // transformArguments('src', 0, 1, {
LIMIT: { // LIMIT: {
offset: 0, // offset: 0,
count: 1 // count: 1
} // }
}), // }),
['ZRANGEBYSCORE', 'src', '0', '1', 'LIMIT', '0', '1', 'WITHSCORES'] // ['ZRANGEBYSCORE', 'src', '0', '1', 'LIMIT', '0', '1', 'WITHSCORES']
); // );
}); // });
}); // });
testUtils.testWithClient('client.zRangeByScoreWithScores', async client => { // testUtils.testWithClient('client.zRangeByScoreWithScores', async client => {
assert.deepEqual( // assert.deepEqual(
await client.zRangeByScoreWithScores('src', 0, 1), // await client.zRangeByScoreWithScores('src', 0, 1),
[] // []
); // );
}, GLOBAL.SERVERS.OPEN); // }, GLOBAL.SERVERS.OPEN);
}); // });

View File

@@ -1,92 +1,92 @@
import { strict as assert } from 'assert'; // import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; // import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments, transformReply } from './ZRANGESTORE'; // import { transformArguments, transformReply } from './ZRANGESTORE';
describe('ZRANGESTORE', () => { // describe('ZRANGESTORE', () => {
testUtils.isVersionGreaterThanHook([6, 2]); // testUtils.isVersionGreaterThanHook([6, 2]);
describe('transformArguments', () => { // describe('transformArguments', () => {
it('simple', () => { // it('simple', () => {
assert.deepEqual( // assert.deepEqual(
transformArguments('dst', 'src', 0, 1), // transformArguments('dst', 'src', 0, 1),
['ZRANGESTORE', 'dst', 'src', '0', '1'] // ['ZRANGESTORE', 'dst', 'src', '0', '1']
); // );
}); // });
it('with BYSCORE', () => { // it('with BYSCORE', () => {
assert.deepEqual( // assert.deepEqual(
transformArguments('dst', 'src', 0, 1, { // transformArguments('dst', 'src', 0, 1, {
BY: 'SCORE' // BY: 'SCORE'
}), // }),
['ZRANGESTORE', 'dst', 'src', '0', '1', 'BYSCORE'] // ['ZRANGESTORE', 'dst', 'src', '0', '1', 'BYSCORE']
); // );
}); // });
it('with BYLEX', () => { // it('with BYLEX', () => {
assert.deepEqual( // assert.deepEqual(
transformArguments('dst', 'src', 0, 1, { // transformArguments('dst', 'src', 0, 1, {
BY: 'LEX' // BY: 'LEX'
}), // }),
['ZRANGESTORE', 'dst', 'src', '0', '1', 'BYLEX'] // ['ZRANGESTORE', 'dst', 'src', '0', '1', 'BYLEX']
); // );
}); // });
it('with REV', () => { // it('with REV', () => {
assert.deepEqual( // assert.deepEqual(
transformArguments('dst', 'src', 0, 1, { // transformArguments('dst', 'src', 0, 1, {
REV: true // REV: true
}), // }),
['ZRANGESTORE', 'dst', 'src', '0', '1', 'REV'] // ['ZRANGESTORE', 'dst', 'src', '0', '1', 'REV']
); // );
}); // });
it('with LIMIT', () => { // it('with LIMIT', () => {
assert.deepEqual( // assert.deepEqual(
transformArguments('dst', 'src', 0, 1, { // transformArguments('dst', 'src', 0, 1, {
LIMIT: { // LIMIT: {
offset: 0, // offset: 0,
count: 1 // count: 1
} // }
}), // }),
['ZRANGESTORE', 'dst', 'src', '0', '1', 'LIMIT', '0', '1'] // ['ZRANGESTORE', 'dst', 'src', '0', '1', 'LIMIT', '0', '1']
); // );
}); // });
it('with BY & REV & LIMIT', () => { // it('with BY & REV & LIMIT', () => {
assert.deepEqual( // assert.deepEqual(
transformArguments('dst', 'src', 0, 1, { // transformArguments('dst', 'src', 0, 1, {
BY: 'SCORE', // BY: 'SCORE',
REV: true, // REV: true,
LIMIT: { // LIMIT: {
offset: 0, // offset: 0,
count: 1 // count: 1
}, // },
WITHSCORES: true // WITHSCORES: true
}), // }),
['ZRANGESTORE', 'dst', 'src', '0', '1', 'BYSCORE', 'REV', 'LIMIT', '0', '1', 'WITHSCORES'] // ['ZRANGESTORE', 'dst', 'src', '0', '1', 'BYSCORE', 'REV', 'LIMIT', '0', '1', 'WITHSCORES']
); // );
}); // });
}); // });
describe('transformReply', () => { // describe('transformReply', () => {
it('should throw TypeError when reply is not a number', () => { // it('should throw TypeError when reply is not a number', () => {
assert.throws( // assert.throws(
// eslint-disable-next-line @typescript-eslint/no-explicit-any // // eslint-disable-next-line @typescript-eslint/no-explicit-any
() => (transformReply as any)([]), // () => (transformReply as any)([]),
TypeError // TypeError
); // );
}); // });
}); // });
testUtils.testWithClient('client.zRangeStore', async client => { // testUtils.testWithClient('client.zRangeStore', async client => {
await client.zAdd('src', { // await client.zAdd('src', {
score: 0.5, // score: 0.5,
value: 'value' // value: 'value'
}); // });
assert.equal( // assert.equal(
await client.zRangeStore('dst', 'src', 0, 1), // await client.zRangeStore('dst', 'src', 0, 1),
1 // 1
); // );
}, GLOBAL.SERVERS.OPEN); // }, GLOBAL.SERVERS.OPEN);
}); // });

View File

@@ -1,65 +1,65 @@
import { strict as assert } from 'assert'; // import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; // import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './ZRANGE_WITHSCORES'; // import { transformArguments } from './ZRANGE_WITHSCORES';
describe('ZRANGE WITHSCORES', () => { // describe('ZRANGE WITHSCORES', () => {
describe('transformArguments', () => { // describe('transformArguments', () => {
it('simple', () => { // it('simple', () => {
assert.deepEqual( // assert.deepEqual(
transformArguments('src', 0, 1), // transformArguments('src', 0, 1),
['ZRANGE', 'src', '0', '1', 'WITHSCORES'] // ['ZRANGE', 'src', '0', '1', 'WITHSCORES']
); // );
}); // });
it('with BY', () => { // it('with BY', () => {
assert.deepEqual( // assert.deepEqual(
transformArguments('src', 0, 1, { // transformArguments('src', 0, 1, {
BY: 'SCORE' // BY: 'SCORE'
}), // }),
['ZRANGE', 'src', '0', '1', 'BYSCORE', 'WITHSCORES'] // ['ZRANGE', 'src', '0', '1', 'BYSCORE', 'WITHSCORES']
); // );
}); // });
it('with REV', () => { // it('with REV', () => {
assert.deepEqual( // assert.deepEqual(
transformArguments('src', 0, 1, { // transformArguments('src', 0, 1, {
REV: true // REV: true
}), // }),
['ZRANGE', 'src', '0', '1', 'REV', 'WITHSCORES'] // ['ZRANGE', 'src', '0', '1', 'REV', 'WITHSCORES']
); // );
}); // });
it('with LIMIT', () => { // it('with LIMIT', () => {
assert.deepEqual( // assert.deepEqual(
transformArguments('src', 0, 1, { // transformArguments('src', 0, 1, {
LIMIT: { // LIMIT: {
offset: 0, // offset: 0,
count: 1 // count: 1
} // }
}), // }),
['ZRANGE', 'src', '0', '1', 'LIMIT', '0', '1', 'WITHSCORES'] // ['ZRANGE', 'src', '0', '1', 'LIMIT', '0', '1', 'WITHSCORES']
); // );
}); // });
it('with BY & REV & LIMIT', () => { // it('with BY & REV & LIMIT', () => {
assert.deepEqual( // assert.deepEqual(
transformArguments('src', 0, 1, { // transformArguments('src', 0, 1, {
BY: 'SCORE', // BY: 'SCORE',
REV: true, // REV: true,
LIMIT: { // LIMIT: {
offset: 0, // offset: 0,
count: 1 // count: 1
} // }
}), // }),
['ZRANGE', 'src', '0', '1', 'BYSCORE', 'REV', 'LIMIT', '0', '1', 'WITHSCORES'] // ['ZRANGE', 'src', '0', '1', 'BYSCORE', 'REV', 'LIMIT', '0', '1', 'WITHSCORES']
); // );
}); // });
}); // });
testUtils.testWithClient('client.zRangeWithScores', async client => { // testUtils.testWithClient('client.zRangeWithScores', async client => {
assert.deepEqual( // assert.deepEqual(
await client.zRangeWithScores('src', 0, 1), // await client.zRangeWithScores('src', 0, 1),
[] // []
); // );
}, GLOBAL.SERVERS.OPEN); // }, GLOBAL.SERVERS.OPEN);
}); // });

View File

@@ -1,19 +1,22 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './ZRANK'; import ZRANK from './ZRANK';
describe('ZRANK', () => { describe('ZRANK', () => {
it('transformArguments', () => { it('transformArguments', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key', 'member'), ZRANK.transformArguments('key', 'member'),
['ZRANK', 'key', 'member'] ['ZRANK', 'key', 'member']
); );
}); });
testUtils.testWithClient('client.zRank', async client => { testUtils.testAll('zRank', async client => {
assert.equal( assert.equal(
await client.zRank('key', 'member'), await client.zRank('key', 'member'),
null null
); );
}, GLOBAL.SERVERS.OPEN); }, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
}); });

View File

@@ -1,28 +1,31 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './ZREM'; import ZREM from './ZREM';
describe('ZREM', () => { describe('ZREM', () => {
describe('transformArguments', () => { describe('transformArguments', () => {
it('string', () => { it('string', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key', 'member'), ZREM.transformArguments('key', 'member'),
['ZREM', 'key', 'member'] ['ZREM', 'key', 'member']
); );
});
it('array', () => {
assert.deepEqual(
transformArguments('key', ['1', '2']),
['ZREM', 'key', '1', '2']
);
});
}); });
testUtils.testWithClient('client.zRem', async client => { it('array', () => {
assert.equal( assert.deepEqual(
await client.zRem('key', 'member'), ZREM.transformArguments('key', ['1', '2']),
0 ['ZREM', 'key', '1', '2']
); );
}, GLOBAL.SERVERS.OPEN); });
});
testUtils.testAll('zRem', async client => {
assert.equal(
await client.zRem('key', 'member'),
0
);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
}); });

View File

@@ -1,19 +1,19 @@
import { strict as assert } from 'assert'; // import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; // import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './ZREMRANGEBYLEX'; // import { transformArguments } from './ZREMRANGEBYLEX';
describe('ZREMRANGEBYLEX', () => { // describe('ZREMRANGEBYLEX', () => {
it('transformArguments', () => { // it('transformArguments', () => {
assert.deepEqual( // assert.deepEqual(
transformArguments('key', '[a', '[b'), // transformArguments('key', '[a', '[b'),
['ZREMRANGEBYLEX', 'key', '[a', '[b'] // ['ZREMRANGEBYLEX', 'key', '[a', '[b']
); // );
}); // });
testUtils.testWithClient('client.zRemRangeByLex', async client => { // testUtils.testWithClient('client.zRemRangeByLex', async client => {
assert.equal( // assert.equal(
await client.zRemRangeByLex('key', '[a', '[b'), // await client.zRemRangeByLex('key', '[a', '[b'),
0 // 0
); // );
}, GLOBAL.SERVERS.OPEN); // }, GLOBAL.SERVERS.OPEN);
}); // });

View File

@@ -1,19 +1,19 @@
import { strict as assert } from 'assert'; // import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; // import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './ZREMRANGEBYRANK'; // import { transformArguments } from './ZREMRANGEBYRANK';
describe('ZREMRANGEBYRANK', () => { // describe('ZREMRANGEBYRANK', () => {
it('transformArguments', () => { // it('transformArguments', () => {
assert.deepEqual( // assert.deepEqual(
transformArguments('key', 0, 1), // transformArguments('key', 0, 1),
['ZREMRANGEBYRANK', 'key', '0', '1'] // ['ZREMRANGEBYRANK', 'key', '0', '1']
); // );
}); // });
testUtils.testWithClient('client.zRemRangeByRank', async client => { // testUtils.testWithClient('client.zRemRangeByRank', async client => {
assert.equal( // assert.equal(
await client.zRemRangeByRank('key', 0, 1), // await client.zRemRangeByRank('key', 0, 1),
0 // 0
); // );
}, GLOBAL.SERVERS.OPEN); // }, GLOBAL.SERVERS.OPEN);
}); // });

View File

@@ -1,19 +1,19 @@
import { strict as assert } from 'assert'; // import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; // import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './ZREMRANGEBYSCORE'; // import { transformArguments } from './ZREMRANGEBYSCORE';
describe('ZREMRANGEBYSCORE', () => { // describe('ZREMRANGEBYSCORE', () => {
it('transformArguments', () => { // it('transformArguments', () => {
assert.deepEqual( // assert.deepEqual(
transformArguments('key', 0, 1), // transformArguments('key', 0, 1),
['ZREMRANGEBYSCORE', 'key', '0', '1'] // ['ZREMRANGEBYSCORE', 'key', '0', '1']
); // );
}); // });
testUtils.testWithClient('client.zRemRangeByScore', async client => { // testUtils.testWithClient('client.zRemRangeByScore', async client => {
assert.equal( // assert.equal(
await client.zRemRangeByScore('key', 0, 1), // await client.zRemRangeByScore('key', 0, 1),
0 // 0
); // );
}, GLOBAL.SERVERS.OPEN); // }, GLOBAL.SERVERS.OPEN);
}); // });

View File

@@ -1,19 +1,22 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './ZREVRANK'; import ZREVRANK from './ZREVRANK';
describe('ZREVRANK', () => { describe('ZREVRANK', () => {
it('transformArguments', () => { it('transformArguments', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key', 'member'), ZREVRANK.transformArguments('key', 'member'),
['ZREVRANK', 'key', 'member'] ['ZREVRANK', 'key', 'member']
); );
}); });
testUtils.testWithClient('client.zRevRank', async client => { testUtils.testAll('zRevRank', async client => {
assert.equal( assert.equal(
await client.zRevRank('key', 'member'), await client.zRevRank('key', 'member'),
null null
); );
}, GLOBAL.SERVERS.OPEN); }, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
}); });

View File

@@ -1,77 +1,52 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments, transformReply } from './ZSCAN'; import ZSCAN from './ZSCAN';
describe('ZSCAN', () => { describe('ZSCAN', () => {
describe('transformArguments', () => { describe('transformArguments', () => {
it('cusror only', () => { it('cusror only', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key', 0), ZSCAN.transformArguments('key', 0),
['ZSCAN', 'key', '0'] ['ZSCAN', 'key', '0']
); );
});
it('with MATCH', () => {
assert.deepEqual(
transformArguments('key', 0, {
MATCH: 'pattern'
}),
['ZSCAN', 'key', '0', 'MATCH', 'pattern']
);
});
it('with COUNT', () => {
assert.deepEqual(
transformArguments('key', 0, {
COUNT: 1
}),
['ZSCAN', 'key', '0', 'COUNT', '1']
);
});
it('with MATCH & COUNT', () => {
assert.deepEqual(
transformArguments('key', 0, {
MATCH: 'pattern',
COUNT: 1
}),
['ZSCAN', 'key', '0', 'MATCH', 'pattern', 'COUNT', '1']
);
});
}); });
describe('transformReply', () => { it('with MATCH', () => {
it('without members', () => { assert.deepEqual(
assert.deepEqual( ZSCAN.transformArguments('key', 0, {
transformReply(['0', []]), MATCH: 'pattern'
{ }),
cursor: 0, ['ZSCAN', 'key', '0', 'MATCH', 'pattern']
members: [] );
}
);
});
it('with members', () => {
assert.deepEqual(
transformReply(['0', ['member', '-inf']]),
{
cursor: 0,
members: [{
value: 'member',
score: -Infinity
}]
}
);
});
}); });
testUtils.testWithClient('client.zScan', async client => { it('with COUNT', () => {
assert.deepEqual( assert.deepEqual(
await client.zScan('key', 0), ZSCAN.transformArguments('key', 0, {
{ COUNT: 1
cursor: 0, }),
members: [] ['ZSCAN', 'key', '0', 'COUNT', '1']
} );
); });
}, GLOBAL.SERVERS.OPEN);
it('with MATCH & COUNT', () => {
assert.deepEqual(
ZSCAN.transformArguments('key', 0, {
MATCH: 'pattern',
COUNT: 1
}),
['ZSCAN', 'key', '0', 'MATCH', 'pattern', 'COUNT', '1']
);
});
});
testUtils.testWithClient('zScan', async client => {
assert.deepEqual(
await client.zScan('key', 0),
{
cursor: 0,
members: []
}
);
}, GLOBAL.SERVERS.OPEN);
}); });

View File

@@ -1,19 +1,22 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './ZSCORE'; import ZSCORE from './ZSCORE';
describe('ZSCORE', () => { describe('ZSCORE', () => {
it('transformArguments', () => { it('transformArguments', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key', 'member'), ZSCORE.transformArguments('key', 'member'),
['ZSCORE', 'key', 'member'] ['ZSCORE', 'key', 'member']
); );
}); });
testUtils.testWithClient('client.zScore', async client => { testUtils.testAll('zScore', async client => {
assert.equal( assert.equal(
await client.zScore('key', 'member'), await client.zScore('key', 'member'),
null null
); );
}, GLOBAL.SERVERS.OPEN); }, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
}); });

View File

@@ -1,48 +1,48 @@
import { strict as assert } from 'assert'; // import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; // import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './ZUNION'; // import { transformArguments } from './ZUNION';
describe('ZUNION', () => { // describe('ZUNION', () => {
testUtils.isVersionGreaterThanHook([6, 2]); // testUtils.isVersionGreaterThanHook([6, 2]);
describe('transformArguments', () => { // describe('transformArguments', () => {
it('key (string)', () => { // it('key (string)', () => {
assert.deepEqual( // assert.deepEqual(
transformArguments('key'), // transformArguments('key'),
['ZUNION', '1', 'key'] // ['ZUNION', '1', 'key']
); // );
}); // });
it('keys (array)', () => { // it('keys (array)', () => {
assert.deepEqual( // assert.deepEqual(
transformArguments(['1', '2']), // transformArguments(['1', '2']),
['ZUNION', '2', '1', '2'] // ['ZUNION', '2', '1', '2']
); // );
}); // });
it('with WEIGHTS', () => { // it('with WEIGHTS', () => {
assert.deepEqual( // assert.deepEqual(
transformArguments('key', { // transformArguments('key', {
WEIGHTS: [1] // WEIGHTS: [1]
}), // }),
['ZUNION', '1', 'key', 'WEIGHTS', '1'] // ['ZUNION', '1', 'key', 'WEIGHTS', '1']
); // );
}); // });
it('with AGGREGATE', () => { // it('with AGGREGATE', () => {
assert.deepEqual( // assert.deepEqual(
transformArguments('key', { // transformArguments('key', {
AGGREGATE: 'SUM' // AGGREGATE: 'SUM'
}), // }),
['ZUNION', '1', 'key', 'AGGREGATE', 'SUM'] // ['ZUNION', '1', 'key', 'AGGREGATE', 'SUM']
); // );
}); // });
}); // });
testUtils.testWithClient('client.zUnion', async client => { // testUtils.testWithClient('client.zUnion', async client => {
assert.deepEqual( // assert.deepEqual(
await client.zUnion('key'), // await client.zUnion('key'),
[] // []
); // );
}, GLOBAL.SERVERS.OPEN); // }, GLOBAL.SERVERS.OPEN);
}); // });

View File

@@ -1,56 +1,56 @@
import { strict as assert } from 'assert'; // import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; // import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './ZUNIONSTORE'; // import { transformArguments } from './ZUNIONSTORE';
describe('ZUNIONSTORE', () => { // describe('ZUNIONSTORE', () => {
describe('transformArguments', () => { // describe('transformArguments', () => {
it('key (string)', () => { // it('key (string)', () => {
assert.deepEqual( // assert.deepEqual(
transformArguments('destination', 'key'), // transformArguments('destination', 'key'),
['ZUNIONSTORE', 'destination', '1', 'key'] // ['ZUNIONSTORE', 'destination', '1', 'key']
); // );
}); // });
it('keys (array)', () => { // it('keys (array)', () => {
assert.deepEqual( // assert.deepEqual(
transformArguments('destination', ['1', '2']), // transformArguments('destination', ['1', '2']),
['ZUNIONSTORE', 'destination', '2', '1', '2'] // ['ZUNIONSTORE', 'destination', '2', '1', '2']
); // );
}); // });
it('with WEIGHTS', () => { // it('with WEIGHTS', () => {
assert.deepEqual( // assert.deepEqual(
transformArguments('destination', 'key', { // transformArguments('destination', 'key', {
WEIGHTS: [1] // WEIGHTS: [1]
}), // }),
['ZUNIONSTORE', 'destination', '1', 'key', 'WEIGHTS', '1'] // ['ZUNIONSTORE', 'destination', '1', 'key', 'WEIGHTS', '1']
); // );
}); // });
it('with AGGREGATE', () => { // it('with AGGREGATE', () => {
assert.deepEqual( // assert.deepEqual(
transformArguments('destination', 'key', { // transformArguments('destination', 'key', {
AGGREGATE: 'SUM' // AGGREGATE: 'SUM'
}), // }),
['ZUNIONSTORE', 'destination', '1', 'key', 'AGGREGATE', 'SUM'] // ['ZUNIONSTORE', 'destination', '1', 'key', 'AGGREGATE', 'SUM']
); // );
}); // });
it('with WEIGHTS, AGGREGATE', () => { // it('with WEIGHTS, AGGREGATE', () => {
assert.deepEqual( // assert.deepEqual(
transformArguments('destination', 'key', { // transformArguments('destination', 'key', {
WEIGHTS: [1], // WEIGHTS: [1],
AGGREGATE: 'SUM' // AGGREGATE: 'SUM'
}), // }),
['ZUNIONSTORE', 'destination', '1', 'key', 'WEIGHTS', '1', 'AGGREGATE', 'SUM'] // ['ZUNIONSTORE', 'destination', '1', 'key', 'WEIGHTS', '1', 'AGGREGATE', 'SUM']
); // );
}); // });
}); // });
testUtils.testWithClient('client.zUnionStore', async client => { // testUtils.testWithClient('client.zUnionStore', async client => {
assert.equal( // assert.equal(
await client.zUnionStore('destination', 'key'), // await client.zUnionStore('destination', 'key'),
0 // 0
); // );
}, GLOBAL.SERVERS.OPEN); // }, GLOBAL.SERVERS.OPEN);
}); // });

View File

@@ -1,48 +1,48 @@
import { strict as assert } from 'assert'; // import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; // import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './ZUNION_WITHSCORES'; // import { transformArguments } from './ZUNION_WITHSCORES';
describe('ZUNION WITHSCORES', () => { // describe('ZUNION WITHSCORES', () => {
testUtils.isVersionGreaterThanHook([6, 2]); // testUtils.isVersionGreaterThanHook([6, 2]);
describe('transformArguments', () => { // describe('transformArguments', () => {
it('key (string)', () => { // it('key (string)', () => {
assert.deepEqual( // assert.deepEqual(
transformArguments('key'), // transformArguments('key'),
['ZUNION', '1', 'key', 'WITHSCORES'] // ['ZUNION', '1', 'key', 'WITHSCORES']
); // );
}); // });
it('keys (array)', () => { // it('keys (array)', () => {
assert.deepEqual( // assert.deepEqual(
transformArguments(['1', '2']), // transformArguments(['1', '2']),
['ZUNION', '2', '1', '2', 'WITHSCORES'] // ['ZUNION', '2', '1', '2', 'WITHSCORES']
); // );
}); // });
it('with WEIGHTS', () => { // it('with WEIGHTS', () => {
assert.deepEqual( // assert.deepEqual(
transformArguments('key', { // transformArguments('key', {
WEIGHTS: [1] // WEIGHTS: [1]
}), // }),
['ZUNION', '1', 'key', 'WEIGHTS', '1', 'WITHSCORES'] // ['ZUNION', '1', 'key', 'WEIGHTS', '1', 'WITHSCORES']
); // );
}); // });
it('with AGGREGATE', () => { // it('with AGGREGATE', () => {
assert.deepEqual( // assert.deepEqual(
transformArguments('key', { // transformArguments('key', {
AGGREGATE: 'SUM' // AGGREGATE: 'SUM'
}), // }),
['ZUNION', '1', 'key', 'AGGREGATE', 'SUM', 'WITHSCORES'] // ['ZUNION', '1', 'key', 'AGGREGATE', 'SUM', 'WITHSCORES']
); // );
}); // });
}); // });
testUtils.testWithClient('client.zUnionWithScores', async client => { // testUtils.testWithClient('client.zUnionWithScores', async client => {
assert.deepEqual( // assert.deepEqual(
await client.zUnionWithScores('key'), // await client.zUnionWithScores('key'),
[] // []
); // );
}, GLOBAL.SERVERS.OPEN); // }, GLOBAL.SERVERS.OPEN);
}); // });

View File

@@ -106,7 +106,28 @@ import SETRANGE from './SETRANGE';
import SMEMBERS from './SMEMBERS'; import SMEMBERS from './SMEMBERS';
import SSCAN from './SSCAN'; import SSCAN from './SSCAN';
import STRLEN from './STRLEN'; import STRLEN from './STRLEN';
import ZADD from './ZADD';
import ZCARD from './ZCARD';
import ZCOUNT from './ZCOUNT';
import ZDIFF_WITHSCORES from './ZDIFF_WITHSCORES';
import ZDIFF from './ZDIFF';
import ZDIFFSTORE from './ZDIFFSTORE';
import ZINCRBY from './ZINCRBY';
import ZINTER_WITHSCORES from './ZINTER_WITHSCORES';
import ZINTER from './ZINTER';
import ZINTERCARD from './ZINTERCARD';
import ZINTERSTORE from './ZINTERSTORE';
import ZLEXCOUNT from './ZLEXCOUNT';
import ZMSCORE from './ZMSCORE';
import ZRANDMEMBER_COUNT_WITHSCORES from './ZRANDMEMBER_COUNT_WITHSCORES';
import ZRANDMEMBER_COUNT from './ZRANDMEMBER_COUNT';
import ZRANDMEMBER from './ZRANDMEMBER';
import ZRANGE from './ZRANGE';
import ZRANK from './ZRANK';
import ZREM from './ZREM';
import ZREVRANK from './ZREVRANK';
import ZSCAN from './ZSCAN'; import ZSCAN from './ZSCAN';
import ZSCORE from './ZSCORE';
import { Command } from '../RESP/types'; import { Command } from '../RESP/types';
export default { export default {
@@ -326,7 +347,49 @@ export default {
SSCAN, SSCAN,
sScan: SSCAN, sScan: SSCAN,
STRLEN, STRLEN,
strLen: STRLEN, strLen: STRLEN,
ZADD,
zAdd: ZADD,
ZCARD,
zCard: ZCARD,
ZCOUNT,
zCount: ZCOUNT,
ZDIFF_WITHSCORES,
zDiffWithScores: ZDIFF_WITHSCORES,
ZDIFF,
zDiff: ZDIFF,
ZDIFFSTORE,
zDiffStore: ZDIFFSTORE,
ZINCRBY,
zIncrBy: ZINCRBY,
ZINTER_WITHSCORES,
zInterWithScores: ZINTER_WITHSCORES,
ZINTER,
zInter: ZINTER,
ZINTERCARD,
zInterCard: ZINTERCARD,
ZINTERSTORE,
zInterStore: ZINTERSTORE,
ZLEXCOUNT,
zLexCount: ZLEXCOUNT,
ZMSCORE,
zmScore: ZMSCORE,
ZRANDMEMBER_COUNT_WITHSCORES,
zRandMemberCountWithScores: ZRANDMEMBER_COUNT_WITHSCORES,
ZRANDMEMBER_COUNT,
zRandMemberCount: ZRANDMEMBER_COUNT,
ZRANDMEMBER,
zRandMember: ZRANDMEMBER,
ZRANGE,
zRange: ZRANGE,
ZRANK,
zRank: ZRANK,
ZREM,
zRem: ZREM,
ZREVRANK,
zRevRank: ZREVRANK,
ZSCAN, ZSCAN,
zScan: ZSCAN zScan: ZSCAN,
ZSCORE,
zScore: ZSCORE
} as const satisfies Record<string, Command>; } as const satisfies Record<string, Command>;