You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
fix XTRIM
This commit is contained in:
@@ -1,49 +1,52 @@
|
||||
// import { strict as assert } from 'assert';
|
||||
// import testUtils, { GLOBAL } from '../test-utils';
|
||||
// import { transformArguments } from './XTRIM';
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import XTRIM from './XTRIM';
|
||||
|
||||
// describe('XTRIM', () => {
|
||||
// describe('transformArguments', () => {
|
||||
// it('simple', () => {
|
||||
// assert.deepEqual(
|
||||
// transformArguments('key', 'MAXLEN', 1),
|
||||
// ['XTRIM', 'key', 'MAXLEN', '1']
|
||||
// );
|
||||
// });
|
||||
describe('XTRIM', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('simple', () => {
|
||||
assert.deepEqual(
|
||||
XTRIM.transformArguments('key', 'MAXLEN', 1),
|
||||
['XTRIM', 'key', 'MAXLEN', '1']
|
||||
);
|
||||
});
|
||||
|
||||
// it('with strategyModifier', () => {
|
||||
// assert.deepEqual(
|
||||
// transformArguments('key', 'MAXLEN', 1, {
|
||||
// strategyModifier: '='
|
||||
// }),
|
||||
// ['XTRIM', 'key', 'MAXLEN', '=', '1']
|
||||
// );
|
||||
// });
|
||||
it('with strategyModifier', () => {
|
||||
assert.deepEqual(
|
||||
XTRIM.transformArguments('key', 'MAXLEN', 1, {
|
||||
strategyModifier: '='
|
||||
}),
|
||||
['XTRIM', 'key', 'MAXLEN', '=', '1']
|
||||
);
|
||||
});
|
||||
|
||||
// it('with LIMIT', () => {
|
||||
// assert.deepEqual(
|
||||
// transformArguments('key', 'MAXLEN', 1, {
|
||||
// LIMIT: 1
|
||||
// }),
|
||||
// ['XTRIM', 'key', 'MAXLEN', '1', 'LIMIT', '1']
|
||||
// );
|
||||
// });
|
||||
it('with LIMIT', () => {
|
||||
assert.deepEqual(
|
||||
XTRIM.transformArguments('key', 'MAXLEN', 1, {
|
||||
LIMIT: 1
|
||||
}),
|
||||
['XTRIM', 'key', 'MAXLEN', '1', 'LIMIT', '1']
|
||||
);
|
||||
});
|
||||
|
||||
// it('with strategyModifier, LIMIT', () => {
|
||||
// assert.deepEqual(
|
||||
// transformArguments('key', 'MAXLEN', 1, {
|
||||
// strategyModifier: '=',
|
||||
// LIMIT: 1
|
||||
// }),
|
||||
// ['XTRIM', 'key', 'MAXLEN', '=', '1', 'LIMIT', '1']
|
||||
// );
|
||||
// });
|
||||
// });
|
||||
it('with strategyModifier, LIMIT', () => {
|
||||
assert.deepEqual(
|
||||
XTRIM.transformArguments('key', 'MAXLEN', 1, {
|
||||
strategyModifier: '=',
|
||||
LIMIT: 1
|
||||
}),
|
||||
['XTRIM', 'key', 'MAXLEN', '=', '1', 'LIMIT', '1']
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
// testUtils.testWithClient('client.xTrim', async client => {
|
||||
// assert.equal(
|
||||
// await client.xTrim('key', 'MAXLEN', 1),
|
||||
// 0
|
||||
// );
|
||||
// }, GLOBAL.SERVERS.OPEN);
|
||||
// });
|
||||
testUtils.testAll('xTrim', async client => {
|
||||
assert.equal(
|
||||
await client.xTrim('key', 'MAXLEN', 1),
|
||||
0
|
||||
);
|
||||
}, {
|
||||
client: GLOBAL.SERVERS.OPEN,
|
||||
cluster: GLOBAL.CLUSTERS.OPEN,
|
||||
});
|
||||
});
|
||||
|
@@ -1,31 +1,31 @@
|
||||
// import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { NumberReply, Command, RedisArgument } from '../RESP/types';
|
||||
|
||||
// export const FIRST_KEY_INDEX = 1;
|
||||
export interface XTrimOptions {
|
||||
strategyModifier?: '=' | '~';
|
||||
LIMIT?: number;
|
||||
}
|
||||
|
||||
// interface XTrimOptions {
|
||||
// strategyModifier?: '=' | '~';
|
||||
// LIMIT?: number;
|
||||
// }
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: false,
|
||||
transformArguments(
|
||||
key: RedisArgument,
|
||||
strategy: 'MAXLEN' | 'MINID',
|
||||
threshold: number,
|
||||
options?: XTrimOptions) {
|
||||
const args = ['XTRIM', key, strategy];
|
||||
|
||||
// export function transformArguments(
|
||||
// key: RedisCommandArgument,
|
||||
// strategy: 'MAXLEN' | 'MINID',
|
||||
// threshold: number,
|
||||
// options?: XTrimOptions
|
||||
// ): RedisCommandArguments {
|
||||
// const args = ['XTRIM', key, strategy];
|
||||
if (options?.strategyModifier) {
|
||||
args.push(options.strategyModifier);
|
||||
}
|
||||
|
||||
// if (options?.strategyModifier) {
|
||||
// args.push(options.strategyModifier);
|
||||
// }
|
||||
args.push(threshold.toString());
|
||||
|
||||
// args.push(threshold.toString());
|
||||
if (options?.LIMIT) {
|
||||
args.push('LIMIT', options.LIMIT.toString());
|
||||
}
|
||||
|
||||
// if (options?.LIMIT) {
|
||||
// args.push('LIMIT', options.LIMIT.toString());
|
||||
// }
|
||||
|
||||
// return args;
|
||||
// }
|
||||
|
||||
// export declare function transformReply(): number;
|
||||
return args;
|
||||
},
|
||||
transformReply: undefined as unknown as () => NumberReply
|
||||
} as const satisfies Command;
|
||||
|
@@ -144,7 +144,8 @@ import WATCH from './WATCH';
|
||||
import XACK from './XACK';
|
||||
import XADD_NOMKSTREAM from './XADD_NOMKSTREAM';
|
||||
import XADD from './XADD';
|
||||
import XDEL from './XDEL'
|
||||
import XDEL from './XDEL';
|
||||
import XTRIM from './XTRIM';
|
||||
import XLEN from './XLEN';
|
||||
import ZADD from './ZADD';
|
||||
import ZCARD from './ZCARD';
|
||||
@@ -466,7 +467,8 @@ export default {
|
||||
xAdd: XADD,
|
||||
XDEL,
|
||||
xDel: XDEL,
|
||||
|
||||
XTRIM,
|
||||
xTrim: XTRIM,
|
||||
XLEN,
|
||||
xLen: XLEN,
|
||||
ZADD,
|
||||
|
Reference in New Issue
Block a user