Skip to content

Commit cc3efc7

Browse files
author
Artem
committed
fix RI-5193, RI-5191. overwrite dbIndex after successful "select"
1 parent 71912ce commit cc3efc7

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

redisinsight/api/src/modules/redis/redis-connection.factory.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Injectable, InternalServerErrorException, Logger } from '@nestjs/common
33
import { Database } from 'src/modules/database/models/database';
44
import apiConfig from 'src/utils/config';
55
import { ConnectionOptions } from 'tls';
6-
import { isEmpty, isNumber } from 'lodash';
6+
import { isEmpty, isNumber, set } from 'lodash';
77
import { cloneClassInstance, generateRedisConnectionName } from 'src/utils';
88
import { ConnectionType } from 'src/modules/database/entities/database.entity';
99
import { ClientMetadata } from 'src/common/models';
@@ -212,7 +212,10 @@ export class RedisConnectionFactory {
212212
// since ioredis doesn't handle "select" command error during connection
213213
if (dbIndex > 0) {
214214
connection.select(dbIndex)
215-
.then(() => resolve(connection))
215+
.then(() => {
216+
set(connection, ['options', 'db'], dbIndex);
217+
resolve(connection);
218+
})
216219
.catch(reject);
217220
} else {
218221
resolve(connection);
@@ -283,7 +286,10 @@ export class RedisConnectionFactory {
283286
// since ioredis doesn't handle "select" command error during connection
284287
if (config.redisOptions.db > 0) {
285288
connection.select(config.redisOptions.db)
286-
.then(() => resolve(connection))
289+
.then(() => {
290+
set(connection, ['options', 'db'], config.redisOptions.db);
291+
resolve(connection);
292+
})
287293
.catch(reject);
288294
} else {
289295
resolve(connection);
@@ -343,7 +349,10 @@ export class RedisConnectionFactory {
343349
// since ioredis doesn't handle "select" command error during connection
344350
if (config.db > 0) {
345351
connection.select(config.db)
346-
.then(() => resolve(connection))
352+
.then(() => {
353+
set(connection, ['options', 'db'], config.db);
354+
resolve(connection);
355+
})
347356
.catch(reject);
348357
} else {
349358
resolve(connection);

0 commit comments

Comments
 (0)