@samet-it/be-redis-common 1.1.2 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2,7 +2,7 @@ import type { RedisConnectionLike } from "../connection";
|
|
|
2
2
|
import type { RedisChannelProps, RedisChannelLike, RedisChannelOpt } from "./index.types";
|
|
3
3
|
import { type Entity } from "@samet-it/be-base-common";
|
|
4
4
|
import { CacheChannel } from "@samet-it/be-cache-common";
|
|
5
|
-
import type { KeyValue
|
|
5
|
+
import type { KeyValue } from "@leyyo/common";
|
|
6
6
|
/**
|
|
7
7
|
* Redis abstract channel class
|
|
8
8
|
*
|
|
@@ -20,13 +20,6 @@ export declare abstract class RedisChannel<ENT extends Entity<ID>, ID extends Ke
|
|
|
20
20
|
* @param {RedisChannelOpt} opt - options
|
|
21
21
|
* */
|
|
22
22
|
protected constructor(conn: RedisConnectionLike, opt?: RedisChannelOpt);
|
|
23
|
-
/**
|
|
24
|
-
* @Check error
|
|
25
|
-
*
|
|
26
|
-
* @param {Error} e - error instance
|
|
27
|
-
* @param {Opt} params - parameters
|
|
28
|
-
* */
|
|
29
|
-
protected _checkError(e: Error, params?: Opt): void;
|
|
30
23
|
/** @inheritDoc */
|
|
31
24
|
get props(): Readonly<RedisChannelProps>;
|
|
32
25
|
/** @inheritDoc */
|
|
@@ -10,7 +10,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.RedisChannel = void 0;
|
|
13
|
-
const be_base_common_1 = require("@samet-it/be-base-common");
|
|
14
13
|
const be_cache_common_1 = require("@samet-it/be-cache-common");
|
|
15
14
|
// noinspection JSUnusedGlobalSymbols
|
|
16
15
|
/**
|
|
@@ -43,24 +42,6 @@ class RedisChannel extends be_cache_common_1.CacheChannel {
|
|
|
43
42
|
this._props.isConnected = false;
|
|
44
43
|
}));
|
|
45
44
|
}
|
|
46
|
-
// region protected-methods
|
|
47
|
-
/**
|
|
48
|
-
* @Check error
|
|
49
|
-
*
|
|
50
|
-
* @param {Error} e - error instance
|
|
51
|
-
* @param {Opt} params - parameters
|
|
52
|
-
* */
|
|
53
|
-
_checkError(e, params) {
|
|
54
|
-
be_base_common_1.errorHandler.addStat(e);
|
|
55
|
-
if (e instanceof be_cache_common_1.CacheError) {
|
|
56
|
-
// todo append params
|
|
57
|
-
throw e;
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
throw be_base_common_1.errorHandler.common.castForClass(be_cache_common_1.CacheError, e, params);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
// endregion protected-methods
|
|
64
45
|
// region getter
|
|
65
46
|
/** @inheritDoc */
|
|
66
47
|
get props() {
|
|
@@ -71,7 +52,7 @@ class RedisChannel extends be_cache_common_1.CacheChannel {
|
|
|
71
52
|
/** @inheritDoc */
|
|
72
53
|
$get(...paths) {
|
|
73
54
|
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
-
const { client } = this._props;
|
|
55
|
+
const { client, conn } = this._props;
|
|
75
56
|
if (!client) {
|
|
76
57
|
return [];
|
|
77
58
|
}
|
|
@@ -86,14 +67,14 @@ class RedisChannel extends be_cache_common_1.CacheChannel {
|
|
|
86
67
|
return (yield client.mGet(paths));
|
|
87
68
|
}
|
|
88
69
|
catch (e) {
|
|
89
|
-
|
|
70
|
+
conn.checkError(e, { name: 'MGET', method: '$get' });
|
|
90
71
|
}
|
|
91
72
|
});
|
|
92
73
|
}
|
|
93
74
|
/** @inheritDoc */
|
|
94
75
|
$set(map) {
|
|
95
76
|
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
-
const { client } = this._props;
|
|
77
|
+
const { client, conn } = this._props;
|
|
97
78
|
if (!client) {
|
|
98
79
|
return 0;
|
|
99
80
|
}
|
|
@@ -110,7 +91,7 @@ class RedisChannel extends be_cache_common_1.CacheChannel {
|
|
|
110
91
|
yield client.set(key, map[key]);
|
|
111
92
|
}
|
|
112
93
|
catch (e) {
|
|
113
|
-
|
|
94
|
+
conn.checkError(e, { name: 'SET', method: '$set' });
|
|
114
95
|
}
|
|
115
96
|
return 1;
|
|
116
97
|
default:
|
|
@@ -118,7 +99,7 @@ class RedisChannel extends be_cache_common_1.CacheChannel {
|
|
|
118
99
|
yield client.mSet(map);
|
|
119
100
|
}
|
|
120
101
|
catch (e) {
|
|
121
|
-
|
|
102
|
+
conn.checkError(e, { name: 'MSET', method: '$set' });
|
|
122
103
|
}
|
|
123
104
|
return keys.length;
|
|
124
105
|
}
|
|
@@ -127,7 +108,7 @@ class RedisChannel extends be_cache_common_1.CacheChannel {
|
|
|
127
108
|
/** @inheritDoc */
|
|
128
109
|
$delete(...paths) {
|
|
129
110
|
return __awaiter(this, void 0, void 0, function* () {
|
|
130
|
-
const { client } = this._props;
|
|
111
|
+
const { client, conn } = this._props;
|
|
131
112
|
if (!client) {
|
|
132
113
|
return 0;
|
|
133
114
|
}
|
|
@@ -138,7 +119,7 @@ class RedisChannel extends be_cache_common_1.CacheChannel {
|
|
|
138
119
|
yield client.del(paths);
|
|
139
120
|
}
|
|
140
121
|
catch (e) {
|
|
141
|
-
|
|
122
|
+
conn.checkError(e, { name: 'DEL', method: '$delete' });
|
|
142
123
|
}
|
|
143
124
|
return paths.length;
|
|
144
125
|
});
|
|
@@ -146,7 +127,7 @@ class RedisChannel extends be_cache_common_1.CacheChannel {
|
|
|
146
127
|
/** @inheritDoc */
|
|
147
128
|
$addLinks(idPath, paths) {
|
|
148
129
|
return __awaiter(this, void 0, void 0, function* () {
|
|
149
|
-
const { client } = this._props;
|
|
130
|
+
const { client, conn } = this._props;
|
|
150
131
|
if (!client) {
|
|
151
132
|
return 0;
|
|
152
133
|
}
|
|
@@ -157,7 +138,7 @@ class RedisChannel extends be_cache_common_1.CacheChannel {
|
|
|
157
138
|
yield client.sAdd(idPath, paths);
|
|
158
139
|
}
|
|
159
140
|
catch (e) {
|
|
160
|
-
|
|
141
|
+
conn.checkError(e, { name: 'SADD', method: '$addLinks' });
|
|
161
142
|
}
|
|
162
143
|
return paths.length;
|
|
163
144
|
});
|
|
@@ -165,7 +146,7 @@ class RedisChannel extends be_cache_common_1.CacheChannel {
|
|
|
165
146
|
/** @inheritDoc */
|
|
166
147
|
$expire(path, seconds) {
|
|
167
148
|
return __awaiter(this, void 0, void 0, function* () {
|
|
168
|
-
const { client } = this._props;
|
|
149
|
+
const { client, conn } = this._props;
|
|
169
150
|
if (!client) {
|
|
170
151
|
return false;
|
|
171
152
|
}
|
|
@@ -173,7 +154,7 @@ class RedisChannel extends be_cache_common_1.CacheChannel {
|
|
|
173
154
|
return (yield client.expire(path, seconds)) > 0;
|
|
174
155
|
}
|
|
175
156
|
catch (e) {
|
|
176
|
-
|
|
157
|
+
conn.checkError(e, { name: 'EXPIRE', method: '$expire' });
|
|
177
158
|
}
|
|
178
159
|
});
|
|
179
160
|
}
|
|
@@ -181,7 +162,7 @@ class RedisChannel extends be_cache_common_1.CacheChannel {
|
|
|
181
162
|
$getLinks(idPath) {
|
|
182
163
|
return __awaiter(this, void 0, void 0, function* () {
|
|
183
164
|
var _a;
|
|
184
|
-
const { client } = this._props;
|
|
165
|
+
const { client, conn } = this._props;
|
|
185
166
|
if (!client) {
|
|
186
167
|
return [];
|
|
187
168
|
}
|
|
@@ -189,7 +170,7 @@ class RedisChannel extends be_cache_common_1.CacheChannel {
|
|
|
189
170
|
return (_a = (yield client.sMembers(idPath))) !== null && _a !== void 0 ? _a : [];
|
|
190
171
|
}
|
|
191
172
|
catch (e) {
|
|
192
|
-
|
|
173
|
+
conn.checkError(e, { name: 'SMEMBERS', method: '$getLinks' });
|
|
193
174
|
}
|
|
194
175
|
});
|
|
195
176
|
}
|
|
@@ -24,6 +24,11 @@ export declare abstract class RedisConnection extends CacheConnection<RedisExecO
|
|
|
24
24
|
private static readonly TRY_COUNT;
|
|
25
25
|
/** {@inheritDoc} */
|
|
26
26
|
protected _props: RedisConnProps;
|
|
27
|
+
/**
|
|
28
|
+
* Constructor
|
|
29
|
+
*
|
|
30
|
+
* @param {RedisConnOpt} opt - options
|
|
31
|
+
* */
|
|
27
32
|
protected constructor(opt?: RedisConnOpt);
|
|
28
33
|
/** @inheritDoc */
|
|
29
34
|
get props(): Readonly<RedisConnProps>;
|
|
@@ -46,11 +46,17 @@ exports.RedisConnection = void 0;
|
|
|
46
46
|
const redis = __importStar(require("redis"));
|
|
47
47
|
const config_1 = require("../config");
|
|
48
48
|
const be_cache_common_1 = require("@samet-it/be-cache-common");
|
|
49
|
+
const be_base_common_1 = require("@samet-it/be-base-common");
|
|
49
50
|
/**
|
|
50
51
|
* Redis connection abstract class
|
|
51
52
|
* */
|
|
52
53
|
class RedisConnection extends be_cache_common_1.CacheConnection {
|
|
53
54
|
// endregion protected-property
|
|
55
|
+
/**
|
|
56
|
+
* Constructor
|
|
57
|
+
*
|
|
58
|
+
* @param {RedisConnOpt} opt - options
|
|
59
|
+
* */
|
|
54
60
|
constructor(opt) {
|
|
55
61
|
super(opt);
|
|
56
62
|
this._props.tryCount = 0;
|
|
@@ -122,7 +128,8 @@ class RedisConnection extends be_cache_common_1.CacheConnection {
|
|
|
122
128
|
return true;
|
|
123
129
|
}
|
|
124
130
|
if (this._props.tryCount > RedisConnection.TRY_COUNT) {
|
|
125
|
-
|
|
131
|
+
const err = new be_cache_common_1.CacheError('Maximum try county', { count: this._props.tryCount });
|
|
132
|
+
this.logger.error(be_base_common_1.errorHandler.common.logText(err, 'connect', 'try', this._props.tryCount));
|
|
126
133
|
return false;
|
|
127
134
|
}
|
|
128
135
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@samet-it/be-redis-common",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "Redis common component",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"redis",
|
|
@@ -67,10 +67,10 @@
|
|
|
67
67
|
}
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
|
-
"@leyyo/common": "^1.2.
|
|
70
|
+
"@leyyo/common": "^1.2.3",
|
|
71
71
|
"@leyyo/env": "^1.2.1",
|
|
72
|
-
"@samet-it/be-base-common": "^1.1.
|
|
73
|
-
"@samet-it/be-cache-common": "^1.1.
|
|
72
|
+
"@samet-it/be-base-common": "^1.1.3",
|
|
73
|
+
"@samet-it/be-cache-common": "^1.1.3",
|
|
74
74
|
"redis": "^5.10.0"
|
|
75
75
|
}
|
|
76
76
|
}
|