Skip to content

Commit 8757f5a

Browse files
author
stand4love@163.com
committed
back-end cleanup
1 parent 19e8af5 commit 8757f5a

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

lib/redis.js

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ const DISCONNECTED = 'disconnected';
1818
async function connect(body) {
1919
// already exist
2020
if (redisInstanceCache[body.id]) {
21-
const redisConn = redisInstanceCache[body.id];
22-
if (redisConn.status == DISCONNECTED) {
23-
redisConn.redis.connect();
21+
const redis = redisInstanceCache[body.id];
22+
if (redis.redisStatus == DISCONNECTED) {
23+
redis.redis.connect();
2424
}
2525
return Promise.resolve(body);
2626
}
@@ -39,17 +39,16 @@ async function connect(body) {
3939

4040
redis.on('error', (e) => {
4141
console.error(e);
42-
body.status = DISCONNECTED;
42+
redis.redisStatus = DISCONNECTED;
4343
});
4444

4545
redis.on('end', () => {
4646
redisInstanceCache[body.id] = null;
4747
});
4848

4949
redis.on('ready', () => {
50-
body.redis = redis;
51-
body.status = CONNECTED;
52-
redisInstanceCache[body.id] = body;
50+
redis.redisStatus = CONNECTED;
51+
redisInstanceCache[body.id] = redis;
5352

5453
resolve(body);
5554
clearTimeout(timeoutHandler);
@@ -63,20 +62,19 @@ async function connect(body) {
6362
* @param query the query params
6463
*/
6564
function getRedisConnection(query) {
66-
const redisConn = redisInstanceCache[query.id];
67-
if (!redisConn || redisConn.status !== CONNECTED) {
65+
const redis = redisInstanceCache[query.id];
66+
if (!redis || redis.redisStatus !== CONNECTED) {
6867
throw errors.newConnectFailedError(query.id);
6968
}
70-
return redisConn;
69+
return redis;
7170
}
7271

7372
/**
7473
* fetch the redis tree
7574
* @param query the query params
7675
*/
7776
async function fetchTree(query) {
78-
const redisConn = getRedisConnection(query);
79-
const redis = redisConn.redis;
77+
const redis = getRedisConnection(query);
8078

8179
const root = {};
8280
const lencommands = {
@@ -176,8 +174,7 @@ async function call(query, body) {
176174
if (!lines || lines.length <= 0) {
177175
return [];
178176
}
179-
const redisConn = getRedisConnection(query);
180-
const redis = redisConn.redis;
177+
const redis = getRedisConnection(query);
181178

182179
const results = [];
183180
for (let i = 0; i < lines.length; i++) {
@@ -196,8 +193,7 @@ async function call(query, body) {
196193
* @return {Promise<*>}
197194
*/
198195
async function dump(query) {
199-
const redisConn = getRedisConnection(query);
200-
const redis = redisConn.redis;
196+
const redis = getRedisConnection(query);
201197

202198
try {
203199
return await redisDump(query.exportType, redis);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy