@samet-it/be-redis-common 1.1.4 → 1.1.6

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.
@@ -3,6 +3,7 @@ import type { RedisChannelProps, RedisChannelLike, RedisChannelOpt } from "./ind
3
3
  import { type Entity } from "@samet-it/be-base-common";
4
4
  import { CacheChannel } from "@samet-it/be-cache-common";
5
5
  import type { KeyValue } from "@leyyo/common";
6
+ import type { CacheExecOpt } from "@samet-it/be-cache-common/dist/connection";
6
7
  /**
7
8
  * Redis abstract channel class
8
9
  *
@@ -10,7 +11,7 @@ import type { KeyValue } from "@leyyo/common";
10
11
  * - 0-`ENT`: entity {@link Entity}
11
12
  * - 1-`ID`: id type {@link KeyValue}
12
13
  * */
13
- export declare abstract class RedisChannel<ENT extends Entity<ID>, ID extends KeyValue> extends CacheChannel<RedisConnectionLike, ENT, ID> implements RedisChannelLike<ENT, ID> {
14
+ export declare class RedisChannel<ENT extends Entity<ID>, ID extends KeyValue> extends CacheChannel<RedisConnectionLike, ENT, ID> implements RedisChannelLike<ENT, ID> {
14
15
  /** @inheritDoc */
15
16
  protected _props: RedisChannelProps;
16
17
  /**
@@ -23,15 +24,21 @@ export declare abstract class RedisChannel<ENT extends Entity<ID>, ID extends Ke
23
24
  /** @inheritDoc */
24
25
  get props(): Readonly<RedisChannelProps>;
25
26
  /** @inheritDoc */
26
- $get(...paths: Array<string>): Promise<Array<string>>;
27
+ $get(path: string, _opt?: CacheExecOpt): Promise<string | undefined>;
27
28
  /** @inheritDoc */
28
- $set(map: Record<string, string>): Promise<number>;
29
+ $getMore(paths: Array<string>, _opt?: CacheExecOpt): Promise<Array<string | undefined>>;
29
30
  /** @inheritDoc */
30
- $delete(...paths: string[]): Promise<number>;
31
+ $set(path: string, value: string, _opt?: CacheExecOpt): Promise<boolean>;
31
32
  /** @inheritDoc */
32
- $addLinks(idPath: string, paths: string): Promise<number>;
33
+ $setMore(map: Record<string, string>, _opt?: CacheExecOpt): Promise<number>;
33
34
  /** @inheritDoc */
34
- $expire(path: string, seconds: number): Promise<boolean>;
35
+ $delete(path: string, _opt?: CacheExecOpt): Promise<boolean>;
35
36
  /** @inheritDoc */
36
- $getLinks(idPath: string): Promise<Array<string>>;
37
+ $deleteMore(paths: string[], _opt?: CacheExecOpt): Promise<number>;
38
+ /** @inheritDoc */
39
+ $addLinks(idPath: string, paths: Array<string>, _opt?: CacheExecOpt): Promise<number>;
40
+ /** @inheritDoc */
41
+ $expire(path: string, seconds: number, _opt?: CacheExecOpt): Promise<boolean>;
42
+ /** @inheritDoc */
43
+ $getLinks(idPath: string, _opt?: CacheExecOpt): Promise<Array<string>>;
37
44
  }
@@ -50,7 +50,26 @@ class RedisChannel extends be_cache_common_1.CacheChannel {
50
50
  // endregion getter
51
51
  // region native-calls
52
52
  /** @inheritDoc */
53
- $get(...paths) {
53
+ $get(path, _opt) {
54
+ return __awaiter(this, void 0, void 0, function* () {
55
+ const { client, conn } = this._props;
56
+ if (!client) {
57
+ return undefined;
58
+ }
59
+ if (typeof path !== 'string') {
60
+ return undefined;
61
+ }
62
+ try {
63
+ return yield client.get(path);
64
+ }
65
+ catch (e) {
66
+ conn.checkError(e, { name: 'GET', method: '$get' });
67
+ }
68
+ return undefined;
69
+ });
70
+ }
71
+ /** @inheritDoc */
72
+ $getMore(paths, _opt) {
54
73
  return __awaiter(this, void 0, void 0, function* () {
55
74
  const { client, conn } = this._props;
56
75
  if (!client) {
@@ -60,19 +79,46 @@ class RedisChannel extends be_cache_common_1.CacheChannel {
60
79
  return [];
61
80
  }
62
81
  if (paths.length == 1) {
63
- const rec = (yield client.get(paths[0]));
64
- return rec ? [rec] : [];
82
+ try {
83
+ const rec = (yield client.get(paths[0]));
84
+ return rec ? [rec] : [];
85
+ }
86
+ catch (e) {
87
+ conn.checkError(e, { name: 'GET', method: '$getMore' });
88
+ return [];
89
+ }
65
90
  }
66
91
  try {
67
92
  return (yield client.mGet(paths));
68
93
  }
69
94
  catch (e) {
70
- conn.checkError(e, { name: 'MGET', method: '$get' });
95
+ conn.checkError(e, { name: 'MGET', method: '$getMore' });
96
+ return [];
71
97
  }
72
98
  });
73
99
  }
74
100
  /** @inheritDoc */
75
- $set(map) {
101
+ $set(path, value, _opt) {
102
+ return __awaiter(this, void 0, void 0, function* () {
103
+ const { client, conn } = this._props;
104
+ if (!client) {
105
+ return false;
106
+ }
107
+ if (typeof path !== 'string' || typeof value !== 'string') {
108
+ return false;
109
+ }
110
+ try {
111
+ yield client.set(path, value);
112
+ return true;
113
+ }
114
+ catch (e) {
115
+ conn.checkError(e, { name: 'SET', method: '$set' });
116
+ }
117
+ return false;
118
+ });
119
+ }
120
+ /** @inheritDoc */
121
+ $setMore(map, _opt) {
76
122
  return __awaiter(this, void 0, void 0, function* () {
77
123
  const { client, conn } = this._props;
78
124
  if (!client) {
@@ -91,7 +137,7 @@ class RedisChannel extends be_cache_common_1.CacheChannel {
91
137
  yield client.set(key, map[key]);
92
138
  }
93
139
  catch (e) {
94
- conn.checkError(e, { name: 'SET', method: '$set' });
140
+ conn.checkError(e, { name: 'SET', method: '$setMore' });
95
141
  }
96
142
  return 1;
97
143
  default:
@@ -99,14 +145,34 @@ class RedisChannel extends be_cache_common_1.CacheChannel {
99
145
  yield client.mSet(map);
100
146
  }
101
147
  catch (e) {
102
- conn.checkError(e, { name: 'MSET', method: '$set' });
148
+ conn.checkError(e, { name: 'MSET', method: '$setMore' });
103
149
  }
104
150
  return keys.length;
105
151
  }
106
152
  });
107
153
  }
108
154
  /** @inheritDoc */
109
- $delete(...paths) {
155
+ $delete(path, _opt) {
156
+ return __awaiter(this, void 0, void 0, function* () {
157
+ const { client, conn } = this._props;
158
+ if (!client) {
159
+ return false;
160
+ }
161
+ if (typeof path !== 'string') {
162
+ return false;
163
+ }
164
+ try {
165
+ const result = yield client.del(path);
166
+ return result > 0;
167
+ }
168
+ catch (e) {
169
+ conn.checkError(e, { name: 'DEL', method: '$delete' });
170
+ }
171
+ return false;
172
+ });
173
+ }
174
+ /** @inheritDoc */
175
+ $deleteMore(paths, _opt) {
110
176
  return __awaiter(this, void 0, void 0, function* () {
111
177
  const { client, conn } = this._props;
112
178
  if (!client) {
@@ -119,13 +185,13 @@ class RedisChannel extends be_cache_common_1.CacheChannel {
119
185
  yield client.del(paths);
120
186
  }
121
187
  catch (e) {
122
- conn.checkError(e, { name: 'DEL', method: '$delete' });
188
+ conn.checkError(e, { name: 'DEL', method: '$deleteMore' });
123
189
  }
124
190
  return paths.length;
125
191
  });
126
192
  }
127
193
  /** @inheritDoc */
128
- $addLinks(idPath, paths) {
194
+ $addLinks(idPath, paths, _opt) {
129
195
  return __awaiter(this, void 0, void 0, function* () {
130
196
  const { client, conn } = this._props;
131
197
  if (!client) {
@@ -144,7 +210,7 @@ class RedisChannel extends be_cache_common_1.CacheChannel {
144
210
  });
145
211
  }
146
212
  /** @inheritDoc */
147
- $expire(path, seconds) {
213
+ $expire(path, seconds, _opt) {
148
214
  return __awaiter(this, void 0, void 0, function* () {
149
215
  const { client, conn } = this._props;
150
216
  if (!client) {
@@ -159,7 +225,7 @@ class RedisChannel extends be_cache_common_1.CacheChannel {
159
225
  });
160
226
  }
161
227
  /** @inheritDoc */
162
- $getLinks(idPath) {
228
+ $getLinks(idPath, _opt) {
163
229
  return __awaiter(this, void 0, void 0, function* () {
164
230
  var _a;
165
231
  const { client, conn } = this._props;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@samet-it/be-redis-common",
3
- "version": "1.1.4",
3
+ "version": "1.1.6",
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.3",
70
+ "@leyyo/common": "^1.2.4",
71
71
  "@leyyo/env": "^1.2.5",
72
- "@samet-it/be-base-common": "^1.1.3",
73
- "@samet-it/be-cache-common": "^1.1.4",
72
+ "@samet-it/be-base-common": "^1.1.4",
73
+ "@samet-it/be-cache-common": "^1.1.6",
74
74
  "redis": "^5.10.0"
75
75
  }
76
76
  }