Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,15 @@ describe('RedisearchService', () => {
cursor: mockSearchRedisearchDto.limit + mockSearchRedisearchDto.offset,
scanned: 2,
total: 100,
maxResults: null,
keys: [{
name: keyName1,
}, {
name: keyName2,
}],
});

expect(nodeClient.sendCommand).toHaveBeenCalledTimes(1);
expect(nodeClient.sendCommand).toHaveBeenCalledTimes(2);
expect(nodeClient.sendCommand).toHaveBeenCalledWith(jasmine.objectContaining({
name: 'FT.SEARCH',
args: [
Expand All @@ -239,6 +240,13 @@ describe('RedisearchService', () => {
'LIMIT', `${mockSearchRedisearchDto.offset}`, `${mockSearchRedisearchDto.limit}`,
],
}));
expect(nodeClient.sendCommand).toHaveBeenCalledWith(jasmine.objectContaining( {
name: 'FT.CONFIG',
args: [
'GET',
'MAXSEARCHRESULTS',
],
}));
});
it('should search in cluster', async () => {
browserTool.getRedisClient.mockResolvedValue(clusterClient);
Expand All @@ -252,13 +260,14 @@ describe('RedisearchService', () => {
cursor: mockSearchRedisearchDto.limit + mockSearchRedisearchDto.offset,
scanned: 2,
total: 100,
maxResults: null,
keys: [
{ name: keyName1 },
{ name: keyName2 },
],
});

expect(clusterClient.sendCommand).toHaveBeenCalledTimes(1);
expect(clusterClient.sendCommand).toHaveBeenCalledTimes(2);
expect(clusterClient.sendCommand).toHaveBeenCalledWith(jasmine.objectContaining({
name: 'FT.SEARCH',
args: [
Expand All @@ -268,6 +277,13 @@ describe('RedisearchService', () => {
'LIMIT', `${mockSearchRedisearchDto.offset}`, `${mockSearchRedisearchDto.limit}`,
],
}));
expect(clusterClient.sendCommand).toHaveBeenCalledWith(jasmine.objectContaining( {
name: 'FT.CONFIG',
args: [
'GET',
'MAXSEARCHRESULTS',
],
}));
});
it('should handle ACL error (ft.info command)', async () => {
when(nodeClient.sendCommand)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
import { GetKeysWithDetailsResponse } from 'src/modules/browser/dto';
import { RedisErrorCodes } from 'src/constants';
import { plainToClass } from 'class-transformer';
import { numberWithSpaces } from 'src/utils/base.helper';
import { BrowserToolService } from '../browser-tool/browser-tool.service';

@Injectable()
Expand Down Expand Up @@ -174,7 +175,7 @@ export class RedisearchService {
} catch (error) {
this.logger.error('Failed to search keys using redisearch index', error);
if (error.message?.includes(RedisErrorCodes.RedisearchLimit)) {
throw new BadRequestException(ERROR_MESSAGES.INCREASE_MINIMUM_LIMIT(dto.limit?.toLocaleString?.()));
throw new BadRequestException(ERROR_MESSAGES.INCREASE_MINIMUM_LIMIT(numberWithSpaces(dto.limit)));
}
throw catchAclError(error);
}
Expand Down
23 changes: 23 additions & 0 deletions redisinsight/api/src/utils/base.helper.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { numberWithSpaces } from 'src/utils/base.helper';

const numberWithSpacesTests = [
{ input: 0, output: '0' },
{ input: 10, output: '10' },
{ input: 100, output: '100' },
{ input: 1000, output: '1 000' },
{ input: 1000.001, output: '1 000.001' },
{ input: 5500, output: '5 500' },
{ input: 1000000, output: '1 000 000' },
{ input: 1233543234543243, output: '1 233 543 234 543 243' },
{ input: NaN, output: 'NaN' },
];

describe('numberWithSpaces', () => {
numberWithSpacesTests.forEach((test) => {
it(`should be output: ${test.output} for input: ${test.input} `, async () => {
const result = numberWithSpaces(test.input);

expect(result).toEqual(test.output);
});
});
});
4 changes: 4 additions & 0 deletions redisinsight/api/src/utils/base.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ export const sortByNumberField = <T>(
items: T[],
field: string,
): T[] => sortBy(items, (o) => (o && isNumber(o[field]) ? o[field] : -Infinity));


export const numberWithSpaces = (number: number = 0) =>
number.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ' ')
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { numberWithSpaces } from 'src/utils/base.helper';
import {
expect,
describe,
Expand Down Expand Up @@ -89,7 +90,7 @@ describe('POST /databases/:id/redisearch/search', () => {
responseBody: {
statusCode: 400,
error: 'Bad Request',
message: `Use a minimum of ${validInputData.limit} as the LIMIT.`,
message: `Set MAXSEARCHRESULTS to at least ${numberWithSpaces(validInputData.limit)}.`,
},
before: () => rte.data.setRedisearchConfig('MAXSEARCHRESULTS', '1'),
after: () => rte.data.setRedisearchConfig('MAXSEARCHRESULTS', '10000'),
Expand Down