@samet-it/be-redis-common 1.1.1 → 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.
- package/dist/channel/index.types.d.ts +5 -1
- package/dist/channel/redis-direct.channel.d.ts +5 -1
- package/dist/channel/redis-direct.channel.js +4 -0
- package/dist/channel/redis.channel.d.ts +12 -3
- package/dist/channel/redis.channel.js +23 -24
- package/dist/connection/index.types.d.ts +5 -1
- package/dist/connection/redis-direct.connection.d.ts +1 -1
- package/dist/connection/redis.connection.d.ts +5 -0
- package/dist/connection/redis.connection.js +8 -1
- package/package.json +4 -4
|
@@ -5,8 +5,12 @@ import type { RedisClientType } from "redis";
|
|
|
5
5
|
import type { KeyValue } from "@leyyo/common";
|
|
6
6
|
/**
|
|
7
7
|
* Redis channel interface
|
|
8
|
+
*
|
|
9
|
+
* Generics:
|
|
10
|
+
* - 0-`ENT`: entity {@link Entity}
|
|
11
|
+
* - 1-`ID`: id type {@link KeyValue}
|
|
8
12
|
* */
|
|
9
|
-
export interface RedisChannelLike<
|
|
13
|
+
export interface RedisChannelLike<ENT extends Entity<ID>, ID extends KeyValue> extends CacheChannelLike<RedisConnectionLike, ENT, ID> {
|
|
10
14
|
/** @inheritDoc */
|
|
11
15
|
get props(): Readonly<RedisChannelProps>;
|
|
12
16
|
}
|
|
@@ -5,8 +5,12 @@ import type { RedisDirectChannelOpt } from "./index.types";
|
|
|
5
5
|
import type { KeyValue } from "@leyyo/common";
|
|
6
6
|
/**
|
|
7
7
|
* Redis direct channel class
|
|
8
|
+
*
|
|
9
|
+
* Generics:
|
|
10
|
+
* - 0-`ENT`: entity {@link Entity}
|
|
11
|
+
* - 1-`ID`: id type {@link KeyValue}
|
|
8
12
|
* */
|
|
9
|
-
export declare class RedisDirectChannel<
|
|
13
|
+
export declare class RedisDirectChannel<ENT extends Entity<ID>, ID extends KeyValue> extends RedisChannel<ENT, ID> {
|
|
10
14
|
/**
|
|
11
15
|
* Constructor
|
|
12
16
|
*
|
|
@@ -5,6 +5,10 @@ const redis_channel_1 = require("./redis.channel");
|
|
|
5
5
|
const be_base_common_1 = require("@samet-it/be-base-common");
|
|
6
6
|
/**
|
|
7
7
|
* Redis direct channel class
|
|
8
|
+
*
|
|
9
|
+
* Generics:
|
|
10
|
+
* - 0-`ENT`: entity {@link Entity}
|
|
11
|
+
* - 1-`ID`: id type {@link KeyValue}
|
|
8
12
|
* */
|
|
9
13
|
class RedisDirectChannel extends redis_channel_1.RedisChannel {
|
|
10
14
|
/**
|
|
@@ -2,15 +2,24 @@ 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
|
+
*
|
|
9
|
+
* Generics:
|
|
10
|
+
* - 0-`ENT`: entity {@link Entity}
|
|
11
|
+
* - 1-`ID`: id type {@link KeyValue}
|
|
8
12
|
* */
|
|
9
|
-
export declare abstract class RedisChannel<
|
|
13
|
+
export declare abstract class RedisChannel<ENT extends Entity<ID>, ID extends KeyValue> extends CacheChannel<RedisConnectionLike, ENT, ID> implements RedisChannelLike<ENT, ID> {
|
|
10
14
|
/** @inheritDoc */
|
|
11
15
|
protected _props: RedisChannelProps;
|
|
16
|
+
/**
|
|
17
|
+
* Constructor
|
|
18
|
+
*
|
|
19
|
+
* @param {RedisConnectionLike} conn - redis connection
|
|
20
|
+
* @param {RedisChannelOpt} opt - options
|
|
21
|
+
* */
|
|
12
22
|
protected constructor(conn: RedisConnectionLike, opt?: RedisChannelOpt);
|
|
13
|
-
protected _checkError(e: Error, opt?: Opt): void;
|
|
14
23
|
/** @inheritDoc */
|
|
15
24
|
get props(): Readonly<RedisChannelProps>;
|
|
16
25
|
/** @inheritDoc */
|
|
@@ -10,14 +10,23 @@ 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
|
/**
|
|
17
16
|
* Redis abstract channel class
|
|
17
|
+
*
|
|
18
|
+
* Generics:
|
|
19
|
+
* - 0-`ENT`: entity {@link Entity}
|
|
20
|
+
* - 1-`ID`: id type {@link KeyValue}
|
|
18
21
|
* */
|
|
19
22
|
class RedisChannel extends be_cache_common_1.CacheChannel {
|
|
20
23
|
// endregion protected-property
|
|
24
|
+
/**
|
|
25
|
+
* Constructor
|
|
26
|
+
*
|
|
27
|
+
* @param {RedisConnectionLike} conn - redis connection
|
|
28
|
+
* @param {RedisChannelOpt} opt - options
|
|
29
|
+
* */
|
|
21
30
|
constructor(conn, opt) {
|
|
22
31
|
super(conn, opt);
|
|
23
32
|
conn.onFirstConnected(() => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -33,16 +42,6 @@ class RedisChannel extends be_cache_common_1.CacheChannel {
|
|
|
33
42
|
this._props.isConnected = false;
|
|
34
43
|
}));
|
|
35
44
|
}
|
|
36
|
-
_checkError(e, opt) {
|
|
37
|
-
be_base_common_1.errorHandler.addStat(e);
|
|
38
|
-
if (e instanceof be_cache_common_1.CacheError) {
|
|
39
|
-
// todo append params
|
|
40
|
-
throw e;
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
throw be_base_common_1.errorHandler.common.castForClass(be_cache_common_1.CacheError, e, opt);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
45
|
// region getter
|
|
47
46
|
/** @inheritDoc */
|
|
48
47
|
get props() {
|
|
@@ -53,7 +52,7 @@ class RedisChannel extends be_cache_common_1.CacheChannel {
|
|
|
53
52
|
/** @inheritDoc */
|
|
54
53
|
$get(...paths) {
|
|
55
54
|
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
-
const { client } = this._props;
|
|
55
|
+
const { client, conn } = this._props;
|
|
57
56
|
if (!client) {
|
|
58
57
|
return [];
|
|
59
58
|
}
|
|
@@ -68,14 +67,14 @@ class RedisChannel extends be_cache_common_1.CacheChannel {
|
|
|
68
67
|
return (yield client.mGet(paths));
|
|
69
68
|
}
|
|
70
69
|
catch (e) {
|
|
71
|
-
|
|
70
|
+
conn.checkError(e, { name: 'MGET', method: '$get' });
|
|
72
71
|
}
|
|
73
72
|
});
|
|
74
73
|
}
|
|
75
74
|
/** @inheritDoc */
|
|
76
75
|
$set(map) {
|
|
77
76
|
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
-
const { client } = this._props;
|
|
77
|
+
const { client, conn } = this._props;
|
|
79
78
|
if (!client) {
|
|
80
79
|
return 0;
|
|
81
80
|
}
|
|
@@ -92,7 +91,7 @@ class RedisChannel extends be_cache_common_1.CacheChannel {
|
|
|
92
91
|
yield client.set(key, map[key]);
|
|
93
92
|
}
|
|
94
93
|
catch (e) {
|
|
95
|
-
|
|
94
|
+
conn.checkError(e, { name: 'SET', method: '$set' });
|
|
96
95
|
}
|
|
97
96
|
return 1;
|
|
98
97
|
default:
|
|
@@ -100,7 +99,7 @@ class RedisChannel extends be_cache_common_1.CacheChannel {
|
|
|
100
99
|
yield client.mSet(map);
|
|
101
100
|
}
|
|
102
101
|
catch (e) {
|
|
103
|
-
|
|
102
|
+
conn.checkError(e, { name: 'MSET', method: '$set' });
|
|
104
103
|
}
|
|
105
104
|
return keys.length;
|
|
106
105
|
}
|
|
@@ -109,7 +108,7 @@ class RedisChannel extends be_cache_common_1.CacheChannel {
|
|
|
109
108
|
/** @inheritDoc */
|
|
110
109
|
$delete(...paths) {
|
|
111
110
|
return __awaiter(this, void 0, void 0, function* () {
|
|
112
|
-
const { client } = this._props;
|
|
111
|
+
const { client, conn } = this._props;
|
|
113
112
|
if (!client) {
|
|
114
113
|
return 0;
|
|
115
114
|
}
|
|
@@ -120,7 +119,7 @@ class RedisChannel extends be_cache_common_1.CacheChannel {
|
|
|
120
119
|
yield client.del(paths);
|
|
121
120
|
}
|
|
122
121
|
catch (e) {
|
|
123
|
-
|
|
122
|
+
conn.checkError(e, { name: 'DEL', method: '$delete' });
|
|
124
123
|
}
|
|
125
124
|
return paths.length;
|
|
126
125
|
});
|
|
@@ -128,7 +127,7 @@ class RedisChannel extends be_cache_common_1.CacheChannel {
|
|
|
128
127
|
/** @inheritDoc */
|
|
129
128
|
$addLinks(idPath, paths) {
|
|
130
129
|
return __awaiter(this, void 0, void 0, function* () {
|
|
131
|
-
const { client } = this._props;
|
|
130
|
+
const { client, conn } = this._props;
|
|
132
131
|
if (!client) {
|
|
133
132
|
return 0;
|
|
134
133
|
}
|
|
@@ -139,7 +138,7 @@ class RedisChannel extends be_cache_common_1.CacheChannel {
|
|
|
139
138
|
yield client.sAdd(idPath, paths);
|
|
140
139
|
}
|
|
141
140
|
catch (e) {
|
|
142
|
-
|
|
141
|
+
conn.checkError(e, { name: 'SADD', method: '$addLinks' });
|
|
143
142
|
}
|
|
144
143
|
return paths.length;
|
|
145
144
|
});
|
|
@@ -147,7 +146,7 @@ class RedisChannel extends be_cache_common_1.CacheChannel {
|
|
|
147
146
|
/** @inheritDoc */
|
|
148
147
|
$expire(path, seconds) {
|
|
149
148
|
return __awaiter(this, void 0, void 0, function* () {
|
|
150
|
-
const { client } = this._props;
|
|
149
|
+
const { client, conn } = this._props;
|
|
151
150
|
if (!client) {
|
|
152
151
|
return false;
|
|
153
152
|
}
|
|
@@ -155,7 +154,7 @@ class RedisChannel extends be_cache_common_1.CacheChannel {
|
|
|
155
154
|
return (yield client.expire(path, seconds)) > 0;
|
|
156
155
|
}
|
|
157
156
|
catch (e) {
|
|
158
|
-
|
|
157
|
+
conn.checkError(e, { name: 'EXPIRE', method: '$expire' });
|
|
159
158
|
}
|
|
160
159
|
});
|
|
161
160
|
}
|
|
@@ -163,7 +162,7 @@ class RedisChannel extends be_cache_common_1.CacheChannel {
|
|
|
163
162
|
$getLinks(idPath) {
|
|
164
163
|
return __awaiter(this, void 0, void 0, function* () {
|
|
165
164
|
var _a;
|
|
166
|
-
const { client } = this._props;
|
|
165
|
+
const { client, conn } = this._props;
|
|
167
166
|
if (!client) {
|
|
168
167
|
return [];
|
|
169
168
|
}
|
|
@@ -171,7 +170,7 @@ class RedisChannel extends be_cache_common_1.CacheChannel {
|
|
|
171
170
|
return (_a = (yield client.sMembers(idPath))) !== null && _a !== void 0 ? _a : [];
|
|
172
171
|
}
|
|
173
172
|
catch (e) {
|
|
174
|
-
|
|
173
|
+
conn.checkError(e, { name: 'SMEMBERS', method: '$getLinks' });
|
|
175
174
|
}
|
|
176
175
|
});
|
|
177
176
|
}
|
|
@@ -18,10 +18,14 @@ export interface RedisDirectConnectionLike extends RedisConnectionLike {
|
|
|
18
18
|
/**
|
|
19
19
|
* Create new channel
|
|
20
20
|
*
|
|
21
|
+
* Generics:
|
|
22
|
+
* - 0-`ENT`: entity {@link Entity}
|
|
23
|
+
* - 1-`ID`: id type {@link KeyValue}
|
|
24
|
+
*
|
|
21
25
|
* @param {RedisDirectChannelOpt?} opt - direct channel options
|
|
22
26
|
* @return {RedisChannelLike<Entity>} - new channel
|
|
23
27
|
* */
|
|
24
|
-
newChannel<
|
|
28
|
+
newChannel<ENT extends Entity<ID>, ID extends KeyValue>(opt?: RedisDirectChannelOpt): RedisChannelLike<ENT, ID>;
|
|
25
29
|
}
|
|
26
30
|
/**
|
|
27
31
|
* Redis connection option
|
|
@@ -14,5 +14,5 @@ export declare class RedisDirectConnection extends RedisConnection implements Re
|
|
|
14
14
|
* */
|
|
15
15
|
constructor(opt?: RedisConnDirectOpt);
|
|
16
16
|
/** @inheritDoc */
|
|
17
|
-
newChannel<
|
|
17
|
+
newChannel<ENT extends Entity<ID>, ID extends KeyValue>(opt?: RedisDirectChannelOpt): RedisChannelLike<ENT, ID>;
|
|
18
18
|
}
|
|
@@ -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
|
}
|