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 XADD
This commit is contained in:
@@ -1,118 +1,93 @@
|
||||
// import { strict as assert } from 'assert';
|
||||
// import testUtils, { GLOBAL } from '../test-utils';
|
||||
// import { transformArguments } from './XADD';
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import XADD from './XADD';
|
||||
|
||||
// describe('XADD', () => {
|
||||
// describe('transformArguments', () => {
|
||||
// it('single field', () => {
|
||||
// assert.deepEqual(
|
||||
// transformArguments('key', '*', {
|
||||
// field: 'value'
|
||||
// }),
|
||||
// ['XADD', 'key', '*', 'field', 'value']
|
||||
// );
|
||||
// });
|
||||
describe('XADD', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('single field', () => {
|
||||
assert.deepEqual(
|
||||
XADD.transformArguments('key', '*', {
|
||||
field: 'value'
|
||||
}),
|
||||
['XADD', 'key', '*', 'field', 'value']
|
||||
);
|
||||
});
|
||||
|
||||
// it('multiple fields', () => {
|
||||
// assert.deepEqual(
|
||||
// transformArguments('key', '*', {
|
||||
// '1': 'I',
|
||||
// '2': 'II'
|
||||
// }),
|
||||
// ['XADD', 'key', '*', '1', 'I', '2', 'II']
|
||||
// );
|
||||
// });
|
||||
it('multiple fields', () => {
|
||||
assert.deepEqual(
|
||||
XADD.transformArguments('key', '*', {
|
||||
'1': 'I',
|
||||
'2': 'II'
|
||||
}),
|
||||
['XADD', 'key', '*', '1', 'I', '2', 'II']
|
||||
);
|
||||
});
|
||||
|
||||
// it('with NOMKSTREAM', () => {
|
||||
// assert.deepEqual(
|
||||
// transformArguments('key', '*', {
|
||||
// field: 'value'
|
||||
// }, {
|
||||
// NOMKSTREAM: true
|
||||
// }),
|
||||
// ['XADD', 'key', 'NOMKSTREAM', '*', 'field', 'value']
|
||||
// );
|
||||
// });
|
||||
it('with TRIM', () => {
|
||||
assert.deepEqual(
|
||||
XADD.transformArguments('key', '*', {
|
||||
field: 'value'
|
||||
}, {
|
||||
TRIM: {
|
||||
threshold: 1000
|
||||
}
|
||||
}),
|
||||
['XADD', 'key', '1000', '*', 'field', 'value']
|
||||
);
|
||||
});
|
||||
|
||||
// it('with TRIM', () => {
|
||||
// assert.deepEqual(
|
||||
// transformArguments('key', '*', {
|
||||
// field: 'value'
|
||||
// }, {
|
||||
// TRIM: {
|
||||
// threshold: 1000
|
||||
// }
|
||||
// }),
|
||||
// ['XADD', 'key', '1000', '*', 'field', 'value']
|
||||
// );
|
||||
// });
|
||||
it('with TRIM.strategy', () => {
|
||||
assert.deepEqual(
|
||||
XADD.transformArguments('key', '*', {
|
||||
field: 'value'
|
||||
}, {
|
||||
TRIM: {
|
||||
strategy: 'MAXLEN',
|
||||
threshold: 1000
|
||||
}
|
||||
}),
|
||||
['XADD', 'key', 'MAXLEN', '1000', '*', 'field', 'value']
|
||||
);
|
||||
});
|
||||
|
||||
// it('with TRIM.strategy', () => {
|
||||
// assert.deepEqual(
|
||||
// transformArguments('key', '*', {
|
||||
// field: 'value'
|
||||
// }, {
|
||||
// TRIM: {
|
||||
// strategy: 'MAXLEN',
|
||||
// threshold: 1000
|
||||
// }
|
||||
// }),
|
||||
// ['XADD', 'key', 'MAXLEN', '1000', '*','field', 'value']
|
||||
// );
|
||||
// });
|
||||
it('with TRIM.strategyModifier', () => {
|
||||
assert.deepEqual(
|
||||
XADD.transformArguments('key', '*', {
|
||||
field: 'value'
|
||||
}, {
|
||||
TRIM: {
|
||||
strategyModifier: '=',
|
||||
threshold: 1000
|
||||
}
|
||||
}),
|
||||
['XADD', 'key', '=', '1000', '*', 'field', 'value']
|
||||
);
|
||||
});
|
||||
|
||||
// it('with TRIM.strategyModifier', () => {
|
||||
// assert.deepEqual(
|
||||
// transformArguments('key', '*', {
|
||||
// field: 'value'
|
||||
// }, {
|
||||
// TRIM: {
|
||||
// strategyModifier: '=',
|
||||
// threshold: 1000
|
||||
// }
|
||||
// }),
|
||||
// ['XADD', 'key', '=', '1000', '*', 'field', 'value']
|
||||
// );
|
||||
// });
|
||||
it('with TRIM.limit', () => {
|
||||
assert.deepEqual(
|
||||
XADD.transformArguments('key', '*', {
|
||||
field: 'value'
|
||||
}, {
|
||||
TRIM: {
|
||||
threshold: 1000,
|
||||
limit: 1
|
||||
}
|
||||
}),
|
||||
['XADD', 'key', '1000', 'LIMIT', '1', '*', 'field', 'value']
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
// it('with TRIM.limit', () => {
|
||||
// assert.deepEqual(
|
||||
// transformArguments('key', '*', {
|
||||
// field: 'value'
|
||||
// }, {
|
||||
// TRIM: {
|
||||
// threshold: 1000,
|
||||
// limit: 1
|
||||
// }
|
||||
// }),
|
||||
// ['XADD', 'key', '1000', 'LIMIT', '1', '*', 'field', 'value']
|
||||
// );
|
||||
// });
|
||||
|
||||
// it('with NOMKSTREAM, TRIM, TRIM.*', () => {
|
||||
// assert.deepEqual(
|
||||
// transformArguments('key', '*', {
|
||||
// field: 'value'
|
||||
// }, {
|
||||
// NOMKSTREAM: true,
|
||||
// TRIM: {
|
||||
// strategy: 'MAXLEN',
|
||||
// strategyModifier: '=',
|
||||
// threshold: 1000,
|
||||
// limit: 1
|
||||
// }
|
||||
// }),
|
||||
// ['XADD', 'key', 'NOMKSTREAM', 'MAXLEN', '=', '1000', 'LIMIT', '1', '*', 'field', 'value']
|
||||
// );
|
||||
// });
|
||||
// });
|
||||
|
||||
// testUtils.testWithClient('client.xAdd', async client => {
|
||||
// assert.equal(
|
||||
// typeof await client.xAdd('key', '*', {
|
||||
// field: 'value'
|
||||
// }),
|
||||
// 'string'
|
||||
// );
|
||||
// }, GLOBAL.SERVERS.OPEN);
|
||||
// });
|
||||
testUtils.testAll('xAdd', async client => {
|
||||
assert.equal(
|
||||
typeof await client.xAdd('key', '*', {
|
||||
field: 'value'
|
||||
}),
|
||||
'string'
|
||||
);
|
||||
}, {
|
||||
client: GLOBAL.SERVERS.OPEN,
|
||||
cluster: GLOBAL.CLUSTERS.OPEN
|
||||
});
|
||||
});
|
||||
|
@@ -1,52 +1,48 @@
|
||||
// import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { RedisArgument, BlobStringReply, Command } from '../RESP/types';
|
||||
|
||||
// export const FIRST_KEY_INDEX = 1;
|
||||
export interface XAddOptions {
|
||||
TRIM?: {
|
||||
strategy?: 'MAXLEN' | 'MINID';
|
||||
strategyModifier?: '=' | '~';
|
||||
threshold: number;
|
||||
limit?: number;
|
||||
};
|
||||
}
|
||||
|
||||
// interface XAddOptions {
|
||||
// NOMKSTREAM?: true;
|
||||
// TRIM?: {
|
||||
// strategy?: 'MAXLEN' | 'MINID';
|
||||
// strategyModifier?: '=' | '~';
|
||||
// threshold: number;
|
||||
// limit?: number;
|
||||
// };
|
||||
// }
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: false,
|
||||
transformArguments(
|
||||
key: RedisArgument,
|
||||
id: RedisArgument,
|
||||
message: Record<string, RedisArgument>,
|
||||
options?: XAddOptions
|
||||
) {
|
||||
const args = ['XADD', key];
|
||||
|
||||
// export function transformArguments(
|
||||
// key: RedisCommandArgument,
|
||||
// id: RedisCommandArgument,
|
||||
// message: Record<string, RedisCommandArgument>,
|
||||
// options?: XAddOptions
|
||||
// ): RedisCommandArguments {
|
||||
// const args = ['XADD', key];
|
||||
if (options?.TRIM) {
|
||||
if (options.TRIM.strategy) {
|
||||
args.push(options.TRIM.strategy);
|
||||
}
|
||||
|
||||
// if (options?.NOMKSTREAM) {
|
||||
// args.push('NOMKSTREAM');
|
||||
// }
|
||||
if (options.TRIM.strategyModifier) {
|
||||
args.push(options.TRIM.strategyModifier);
|
||||
}
|
||||
|
||||
// if (options?.TRIM) {
|
||||
// if (options.TRIM.strategy) {
|
||||
// args.push(options.TRIM.strategy);
|
||||
// }
|
||||
args.push(options.TRIM.threshold.toString());
|
||||
|
||||
// if (options.TRIM.strategyModifier) {
|
||||
// args.push(options.TRIM.strategyModifier);
|
||||
// }
|
||||
if (options.TRIM.limit) {
|
||||
args.push('LIMIT', options.TRIM.limit.toString());
|
||||
}
|
||||
}
|
||||
|
||||
// args.push(options.TRIM.threshold.toString());
|
||||
args.push(id);
|
||||
|
||||
// if (options.TRIM.limit) {
|
||||
// args.push('LIMIT', options.TRIM.limit.toString());
|
||||
// }
|
||||
// }
|
||||
for (const [key, value] of Object.entries(message)) {
|
||||
args.push(key, value);
|
||||
}
|
||||
|
||||
// args.push(id);
|
||||
|
||||
// for (const [key, value] of Object.entries(message)) {
|
||||
// args.push(key, value);
|
||||
// }
|
||||
|
||||
// return args;
|
||||
// }
|
||||
|
||||
// export declare function transformReply(): string;
|
||||
return args;
|
||||
},
|
||||
transformReply: undefined as unknown as () => BlobStringReply
|
||||
} as const satisfies Command;
|
||||
|
93
packages/client/lib/commands/XADD_NOMKSTREAM.spec.ts
Normal file
93
packages/client/lib/commands/XADD_NOMKSTREAM.spec.ts
Normal file
@@ -0,0 +1,93 @@
|
||||
import { strict as assert } from 'assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import XADD_NOMKSTREAM from './XADD_NOMKSTREAM';
|
||||
|
||||
describe('XADD NOMKSTREAM', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('single field', () => {
|
||||
assert.deepEqual(
|
||||
XADD_NOMKSTREAM.transformArguments('key', '*', {
|
||||
field: 'value'
|
||||
}),
|
||||
['XADD', 'key', '*', 'field', 'value', 'NOMKSTREAM']
|
||||
);
|
||||
});
|
||||
|
||||
it('multiple fields', () => {
|
||||
assert.deepEqual(
|
||||
XADD_NOMKSTREAM.transformArguments('key', '*', {
|
||||
'1': 'I',
|
||||
'2': 'II'
|
||||
}),
|
||||
['XADD', 'key', '*', '1', 'I', '2', 'II', 'NOMKSTREAM']
|
||||
);
|
||||
});
|
||||
|
||||
it('with TRIM', () => {
|
||||
assert.deepEqual(
|
||||
XADD_NOMKSTREAM.transformArguments('key', '*', {
|
||||
field: 'value'
|
||||
}, {
|
||||
TRIM: {
|
||||
threshold: 1000
|
||||
}
|
||||
}),
|
||||
['XADD', 'key', '1000', '*', 'field', 'value', 'NOMKSTREAM']
|
||||
);
|
||||
});
|
||||
|
||||
it('with TRIM.strategy', () => {
|
||||
assert.deepEqual(
|
||||
XADD_NOMKSTREAM.transformArguments('key', '*', {
|
||||
field: 'value'
|
||||
}, {
|
||||
TRIM: {
|
||||
strategy: 'MAXLEN',
|
||||
threshold: 1000
|
||||
}
|
||||
}),
|
||||
['XADD', 'key', 'MAXLEN', '1000', '*', 'field', 'value', 'NOMKSTREAM']
|
||||
);
|
||||
});
|
||||
|
||||
it('with TRIM.strategyModifier', () => {
|
||||
assert.deepEqual(
|
||||
XADD_NOMKSTREAM.transformArguments('key', '*', {
|
||||
field: 'value'
|
||||
}, {
|
||||
TRIM: {
|
||||
strategyModifier: '=',
|
||||
threshold: 1000
|
||||
}
|
||||
}),
|
||||
['XADD', 'key', '=', '1000', '*', 'field', 'value', 'NOMKSTREAM']
|
||||
);
|
||||
});
|
||||
|
||||
it('with TRIM.limit', () => {
|
||||
assert.deepEqual(
|
||||
XADD_NOMKSTREAM.transformArguments('key', '*', {
|
||||
field: 'value'
|
||||
}, {
|
||||
TRIM: {
|
||||
threshold: 1000,
|
||||
limit: 1
|
||||
}
|
||||
}),
|
||||
['XADD', 'key', '1000', 'LIMIT', '1', '*', 'field', 'value', 'NOMKSTREAM']
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
testUtils.testAll('xAddNoMkStream', async client => {
|
||||
assert.equal(
|
||||
typeof await client.xAddNoMkStream('key', '*', {
|
||||
field: 'value'
|
||||
}),
|
||||
'string'
|
||||
);
|
||||
}, {
|
||||
client: GLOBAL.SERVERS.OPEN,
|
||||
cluster: GLOBAL.CLUSTERS.OPEN
|
||||
});
|
||||
});
|
13
packages/client/lib/commands/XADD_NOMKSTREAM.ts
Normal file
13
packages/client/lib/commands/XADD_NOMKSTREAM.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { BlobStringReply, NullReply, Command } from '../RESP/types';
|
||||
import XADD from './XADD';
|
||||
|
||||
export default {
|
||||
FIRST_KEY_INDEX: XADD.FIRST_KEY_INDEX,
|
||||
IS_READ_ONLY: XADD.IS_READ_ONLY,
|
||||
transformArguments(...args: Parameters<typeof XADD.transformArguments>) {
|
||||
const redisArgs = XADD.transformArguments(...args);
|
||||
redisArgs.push('NOMKSTREAM');
|
||||
return redisArgs;
|
||||
},
|
||||
transformReply: undefined as unknown as () => BlobStringReply | NullReply
|
||||
} as const satisfies Command;
|
@@ -141,6 +141,8 @@ import UNLINK from './UNLINK';
|
||||
import UNWATCH from './UNWATCH';
|
||||
import WAIT from './WAIT';
|
||||
import WATCH from './WATCH';
|
||||
import XADD_NOMKSTREAM from './XADD_NOMKSTREAM';
|
||||
import XADD from './XADD';
|
||||
import XLEN from './XLEN';
|
||||
import ZADD from './ZADD';
|
||||
import ZCARD from './ZCARD';
|
||||
@@ -407,7 +409,7 @@ export default {
|
||||
SETEX,
|
||||
setEx: SETEX,
|
||||
SETNX,
|
||||
setNX: SETNX,
|
||||
setNX: SETNX,
|
||||
SETRANGE,
|
||||
setRange: SETRANGE,
|
||||
SINTER,
|
||||
@@ -454,6 +456,10 @@ export default {
|
||||
wait: WAIT,
|
||||
WATCH,
|
||||
watch: WATCH,
|
||||
XADD_NOMKSTREAM,
|
||||
xAddNoMkStream: XADD_NOMKSTREAM,
|
||||
XADD,
|
||||
xAdd: XADD,
|
||||
XLEN,
|
||||
xLen: XLEN,
|
||||
ZADD,
|
||||
|
Reference in New Issue
Block a user