Skip to content

Commit 03089c4

Browse files
authored
Merge pull request #3575 from RedisInsight/be/bugfix/RI-5820-fix-reply-transform
fix transform reply
2 parents 81d9e25 + 1e5b0a7 commit 03089c4

File tree

8 files changed

+24
-10
lines changed

8 files changed

+24
-10
lines changed

redisinsight/api/src/modules/browser/constants/browser-tool-commands.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export enum BrowserToolStringCommands {
2020

2121
export enum BrowserToolHashCommands {
2222
HSet = 'hset',
23+
HGetAll = 'hgetall',
24+
HGETALL = 'HGETALL',
2325
HGet = 'hget',
2426
HLen = 'hlen',
2527
HScan = 'hscan',

redisinsight/api/src/modules/redis/client/ioredis/ioredis.client.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import { RedisString } from 'src/common/constants';
1010
import { ClientMetadata } from 'src/common/models';
1111
import { BrowserToolHashCommands } from 'src/modules/browser/constants/browser-tool-commands';
1212

13+
// should return array (same as original reply)
14+
Redis.Command.setReplyTransformer(BrowserToolHashCommands.HGetAll, (result) => result);
15+
1316
export abstract class IoredisClient extends RedisClient {
1417
constructor(
1518
public readonly clientMetadata: ClientMetadata,
@@ -20,6 +23,8 @@ export abstract class IoredisClient extends RedisClient {
2023
client.addBuiltinCommand(BrowserToolHashCommands.HExpire);
2124
client.addBuiltinCommand(BrowserToolHashCommands.HTtl);
2225
client.addBuiltinCommand(BrowserToolHashCommands.HPersist);
26+
// fix not existing command in pipeline
27+
client.addBuiltinCommand(BrowserToolHashCommands.HGETALL);
2328
}
2429

2530
static prepareCommandOptions(options: IRedisClientCommandOptions): any {

redisinsight/api/src/modules/redis/connection/ioredis.redis.connection.strategy.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import * as Redis from 'ioredis';
33
import {
44
mockClientMetadata, mockClusterDatabaseWithTlsAuth,
55
mockDatabase, mockDatabaseWithSshBasic,
6-
mockDatabaseWithTlsAuth, mockIORedisClient,
7-
mockSentinelDatabaseWithTlsAuth, mockSshTunnel, mockSshTunnelProvider, mockStandaloneRedisClient
6+
mockDatabaseWithTlsAuth,
7+
mockSentinelDatabaseWithTlsAuth,
8+
mockSshTunnelProvider,
9+
mockStandaloneRedisClient,
810
} from 'src/__mocks__';
911
import { EventEmitter } from 'events';
1012
import apiConfig, { Config } from 'src/utils/config';

redisinsight/api/test/api/cli/POST-databases-id-cli-uuid-send_command.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
requirements, serverConfig
1313
} from '../deps';
1414
import { ServerService } from 'src/modules/server/server.service';
15+
import { convertArrayReplyToObject } from 'src/modules/redis/utils';
1516
const { server, request, constants, rte, analytics } = deps;
1617

1718
// endpoint to test
@@ -292,7 +293,7 @@ describe('POST /databases/:instanceId/cli/:uuid/send-command', () => {
292293
expect(await rte.client.exists(constants.TEST_HASH_KEY_1)).to.eql(0);
293294
},
294295
after: async () => {
295-
expect(await rte.client.hgetall(constants.TEST_HASH_KEY_1)).to.deep.eql({
296+
expect(convertArrayReplyToObject(await rte.client.hgetall(constants.TEST_HASH_KEY_1))).to.deep.eql({
296297
[constants.TEST_HASH_FIELD_1_NAME]: constants.TEST_HASH_FIELD_1_VALUE,
297298
});
298299
},

redisinsight/api/test/api/hash/DELETE-databases-id-hash-fields.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
} from '../deps';
1111
const { server, request, constants, rte } = deps;
1212
import * as Joi from 'joi';
13+
import { convertArrayReplyToObject } from 'src/modules/redis/utils';
1314

1415
// endpoint to test
1516
const endpoint = (instanceId = constants.TEST_INSTANCE_ID) =>
@@ -89,7 +90,7 @@ describe('DELETE /databases/:instanceId/hash/fields', () => {
8990
affected: 0,
9091
},
9192
after: async () => {
92-
const fields = await rte.client.hgetall(constants.TEST_HASH_KEY_2);
93+
const fields = convertArrayReplyToObject(await rte.client.hgetall(constants.TEST_HASH_KEY_2));
9394
(new Array(3000).fill(0)).map((_, i) => {
9495
expect(fields[`field_${i + 1}`]).to.eql(`value_${i + 1}`);
9596
});
@@ -106,7 +107,7 @@ describe('DELETE /databases/:instanceId/hash/fields', () => {
106107
affected: 1,
107108
},
108109
after: async () => {
109-
const fields = await rte.client.hgetall(constants.TEST_HASH_KEY_2);
110+
const fields = convertArrayReplyToObject(await rte.client.hgetall(constants.TEST_HASH_KEY_2));
110111
(new Array(2999).fill(0)).map((_, i) => {
111112
expect(fields[`field_${i + 1}`]).to.eql(`value_${i + 1}`);
112113
});
@@ -123,7 +124,7 @@ describe('DELETE /databases/:instanceId/hash/fields', () => {
123124
affected: 4,
124125
},
125126
after: async () => {
126-
const fields = await rte.client.hgetall(constants.TEST_HASH_KEY_2);
127+
const fields = convertArrayReplyToObject(await rte.client.hgetall(constants.TEST_HASH_KEY_2));
127128
(new Array(2995).fill(0)).map((_, i) => {
128129
expect(fields[`field_${i + 3}`]).to.eql(`value_${i + 3}`);
129130
});

redisinsight/api/test/api/hash/POST-databases-id-hash.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
} from '../deps';
1212
const { server, request, constants, rte } = deps;
1313
import * as Joi from 'joi';
14+
import { convertArrayReplyToObject } from 'src/modules/redis/utils';
1415

1516
// endpoint to test
1617
const endpoint = (instanceId = constants.TEST_INSTANCE_ID) =>
@@ -62,7 +63,7 @@ const createCheckFn = async (testCase) => {
6263
} else {
6364
if (testCase.statusCode === 201) {
6465
expect(await rte.client.exists(testCase.data.keyName)).to.eql(1);
65-
expect(await rte.client.hgetall(testCase.data.keyName)).to.eql({
66+
expect(convertArrayReplyToObject(await rte.client.hgetall(testCase.data.keyName))).to.eql({
6667
[testCase.data.fields[0].field]: testCase.data.fields[0].value,
6768
});
6869
if (testCase.data.expire) {
@@ -188,7 +189,7 @@ describe('POST /databases/:instanceId/hash', () => {
188189
},
189190
after: async () =>
190191
// check that value was not overwritten
191-
expect(await rte.client.hgetall(constants.TEST_HASH_KEY_1)).to.deep.eql({
192+
expect(convertArrayReplyToObject(await rte.client.hgetall(constants.TEST_HASH_KEY_1))).to.deep.eql({
192193
[constants.TEST_HASH_FIELD_1_NAME]: constants.TEST_HASH_FIELD_1_VALUE,
193194
})
194195
},

redisinsight/api/test/api/hash/PUT-databases-id-hash.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
} from '../deps';
1111
const { server, request, constants, rte } = deps;
1212
import * as Joi from 'joi';
13+
import { convertArrayReplyToObject } from 'src/modules/redis/utils';
1314

1415
// endpoint to test
1516
const endpoint = (instanceId = constants.TEST_INSTANCE_ID) =>
@@ -111,7 +112,7 @@ describe('PUT /databases/:instanceId/hash', () => {
111112
},
112113
statusCode: 200,
113114
after: async () => {
114-
expect(await rte.client.hgetall(constants.TEST_HASH_KEY_1)).to.eql({
115+
expect(convertArrayReplyToObject(await rte.client.hgetall(constants.TEST_HASH_KEY_1))).to.eql({
115116
[constants.TEST_HASH_FIELD_1_NAME]: '',
116117
[constants.TEST_HASH_FIELD_2_NAME]: constants.TEST_HASH_FIELD_2_VALUE,
117118
['new_field']: 'new_value',

redisinsight/api/test/api/workbench/POST-databases-id-workbench-command_executions.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
validateApiCall,
1212
requirements,
1313
} from '../deps';
14+
import { convertArrayReplyToObject } from 'src/modules/redis/utils';
1415
const { server, request, constants, rte, localDb } = deps;
1516

1617
// endpoint to test
@@ -369,7 +370,7 @@ describe('POST /databases/:instanceId/workbench/command-executions', () => {
369370
expect(await rte.client.exists(constants.TEST_HASH_KEY_1)).to.eql(0);
370371
},
371372
after: async () => {
372-
expect(await rte.client.hgetall(constants.TEST_HASH_KEY_1)).to.deep.eql({
373+
expect(convertArrayReplyToObject(await rte.client.hgetall(constants.TEST_HASH_KEY_1))).to.deep.eql({
373374
[constants.TEST_HASH_FIELD_1_NAME]: constants.TEST_HASH_FIELD_1_VALUE,
374375
});
375376
},

0 commit comments

Comments
 (0)