You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-12-25 00:40:59 +03:00
fix #1665 - add ZRANGEBYLEX, ZRANGEBYSCORE, ZRANGEBYSCORE_WITHSCORES
This commit is contained in:
33
lib/commands/ZRANGEBYLEX.spec.ts
Normal file
33
lib/commands/ZRANGEBYLEX.spec.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import { TestRedisServers, itWithClient } from '../test-utils';
|
||||
import { transformArguments } from './ZRANGEBYLEX';
|
||||
|
||||
describe('ZRANGEBYLEX', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('simple', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('src', '-', '+'),
|
||||
['ZRANGEBYLEX', 'src', '-', '+']
|
||||
);
|
||||
});
|
||||
|
||||
it('with LIMIT', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('src', '-', '+', {
|
||||
LIMIT: {
|
||||
offset: 0,
|
||||
count: 1
|
||||
}
|
||||
}),
|
||||
['ZRANGEBYLEX', 'src', '-', '+', 'LIMIT', '0', '1']
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
itWithClient(TestRedisServers.OPEN, 'client.zRangeByLex', async client => {
|
||||
assert.deepEqual(
|
||||
await client.zRangeByLex('src', '-', '+'),
|
||||
[]
|
||||
);
|
||||
});
|
||||
});
|
||||
35
lib/commands/ZRANGEBYLEX.ts
Normal file
35
lib/commands/ZRANGEBYLEX.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { TransformArgumentsReply } from '.';
|
||||
import { transformArgumentNumberInfinity } from './generic-transformers';
|
||||
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
export const IS_READ_ONLY = true;
|
||||
|
||||
export interface ZRangeByLexOptions {
|
||||
LIMIT?: {
|
||||
offset: number;
|
||||
count: number;
|
||||
};
|
||||
}
|
||||
|
||||
export function transformArguments(
|
||||
key: string,
|
||||
min: number | string,
|
||||
max: number | string,
|
||||
options?: ZRangeByLexOptions
|
||||
): TransformArgumentsReply {
|
||||
const args = [
|
||||
'ZRANGEBYLEX',
|
||||
key,
|
||||
typeof min === 'string' ? min : transformArgumentNumberInfinity(min),
|
||||
typeof max === 'string' ? max : transformArgumentNumberInfinity(max)
|
||||
];
|
||||
|
||||
if (options?.LIMIT) {
|
||||
args.push('LIMIT', options.LIMIT.offset.toString(), options.LIMIT.count.toString());
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
export declare function transformReply(): Array<string>;
|
||||
33
lib/commands/ZRANGEBYSCORE.spec.ts
Normal file
33
lib/commands/ZRANGEBYSCORE.spec.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import { TestRedisServers, itWithClient } from '../test-utils';
|
||||
import { transformArguments } from './ZRANGEBYSCORE';
|
||||
|
||||
describe('ZRANGEBYSCORE', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('simple', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('src', 0, 1),
|
||||
['ZRANGEBYSCORE', 'src', '0', '1']
|
||||
);
|
||||
});
|
||||
|
||||
it('with LIMIT', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('src', 0, 1, {
|
||||
LIMIT: {
|
||||
offset: 0,
|
||||
count: 1
|
||||
}
|
||||
}),
|
||||
['ZRANGEBYSCORE', 'src', '0', '1', 'LIMIT', '0', '1']
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
itWithClient(TestRedisServers.OPEN, 'client.zRangeByScore', async client => {
|
||||
assert.deepEqual(
|
||||
await client.zRangeByScore('src', 0, 1),
|
||||
[]
|
||||
);
|
||||
});
|
||||
});
|
||||
35
lib/commands/ZRANGEBYSCORE.ts
Normal file
35
lib/commands/ZRANGEBYSCORE.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { TransformArgumentsReply } from '.';
|
||||
import { transformArgumentNumberInfinity } from './generic-transformers';
|
||||
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
export const IS_READ_ONLY = true;
|
||||
|
||||
export interface ZRangeByScoreOptions {
|
||||
LIMIT?: {
|
||||
offset: number;
|
||||
count: number;
|
||||
};
|
||||
}
|
||||
|
||||
export function transformArguments(
|
||||
key: string,
|
||||
min: number | string,
|
||||
max: number | string,
|
||||
options?: ZRangeByScoreOptions
|
||||
): TransformArgumentsReply {
|
||||
const args = [
|
||||
'ZRANGEBYSCORE',
|
||||
key,
|
||||
typeof min === 'string' ? min : transformArgumentNumberInfinity(min),
|
||||
typeof max === 'string' ? max : transformArgumentNumberInfinity(max)
|
||||
];
|
||||
|
||||
if (options?.LIMIT) {
|
||||
args.push('LIMIT', options.LIMIT.offset.toString(), options.LIMIT.count.toString());
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
export declare function transformReply(): Array<string>;
|
||||
33
lib/commands/ZRANGEBYSCORE_WITHSCORES.spec.ts
Normal file
33
lib/commands/ZRANGEBYSCORE_WITHSCORES.spec.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import { TestRedisServers, itWithClient } from '../test-utils';
|
||||
import { transformArguments } from './ZRANGEBYSCORE_WITHSCORES';
|
||||
|
||||
describe('ZRANGEBYSCORE WITHSCORES', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('simple', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('src', 0, 1),
|
||||
['ZRANGEBYSCORE', 'src', '0', '1', 'WITHSCORES']
|
||||
);
|
||||
});
|
||||
|
||||
it('with LIMIT', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('src', 0, 1, {
|
||||
LIMIT: {
|
||||
offset: 0,
|
||||
count: 1
|
||||
}
|
||||
}),
|
||||
['ZRANGEBYSCORE', 'src', '0', '1', 'LIMIT', '0', '1', 'WITHSCORES']
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
itWithClient(TestRedisServers.OPEN, 'client.zRangeByScoreWithScores', async client => {
|
||||
assert.deepEqual(
|
||||
await client.zRangeByScoreWithScores('src', 0, 1),
|
||||
[]
|
||||
);
|
||||
});
|
||||
});
|
||||
19
lib/commands/ZRANGEBYSCORE_WITHSCORES.ts
Normal file
19
lib/commands/ZRANGEBYSCORE_WITHSCORES.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { TransformArgumentsReply } from '.';
|
||||
import { transformReplySortedSetWithScores } from './generic-transformers';
|
||||
import { ZRangeByScoreOptions, transformArguments as transformZRangeByScoreArguments } from './ZRANGEBYSCORE';
|
||||
|
||||
export { FIRST_KEY_INDEX, IS_READ_ONLY } from './ZRANGEBYSCORE';
|
||||
|
||||
export function transformArguments(
|
||||
key: string,
|
||||
min: number | string,
|
||||
max: number | string,
|
||||
options?: ZRangeByScoreOptions
|
||||
): TransformArgumentsReply {
|
||||
return [
|
||||
...transformZRangeByScoreArguments(key, min, max, options),
|
||||
'WITHSCORES'
|
||||
];
|
||||
}
|
||||
|
||||
export const transformReply = transformReplySortedSetWithScores;
|
||||
@@ -232,6 +232,9 @@ import * as ZRANDMEMBER_COUNT from './ZRANDMEMBER_COUNT';
|
||||
import * as ZRANDMEMBER from './ZRANDMEMBER';
|
||||
import * as ZRANGE_WITHSCORES from './ZRANGE_WITHSCORES';
|
||||
import * as ZRANGE from './ZRANGE';
|
||||
import * as ZRANGEBYLEX from './ZRANGEBYLEX';
|
||||
import * as ZRANGEBYSCORE_WITHSCORES from './ZRANGEBYSCORE_WITHSCORES';
|
||||
import * as ZRANGEBYSCORE from './ZRANGEBYSCORE';
|
||||
import * as ZRANGESTORE from './ZRANGESTORE';
|
||||
import * as ZRANK from './ZRANK';
|
||||
import * as ZREM from './ZREM';
|
||||
@@ -713,6 +716,12 @@ export default {
|
||||
zRangeWithScores: ZRANGE_WITHSCORES,
|
||||
ZRANGE,
|
||||
zRange: ZRANGE,
|
||||
ZRANGEBYLEX,
|
||||
zRangeByLex: ZRANGEBYLEX,
|
||||
ZRANGEBYSCORE_WITHSCORES,
|
||||
zRangeByScoreWithScores: ZRANGEBYSCORE_WITHSCORES,
|
||||
ZRANGEBYSCORE,
|
||||
zRangeByScore: ZRANGEBYSCORE,
|
||||
ZRANGESTORE,
|
||||
zRangeStore: ZRANGESTORE,
|
||||
ZRANK,
|
||||
|
||||
Reference in New Issue
Block a user