Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/v5' into v5-search-broken
Browse files Browse the repository at this point in the history
  • Loading branch information
sjpotter committed Oct 11, 2024
2 parents e1b935c + 2eaaa58 commit 1f346f8
Show file tree
Hide file tree
Showing 12 changed files with 123 additions and 20 deletions.
7 changes: 7 additions & 0 deletions packages/search/lib/commands/AGGREGATE.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ describe('AGGREGATE', () => {
);
});

it('with ADDSCORES', () => {
assert.deepEqual(
AGGREGATE.transformArguments('index', '*', { ADDSCORES: true }),
['FT.AGGREGATE', 'index', '*', 'ADDSCORES']
);
});

describe('with LOAD', () => {
describe('single', () => {
describe('without alias', () => {
Expand Down
5 changes: 5 additions & 0 deletions packages/search/lib/commands/AGGREGATE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ interface FilterStep extends AggregateStep<FT_AGGREGATE_STEPS['FILTER']> {

export interface FtAggregateOptions {
VERBATIM?: boolean;
ADDSCORES?: boolean;
LOAD?: LoadField | Array<LoadField>;
TIMEOUT?: number;
STEPS?: Array<GroupByStep | SortStep | ApplyStep | LimitStep | FilterStep>;
Expand Down Expand Up @@ -167,6 +168,10 @@ export function pushAggregateOptions(args: Array<RedisArgument>, options?: FtAgg
args.push('VERBATIM');
}

if (options?.ADDSCORES) {
args.push('ADDSCORES');
}

if (options?.LOAD) {
const length = args.push('LOAD', '');

Expand Down
19 changes: 16 additions & 3 deletions packages/time-series/lib/commands/ADD.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,29 @@ describe('TS.ADD', () => {
);
});

it('with RETENTION, ENCODING, CHUNK_SIZE, ON_DUPLICATE, LABELS', () => {
it ('with IGNORE', () => {
assert.deepEqual(
ADD.transformArguments('key', '*', 1, {
IGNORE: {
maxTimeDiff: 1,
maxValDiff: 1
}
}),
['TS.ADD', 'key', '*', '1', 'IGNORE', '1', '1']
)
});

it('with RETENTION, ENCODING, CHUNK_SIZE, ON_DUPLICATE, LABELS, IGNORE', () => {
assert.deepEqual(
ADD.transformArguments('key', '*', 1, {
RETENTION: 1,
ENCODING: TIME_SERIES_ENCODING.UNCOMPRESSED,
CHUNK_SIZE: 1,
ON_DUPLICATE: TIME_SERIES_DUPLICATE_POLICIES.BLOCK,
LABELS: { label: 'value' }
LABELS: { label: 'value' },
IGNORE: { maxTimeDiff: 1, maxValDiff: 1}
}),
['TS.ADD', 'key', '*', '1', 'RETENTION', '1', 'ENCODING', 'UNCOMPRESSED', 'CHUNK_SIZE', '1', 'ON_DUPLICATE', 'BLOCK', 'LABELS', 'label', 'value']
['TS.ADD', 'key', '*', '1', 'RETENTION', '1', 'ENCODING', 'UNCOMPRESSED', 'CHUNK_SIZE', '1', 'ON_DUPLICATE', 'BLOCK', 'LABELS', 'label', 'value', 'IGNORE', '1', '1']
);
});
});
Expand Down
11 changes: 10 additions & 1 deletion packages/time-series/lib/commands/ADD.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,22 @@ import {
TimeSeriesDuplicatePolicies,
Labels,
pushLabelsArgument,
Timestamp
Timestamp,
pushIgnoreArgument
} from '.';

export interface TsIgnoreOptions {
maxTimeDiff: number;
maxValDiff: number;
}

export interface TsAddOptions {
RETENTION?: number;
ENCODING?: TimeSeriesEncoding;
CHUNK_SIZE?: number;
ON_DUPLICATE?: TimeSeriesDuplicatePolicies;
LABELS?: Labels;
IGNORE?: TsIgnoreOptions;
}

export default {
Expand Down Expand Up @@ -47,6 +54,8 @@ export default {

pushLabelsArgument(args, options?.LABELS);

pushIgnoreArgument(args, options?.IGNORE);

return args;
},
transformReply: undefined as unknown as () => NumberReply
Expand Down
19 changes: 16 additions & 3 deletions packages/time-series/lib/commands/ALTER.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,28 @@ describe('TS.ALTER', () => {
);
});

it('with RETENTION, CHUNK_SIZE, DUPLICATE_POLICY, LABELS', () => {
it('with IGNORE', () => {
assert.deepEqual(
ALTER.transformArguments('key', {
IGNORE: {
maxTimeDiff: 1,
maxValDiff: 1
}
}),
['TS.ALTER', 'key', 'IGNORE', '1', '1']
)
});

it('with RETENTION, CHUNK_SIZE, DUPLICATE_POLICY, LABELS, IGNORE', () => {
assert.deepEqual(
ALTER.transformArguments('key', {
RETENTION: 1,
CHUNK_SIZE: 1,
DUPLICATE_POLICY: TIME_SERIES_DUPLICATE_POLICIES.BLOCK,
LABELS: { label: 'value' }
LABELS: { label: 'value' },
IGNORE: { maxTimeDiff: 1, maxValDiff: 1}
}),
['TS.ALTER', 'key', 'RETENTION', '1', 'CHUNK_SIZE', '1', 'DUPLICATE_POLICY', 'BLOCK', 'LABELS', 'label', 'value']
['TS.ALTER', 'key', 'RETENTION', '1', 'CHUNK_SIZE', '1', 'DUPLICATE_POLICY', 'BLOCK', 'LABELS', 'label', 'value', 'IGNORE', '1', '1']
);
});
});
Expand Down
6 changes: 4 additions & 2 deletions packages/time-series/lib/commands/ALTER.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { RedisArgument, SimpleStringReply, Command } from '@redis/client/dist/lib/RESP/types';
import { TsCreateOptions } from './CREATE';
import { pushRetentionArgument, pushChunkSizeArgument, pushDuplicatePolicy, pushLabelsArgument } from '.';
import { pushRetentionArgument, pushChunkSizeArgument, pushDuplicatePolicy, pushLabelsArgument, pushIgnoreArgument } from '.';

export type TsAlterOptions = Pick<TsCreateOptions, 'RETENTION' | 'CHUNK_SIZE' | 'DUPLICATE_POLICY' | 'LABELS'>;
export type TsAlterOptions = Pick<TsCreateOptions, 'RETENTION' | 'CHUNK_SIZE' | 'DUPLICATE_POLICY' | 'LABELS' | 'IGNORE'>;

export default {
FIRST_KEY_INDEX: 1,
Expand All @@ -18,6 +18,8 @@ export default {

pushLabelsArgument(args, options?.LABELS);

pushIgnoreArgument(args, options?.IGNORE);

return args;
},
transformReply: undefined as unknown as () => SimpleStringReply<'OK'>
Expand Down
19 changes: 16 additions & 3 deletions packages/time-series/lib/commands/CREATE.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,29 @@ describe('TS.CREATE', () => {
);
});

it('with RETENTION, ENCODING, CHUNK_SIZE, DUPLICATE_POLICY, LABELS', () => {
it('with IGNORE', () => {
assert.deepEqual(
CREATE.transformArguments('key', {
IGNORE: {
maxTimeDiff: 1,
maxValDiff: 1
}
}),
['TS.CREATE', 'key', 'IGNORE', '1', '1']
)
});

it('with RETENTION, ENCODING, CHUNK_SIZE, DUPLICATE_POLICY, LABELS, IGNORE', () => {
assert.deepEqual(
CREATE.transformArguments('key', {
RETENTION: 1,
ENCODING: TIME_SERIES_ENCODING.UNCOMPRESSED,
CHUNK_SIZE: 1,
DUPLICATE_POLICY: TIME_SERIES_DUPLICATE_POLICIES.BLOCK,
LABELS: { label: 'value' }
LABELS: { label: 'value' },
IGNORE: { maxTimeDiff: 1, maxValDiff: 1}
}),
['TS.CREATE', 'key', 'RETENTION', '1', 'ENCODING', 'UNCOMPRESSED', 'CHUNK_SIZE', '1', 'DUPLICATE_POLICY', 'BLOCK', 'LABELS', 'label', 'value']
['TS.CREATE', 'key', 'RETENTION', '1', 'ENCODING', 'UNCOMPRESSED', 'CHUNK_SIZE', '1', 'DUPLICATE_POLICY', 'BLOCK', 'LABELS', 'label', 'value', 'IGNORE', '1', '1']
);
});
});
Expand Down
7 changes: 6 additions & 1 deletion packages/time-series/lib/commands/CREATE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@ import {
TimeSeriesDuplicatePolicies,
pushDuplicatePolicy,
Labels,
pushLabelsArgument
pushLabelsArgument,
pushIgnoreArgument
} from '.';
import { TsIgnoreOptions } from './ADD';

export interface TsCreateOptions {
RETENTION?: number;
ENCODING?: TimeSeriesEncoding;
CHUNK_SIZE?: number;
DUPLICATE_POLICY?: TimeSeriesDuplicatePolicies;
LABELS?: Labels;
IGNORE?: TsIgnoreOptions;
}

export default {
Expand All @@ -34,6 +37,8 @@ export default {

pushLabelsArgument(args, options?.LABELS);

pushIgnoreArgument(args, options?.IGNORE);

return args;
},
transformReply: undefined as unknown as () => SimpleStringReply<'OK'>
Expand Down
17 changes: 15 additions & 2 deletions packages/time-series/lib/commands/DECRBY.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,29 @@ describe('TS.DECRBY', () => {
);
});

it ('with IGNORE', () => {
assert.deepEqual(
DECRBY.transformArguments('key', 1, {
IGNORE: {
maxTimeDiff: 1,
maxValDiff: 1
}
}),
['TS.DECRBY', 'key', '1', 'IGNORE', '1', '1']
)
});

it('with TIMESTAMP, RETENTION, UNCOMPRESSED, CHUNK_SIZE and LABELS', () => {
assert.deepEqual(
DECRBY.transformArguments('key', 1, {
TIMESTAMP: '*',
RETENTION: 1,
UNCOMPRESSED: true,
CHUNK_SIZE: 2,
LABELS: { label: 'value' }
LABELS: { label: 'value' },
IGNORE: { maxTimeDiff: 1, maxValDiff: 1 }
}),
['TS.DECRBY', 'key', '1', 'TIMESTAMP', '*', 'RETENTION', '1', 'UNCOMPRESSED', 'CHUNK_SIZE', '2', 'LABELS', 'label', 'value']
['TS.DECRBY', 'key', '1', 'TIMESTAMP', '*', 'RETENTION', '1', 'UNCOMPRESSED', 'CHUNK_SIZE', '2', 'LABELS', 'label', 'value', 'IGNORE', '1', '1']
);
});
});
Expand Down
17 changes: 15 additions & 2 deletions packages/time-series/lib/commands/INCRBY.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,30 @@ describe('TS.INCRBY', () => {
);
});

it ('with IGNORE', () => {
assert.deepEqual(
INCRBY.transformArguments('key', 1, {
IGNORE: {
maxTimeDiff: 1,
maxValDiff: 1
}
}),
['TS.INCRBY', 'key', '1', 'IGNORE', '1', '1']
)
});

it('with TIMESTAMP, RETENTION, UNCOMPRESSED, CHUNK_SIZE and LABELS', () => {
assert.deepEqual(
INCRBY.transformArguments('key', 1, {
TIMESTAMP: '*',
RETENTION: 1,
UNCOMPRESSED: true,
CHUNK_SIZE: 1,
LABELS: { label: 'value' }
LABELS: { label: 'value' },
IGNORE: { maxTimeDiff: 1, maxValDiff: 1 }
}),
['TS.INCRBY', 'key', '1', 'TIMESTAMP', '*', 'RETENTION', '1', 'UNCOMPRESSED',
'CHUNK_SIZE', '1', 'LABELS', 'label', 'value']
'CHUNK_SIZE', '1', 'LABELS', 'label', 'value', 'IGNORE', '1', '1']
);
});
});
Expand Down
6 changes: 5 additions & 1 deletion packages/time-series/lib/commands/INCRBY.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { RedisArgument, NumberReply, Command } from '@redis/client/dist/lib/RESP/types';
import { Timestamp, transformTimestampArgument, pushRetentionArgument, pushChunkSizeArgument, Labels, pushLabelsArgument } from '.';
import { Timestamp, transformTimestampArgument, pushRetentionArgument, pushChunkSizeArgument, Labels, pushLabelsArgument, pushIgnoreArgument } from '.';
import { TsIgnoreOptions } from './ADD';

export interface TsIncrByOptions {
TIMESTAMP?: Timestamp;
RETENTION?: number;
UNCOMPRESSED?: boolean;
CHUNK_SIZE?: number;
LABELS?: Labels;
IGNORE?: TsIgnoreOptions;
}

export function transformIncrByArguments(
Expand Down Expand Up @@ -35,6 +37,8 @@ export function transformIncrByArguments(

pushLabelsArgument(args, options?.LABELS);

pushIgnoreArgument(args, options?.IGNORE);

return args;
}

Expand Down
10 changes: 8 additions & 2 deletions packages/time-series/lib/commands/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { DoubleReply, NumberReply, RedisArgument, RedisCommands, TuplesReply, UnwrapReply, Resp2Reply, ArrayReply, BlobStringReply, MapReply, NullReply, TypeMapping, ReplyUnion, RespType } from '@redis/client/dist/lib/RESP/types';
import ADD from './ADD';
import type { DoubleReply, NumberReply, RedisArgument, RedisCommands, TuplesReply, UnwrapReply, Resp2Reply, ArrayReply, BlobStringReply, MapReply, NullReply, TypeMapping, ReplyUnion, RespType } from '@redis/client/lib/RESP/types';
import ADD, { TsIgnoreOptions } from './ADD';
import ALTER from './ALTER';
import CREATE from './CREATE';
import CREATERULE from './CREATERULE';
Expand Down Expand Up @@ -95,6 +95,12 @@ export default {
revRange: REVRANGE
} as const satisfies RedisCommands;

export function pushIgnoreArgument(args: Array<RedisArgument>, ignore?: TsIgnoreOptions) {
if (ignore !== undefined) {
args.push('IGNORE', ignore.maxTimeDiff.toString(), ignore.maxValDiff.toString());
}
}

export function pushRetentionArgument(args: Array<RedisArgument>, retention?: number) {
if (retention !== undefined) {
args.push('RETENTION', retention.toString());
Expand Down

0 comments on commit 1f346f8

Please sign in to comment.