You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-17 19:41:06 +03:00
Support new muilti pop commands
This commit is contained in:
37
packages/client/lib/commands/BLMPOP.spec.ts
Normal file
37
packages/client/lib/commands/BLMPOP.spec.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import { transformArguments } from './BLMPOP';
|
||||
|
||||
describe.only('BLMPOP', () => {
|
||||
testUtils.isVersionGreaterThanHook([7, 0]);
|
||||
|
||||
describe('transformArguments', () => {
|
||||
it('simple', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments(0, 'key', {
|
||||
SIDE: 'LEFT'
|
||||
}),
|
||||
['BLMPOP', '0', '1', 'key', 'LEFT']
|
||||
);
|
||||
});
|
||||
|
||||
it('with score and count', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments(0, 'key', {
|
||||
SIDE: 'LEFT',
|
||||
COUNT: 2
|
||||
}),
|
||||
['BLMPOP', '0', '1', 'key', 'LEFT', 'COUNT', '2']
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.zmScore', async client => {
|
||||
assert.deepEqual(
|
||||
await client.blmPop(0, 'key', {
|
||||
SIDE: 'LEFT'
|
||||
}),
|
||||
null
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
});
|
14
packages/client/lib/commands/BLMPOP.ts
Normal file
14
packages/client/lib/commands/BLMPOP.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { RedisCommandArguments } from '.';
|
||||
import { transformLMPopArguments, LMPopOptions } from './generic-transformers';
|
||||
|
||||
export const FIRST_KEY_INDEX = 3;
|
||||
|
||||
export function transformArguments(
|
||||
timeout: number,
|
||||
keys: string | Array<string>,
|
||||
options: LMPopOptions
|
||||
): RedisCommandArguments {
|
||||
return transformLMPopArguments(['BLMPOP', timeout.toString()], keys, options);
|
||||
}
|
||||
|
||||
export { transformReply } from './LMPOP';
|
37
packages/client/lib/commands/BZMPOP.spec.ts
Normal file
37
packages/client/lib/commands/BZMPOP.spec.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import { transformArguments } from './BZMPOP';
|
||||
|
||||
describe.only('BZMPOP', () => {
|
||||
testUtils.isVersionGreaterThanHook([7, 0]);
|
||||
|
||||
describe('transformArguments', () => {
|
||||
it('simple', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments(0, 'key', {
|
||||
SCORE: 'MIN'
|
||||
}),
|
||||
['BZMPOP', '0', '1', 'key', 'MIN']
|
||||
);
|
||||
});
|
||||
|
||||
it('with score and count', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments(0, 'key', {
|
||||
SCORE: 'MIN',
|
||||
COUNT: 2
|
||||
}),
|
||||
['BZMPOP', '0', '1', 'key', 'MIN', 'COUNT', '2']
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.zmScore', async client => {
|
||||
assert.deepEqual(
|
||||
await client.bzmPop(0, 'key', {
|
||||
SCORE: 'MAX'
|
||||
}),
|
||||
null
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
});
|
14
packages/client/lib/commands/BZMPOP.ts
Normal file
14
packages/client/lib/commands/BZMPOP.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { RedisCommandArguments } from '.';
|
||||
import { transformZMPopArguments, ZMPopOptions } from './generic-transformers';
|
||||
|
||||
export const FIRST_KEY_INDEX = 3;
|
||||
|
||||
export function transformArguments(
|
||||
timeout: number,
|
||||
keys: string | Array<string>,
|
||||
options: ZMPopOptions
|
||||
): RedisCommandArguments {
|
||||
return transformZMPopArguments(['BZMPOP', timeout.toString()], keys, options);
|
||||
}
|
||||
|
||||
export { transformReply } from './ZMPOP';
|
37
packages/client/lib/commands/LMPOP.spec.ts
Normal file
37
packages/client/lib/commands/LMPOP.spec.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import { transformArguments } from './LMPOP';
|
||||
|
||||
describe.only('LMPOP', () => {
|
||||
testUtils.isVersionGreaterThanHook([7, 0]);
|
||||
|
||||
describe('transformArguments', () => {
|
||||
it('simple', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', {
|
||||
SIDE: 'LEFT'
|
||||
}),
|
||||
['LMPOP', '1', 'key', 'LEFT']
|
||||
);
|
||||
});
|
||||
|
||||
it('with score and count', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', {
|
||||
SIDE: 'LEFT',
|
||||
COUNT: 2
|
||||
}),
|
||||
['LMPOP', '1', 'key', 'LEFT', 'COUNT', '2']
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.zmScore', async client => {
|
||||
assert.deepEqual(
|
||||
await client.lmPop('key', {
|
||||
SIDE: 'RIGHT'
|
||||
}),
|
||||
null
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
});
|
20
packages/client/lib/commands/LMPOP.ts
Normal file
20
packages/client/lib/commands/LMPOP.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { RedisCommandArguments } from '.';
|
||||
import { transformLMPopArguments, LMPopOptions } from './generic-transformers';
|
||||
|
||||
export const FIRST_KEY_INDEX = 2;
|
||||
|
||||
export const IS_READ_ONLY = true;
|
||||
|
||||
export function transformArguments(
|
||||
keys: string | Array<string>,
|
||||
options: LMPopOptions
|
||||
): RedisCommandArguments {
|
||||
return transformLMPopArguments(['LMPOP'], keys, options);
|
||||
}
|
||||
|
||||
type LMPopReply = null | [
|
||||
key: string,
|
||||
elements: Array<String>
|
||||
];
|
||||
|
||||
export declare function transformReply(): LMPopReply;
|
37
packages/client/lib/commands/ZMPOP.spec.ts
Normal file
37
packages/client/lib/commands/ZMPOP.spec.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import { transformArguments } from './ZMPOP';
|
||||
|
||||
describe.only('ZMPOP', () => {
|
||||
testUtils.isVersionGreaterThanHook([7, 0]);
|
||||
|
||||
describe('transformArguments', () => {
|
||||
it('simple', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', {
|
||||
SCORE: 'MIN'
|
||||
}),
|
||||
['ZMPOP', '1', 'key', 'MIN']
|
||||
);
|
||||
});
|
||||
|
||||
it('with score and count', () => {
|
||||
assert.deepEqual(
|
||||
transformArguments('key', {
|
||||
SCORE: 'MIN',
|
||||
COUNT: 2
|
||||
}),
|
||||
['ZMPOP', '1', 'key', 'MIN', 'COUNT', '2']
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.zmScore', async client => {
|
||||
assert.deepEqual(
|
||||
await client.zmPop('key', {
|
||||
SCORE: 'MAX'
|
||||
}),
|
||||
null
|
||||
);
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
});
|
26
packages/client/lib/commands/ZMPOP.ts
Normal file
26
packages/client/lib/commands/ZMPOP.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { 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<string>,
|
||||
options: ZMPopOptions
|
||||
): RedisCommandArguments {
|
||||
return transformZMPopArguments(['ZMPOP'], keys, options);
|
||||
}
|
||||
|
||||
type ZMPopRawReply = null | [string, Array<[RedisCommandArgument, RedisCommandArgument]>];
|
||||
|
||||
type ZMPopReply = null | [
|
||||
key: string,
|
||||
elements: Array<ZMember>
|
||||
];
|
||||
|
||||
export function transformReply(reply: ZMPopRawReply): ZMPopReply {
|
||||
if (reply == null) return null;
|
||||
|
||||
return [reply[0], reply[1].map(transformSortedSetMemberReply)];
|
||||
}
|
@@ -131,6 +131,13 @@ export function transformSortedSetMemberNullReply(
|
||||
): ZMember | null {
|
||||
if (!reply.length) return null;
|
||||
|
||||
return transformSortedSetMemberReply(reply);
|
||||
}
|
||||
|
||||
export function transformSortedSetMemberReply(
|
||||
reply: [RedisCommandArgument, RedisCommandArgument]
|
||||
): ZMember {
|
||||
|
||||
return {
|
||||
value: reply[0],
|
||||
score: transformNumberInfinityReply(reply[1])
|
||||
@@ -150,6 +157,49 @@ export function transformSortedSetWithScoresReply(reply: Array<RedisCommandArgum
|
||||
return members;
|
||||
}
|
||||
|
||||
|
||||
export interface ZMPopOptions {
|
||||
SCORE: 'MIN' | 'MAX';
|
||||
COUNT?: number;
|
||||
}
|
||||
|
||||
export function transformZMPopArguments(
|
||||
args: RedisCommandArguments,
|
||||
keys: string | Array<string>,
|
||||
options: ZMPopOptions
|
||||
): RedisCommandArguments {
|
||||
pushVerdictArgument(args, keys);
|
||||
|
||||
args.push(options.SCORE);
|
||||
|
||||
if (options?.COUNT) {
|
||||
args.push('COUNT', options.COUNT.toString());
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
export interface LMPopOptions {
|
||||
SIDE: 'LEFT' | 'RIGHT';
|
||||
COUNT?: number;
|
||||
}
|
||||
|
||||
export function transformLMPopArguments(
|
||||
args: RedisCommandArguments,
|
||||
keys: string | Array<string>,
|
||||
options: LMPopOptions
|
||||
): RedisCommandArguments {
|
||||
pushVerdictArgument(args, keys);
|
||||
|
||||
args.push(options.SIDE);
|
||||
|
||||
if (options?.COUNT) {
|
||||
args.push('COUNT', options.COUNT.toString());
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
type GeoCountArgument = number | {
|
||||
value: number;
|
||||
ANY?: true
|
||||
|
Reference in New Issue
Block a user