|
1 |
| -import { BadRequestException, Injectable } from '@nestjs/common'; |
| 1 | +import { BadRequestException, Injectable, ForbiddenException } from '@nestjs/common'; |
2 | 2 | import * as IORedis from 'ioredis';
|
3 | 3 | import {
|
4 | 4 | IRedisClusterInfo,
|
@@ -216,30 +216,36 @@ export class DatabaseInfoProvider {
|
216 | 216 | private async getRedisNodeGeneralInfo(
|
217 | 217 | client: IORedis.Redis,
|
218 | 218 | ): Promise<RedisDatabaseInfoResponse> {
|
219 |
| - const info = convertRedisInfoReplyToObject( |
220 |
| - await client.info(), |
221 |
| - ); |
222 |
| - const serverInfo = info['server']; |
223 |
| - const memoryInfo = info['memory']; |
224 |
| - const keyspaceInfo = info['keyspace']; |
225 |
| - const clientsInfo = info['clients']; |
226 |
| - const statsInfo = info['stats']; |
227 |
| - const replicationInfo = info['replication']; |
228 |
| - const databases = await this.getDatabasesCount(client, keyspaceInfo); |
229 |
| - return { |
230 |
| - version: serverInfo?.redis_version, |
231 |
| - databases, |
232 |
| - role: get(replicationInfo, 'role') || undefined, |
233 |
| - totalKeys: this.getRedisNodeTotalKeysCount(keyspaceInfo), |
234 |
| - usedMemory: parseInt(get(memoryInfo, 'used_memory'), 10) || undefined, |
235 |
| - connectedClients: |
236 |
| - parseInt(get(clientsInfo, 'connected_clients'), 10) || undefined, |
237 |
| - uptimeInSeconds: |
238 |
| - parseInt(get(serverInfo, 'uptime_in_seconds'), 10) || undefined, |
239 |
| - hitRatio: this.getRedisHitRatio(statsInfo), |
240 |
| - cashedScripts: parseInt(get(memoryInfo, 'number_of_cached_scripts'), 10) || undefined, |
241 |
| - server: serverInfo, |
242 |
| - }; |
| 219 | + try { |
| 220 | + const info = convertRedisInfoReplyToObject( |
| 221 | + await client.info(), |
| 222 | + ); |
| 223 | + const serverInfo = info['server']; |
| 224 | + const memoryInfo = info['memory']; |
| 225 | + const keyspaceInfo = info['keyspace']; |
| 226 | + const clientsInfo = info['clients']; |
| 227 | + const statsInfo = info['stats']; |
| 228 | + const replicationInfo = info['replication']; |
| 229 | + const databases = await this.getDatabasesCount(client, keyspaceInfo); |
| 230 | + return { |
| 231 | + version: serverInfo?.redis_version, |
| 232 | + databases, |
| 233 | + role: get(replicationInfo, 'role') || undefined, |
| 234 | + totalKeys: this.getRedisNodeTotalKeysCount(keyspaceInfo), |
| 235 | + usedMemory: parseInt(get(memoryInfo, 'used_memory'), 10) || undefined, |
| 236 | + connectedClients: |
| 237 | + parseInt(get(clientsInfo, 'connected_clients'), 10) || undefined, |
| 238 | + uptimeInSeconds: |
| 239 | + parseInt(get(serverInfo, 'uptime_in_seconds'), 10) || undefined, |
| 240 | + hitRatio: this.getRedisHitRatio(statsInfo), |
| 241 | + cashedScripts: parseInt(get(memoryInfo, 'number_of_cached_scripts'), 10) || undefined, |
| 242 | + server: serverInfo, |
| 243 | + }; |
| 244 | + } catch (error) { |
| 245 | + if (error.message.includes('NOPERM this user has no permissions to run the \'info\' command')) { |
| 246 | + throw new ForbiddenException(ERROR_MESSAGES.NO_PERMISSION_COMMAND_INFO); |
| 247 | + } |
| 248 | + } |
243 | 249 | }
|
244 | 250 |
|
245 | 251 | private async getRedisMasterNodesGeneralInfo(
|
|
0 commit comments