@maiyunnet/kebab 2.0.6 → 2.0.8
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/index.d.ts +11 -1
- package/index.js +13 -1
- package/lib/buffer.d.ts +25 -0
- package/lib/buffer.js +30 -5
- package/lib/captcha.d.ts +15 -0
- package/lib/captcha.js +20 -0
- package/lib/consistent.d.ts +51 -0
- package/lib/consistent.js +59 -0
- package/lib/core.d.ts +134 -0
- package/lib/core.js +176 -0
- package/lib/crypto.d.ts +75 -6
- package/lib/crypto.js +206 -38
- package/lib/db.d.ts +104 -0
- package/lib/db.js +126 -0
- package/lib/dns.d.ts +51 -0
- package/lib/dns.js +54 -2
- package/lib/fs.d.ts +100 -0
- package/lib/fs.js +118 -0
- package/lib/jwt.d.ts +43 -0
- package/lib/jwt.js +45 -0
- package/lib/kv.d.ts +362 -0
- package/lib/kv.js +377 -0
- package/lib/lan.d.ts +6 -0
- package/lib/lan.js +7 -0
- package/lib/net/formdata.d.ts +38 -0
- package/lib/net/formdata.js +43 -0
- package/lib/net/request.d.ts +62 -0
- package/lib/net/request.js +57 -0
- package/lib/net/response.d.ts +21 -0
- package/lib/net/response.js +16 -0
- package/lib/net.d.ts +86 -0
- package/lib/net.js +140 -0
- package/lib/s3.d.ts +52 -0
- package/lib/s3.js +51 -0
- package/lib/scan.d.ts +52 -0
- package/lib/scan.js +84 -0
- package/lib/session.d.ts +31 -0
- package/lib/session.js +52 -1
- package/lib/sql.d.ts +176 -0
- package/lib/sql.js +287 -2
- package/lib/ssh/sftp.d.ts +106 -0
- package/lib/ssh/sftp.js +106 -0
- package/lib/ssh/shell.d.ts +37 -0
- package/lib/ssh/shell.js +31 -0
- package/lib/ssh.d.ts +32 -0
- package/lib/ssh.js +32 -0
- package/lib/text.d.ts +131 -0
- package/lib/text.js +188 -0
- package/lib/time.d.ts +53 -0
- package/lib/time.js +55 -0
- package/lib/ws.d.ts +68 -0
- package/lib/ws.js +74 -0
- package/lib/zip.d.ts +53 -0
- package/lib/zip.js +73 -0
- package/lib/zlib.d.ts +76 -0
- package/lib/zlib.js +78 -0
- package/main.d.ts +6 -1
- package/main.js +11 -1
- package/package.json +2 -2
- package/sys/child.js +104 -0
- package/sys/cmd.js +28 -0
- package/sys/ctr.d.ts +166 -0
- package/sys/ctr.js +177 -0
- package/sys/master.js +63 -0
- package/sys/mod.d.ts +266 -0
- package/sys/mod.js +335 -0
- package/sys/route.d.ts +34 -0
- package/sys/route.js +164 -0
- package/www/example/ctr/test.d.ts +3 -0
- package/www/example/ctr/test.js +63 -1
- package/www/example/mod/test.js +14 -0
- package/www/example/mod/testdata.js +9 -0
- package/www/example/ws/test.js +1 -0
- package/.VSCodeCounter/2025-02-14_14-46-44/details.md +0 -82
- package/.VSCodeCounter/2025-02-14_14-46-44/diff-details.md +0 -15
- package/.VSCodeCounter/2025-02-14_14-46-44/diff.csv +0 -2
- package/.VSCodeCounter/2025-02-14_14-46-44/diff.md +0 -19
- package/.VSCodeCounter/2025-02-14_14-46-44/diff.txt +0 -22
- package/.VSCodeCounter/2025-02-14_14-46-44/results.csv +0 -69
- package/.VSCodeCounter/2025-02-14_14-46-44/results.json +0 -1
- package/.VSCodeCounter/2025-02-14_14-46-44/results.md +0 -48
- package/.VSCodeCounter/2025-02-14_14-46-44/results.txt +0 -118
- package/.vscode/tasks.json +0 -15
package/lib/jwt.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Project: Kebab, User: JianSuoQiYue
|
|
4
|
+
* Date: 2023-1-31 20:34:47
|
|
5
|
+
* Last: 2023-1-31 20:34:47, 2023-12-8 13:55:09
|
|
6
|
+
*/
|
|
2
7
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
8
|
if (k2 === undefined) k2 = k;
|
|
4
9
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -38,11 +43,19 @@ exports.getOrigin = getOrigin;
|
|
|
38
43
|
exports.decode = decode;
|
|
39
44
|
exports.block = block;
|
|
40
45
|
exports.get = get;
|
|
46
|
+
// --- 库和定义 ---
|
|
41
47
|
const lCore = __importStar(require("../lib/core"));
|
|
42
48
|
const lTime = __importStar(require("../lib/time"));
|
|
43
49
|
const lText = __importStar(require("../lib/text"));
|
|
44
50
|
const lCrypto = __importStar(require("../lib/crypto"));
|
|
45
51
|
class Jwt {
|
|
52
|
+
/**
|
|
53
|
+
* --- 初始化函数,相当于 construct ---
|
|
54
|
+
* @param ctr 模型实例
|
|
55
|
+
* @param link Kv 或 Db 实例
|
|
56
|
+
* @param auth 设为 true 则优先从头 Authorization 或 post _auth 值读取 token
|
|
57
|
+
* @param opt 选项
|
|
58
|
+
*/
|
|
46
59
|
async init(ctr, opt = {}, link) {
|
|
47
60
|
const config = ctr.getPrototype('_config');
|
|
48
61
|
this._ctr = ctr;
|
|
@@ -69,6 +82,7 @@ class Jwt {
|
|
|
69
82
|
}
|
|
70
83
|
const data = await decode(this._ctr, jwt, this._link, this._name, this._secret);
|
|
71
84
|
if (!data) {
|
|
85
|
+
// --- 清除 cookie ---
|
|
72
86
|
const cookie = this._ctr.getPrototype('_cookie');
|
|
73
87
|
if (cookie[this._name]) {
|
|
74
88
|
delete cookie[this._name];
|
|
@@ -78,12 +92,16 @@ class Jwt {
|
|
|
78
92
|
this._ctr.setPrototype('_jwt', data);
|
|
79
93
|
return true;
|
|
80
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* --- 将 _jwt 数据封装并返回(创建新的或者续期老的 token),默认会同时设置一个 cookie(data 值会自动设置 token、exp) ---
|
|
97
|
+
*/
|
|
81
98
|
renew() {
|
|
82
99
|
const time = lTime.stamp();
|
|
83
100
|
const data = this._ctr.getPrototype('_jwt');
|
|
84
101
|
const token = data['token'] ? data['token'] : lCore.random(16, lCore.RANDOM_LUN);
|
|
85
102
|
data['exp'] = time + this._ttl;
|
|
86
103
|
data['token'] = token;
|
|
104
|
+
// --- 拼装 ---
|
|
87
105
|
const header = lCrypto.base64Encode(lText.stringifyJson({
|
|
88
106
|
'alg': 'HS256',
|
|
89
107
|
'typ': 'JWT'
|
|
@@ -99,6 +117,9 @@ class Jwt {
|
|
|
99
117
|
}
|
|
100
118
|
return jwt;
|
|
101
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* --- 清除 cookie,仅仅清除 cookie,jwt 并不会失效 ---
|
|
122
|
+
*/
|
|
102
123
|
clearCookie() {
|
|
103
124
|
if (this._auth) {
|
|
104
125
|
return;
|
|
@@ -108,6 +129,9 @@ class Jwt {
|
|
|
108
129
|
'ssl': this._ssl
|
|
109
130
|
});
|
|
110
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* --- 销毁 jwt,其实就是将 token block 信息写入 redis,如果没有 redis 则不能销毁,返回数组代表销毁成功的 token 和原 exp,否则失败返回 false ---
|
|
134
|
+
*/
|
|
111
135
|
async destory() {
|
|
112
136
|
if (!this._link) {
|
|
113
137
|
return false;
|
|
@@ -136,6 +160,9 @@ class Jwt {
|
|
|
136
160
|
}
|
|
137
161
|
}
|
|
138
162
|
exports.Jwt = Jwt;
|
|
163
|
+
/**
|
|
164
|
+
* --- 获取 jwt 原始字符串,不保证有效 ---
|
|
165
|
+
*/
|
|
139
166
|
function getOrigin(ctr, name = '', auth = false) {
|
|
140
167
|
if (!name) {
|
|
141
168
|
name = ctr.getPrototype('_config').jwt.name;
|
|
@@ -157,6 +184,10 @@ function getOrigin(ctr, name = '', auth = false) {
|
|
|
157
184
|
}
|
|
158
185
|
return jwt;
|
|
159
186
|
}
|
|
187
|
+
/**
|
|
188
|
+
* --- decode ---
|
|
189
|
+
* 不传入 link 的话,将不做 block 有效校验,只做本身的 exp 有效校验
|
|
190
|
+
*/
|
|
160
191
|
async function decode(ctr, val, link, name = '', secret = '') {
|
|
161
192
|
if (!val) {
|
|
162
193
|
return false;
|
|
@@ -172,6 +203,8 @@ async function decode(ctr, val, link, name = '', secret = '') {
|
|
|
172
203
|
if (!jwtArray[2]) {
|
|
173
204
|
return false;
|
|
174
205
|
}
|
|
206
|
+
// jwtArray[1]: payload, jwtArray[2]: signature
|
|
207
|
+
// --- 判断是否合法 ---
|
|
175
208
|
const nsignature = lCrypto.hashHmac('sha256', jwtArray[0] + '.' + jwtArray[1], secret, 'base64');
|
|
176
209
|
if (nsignature !== jwtArray[2]) {
|
|
177
210
|
return false;
|
|
@@ -185,16 +218,20 @@ async function decode(ctr, val, link, name = '', secret = '') {
|
|
|
185
218
|
if (!data) {
|
|
186
219
|
return false;
|
|
187
220
|
}
|
|
221
|
+
// --- 检测 token ---
|
|
188
222
|
if (!data['token']) {
|
|
189
223
|
return false;
|
|
190
224
|
}
|
|
225
|
+
// --- 检测 exp ---
|
|
191
226
|
if (!data['exp']) {
|
|
192
227
|
return false;
|
|
193
228
|
}
|
|
194
229
|
const time = lTime.stamp();
|
|
195
230
|
if (data['exp'] < time) {
|
|
231
|
+
// --- 过期 ---
|
|
196
232
|
return false;
|
|
197
233
|
}
|
|
234
|
+
// --- 检测 token 是否有效 ---
|
|
198
235
|
if (!link || !await link.get(name + '_block_' + data['token'])) {
|
|
199
236
|
return data;
|
|
200
237
|
}
|
|
@@ -204,6 +241,9 @@ async function decode(ctr, val, link, name = '', secret = '') {
|
|
|
204
241
|
return false;
|
|
205
242
|
}
|
|
206
243
|
}
|
|
244
|
+
/**
|
|
245
|
+
* --- 仅往 redis 写禁止相关 token 的数据,一般用于异步通知时在异处的服务器来调用的 ---
|
|
246
|
+
*/
|
|
207
247
|
async function block(ctr, token, exp, link, name = '') {
|
|
208
248
|
const time = lTime.stamp();
|
|
209
249
|
if (!name) {
|
|
@@ -216,6 +256,11 @@ async function block(ctr, token, exp, link, name = '') {
|
|
|
216
256
|
await link.set(name + '_block_' + token, '1', ttl + 1);
|
|
217
257
|
return true;
|
|
218
258
|
}
|
|
259
|
+
/**
|
|
260
|
+
* @param ctr 模型实例
|
|
261
|
+
* @param opt name, ttl, ssl, secret, auth: false, true 则优先从头 Authorization 或 post _auth 值读取 token
|
|
262
|
+
* @param link 实例
|
|
263
|
+
*/
|
|
219
264
|
async function get(ctr, opt = {}, link) {
|
|
220
265
|
const jwt = new Jwt();
|
|
221
266
|
await jwt.init(ctr, opt, link);
|
package/lib/kv.d.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Project: Kebab, User: JianSuoQiYue
|
|
3
|
+
* Date: 2019-5-30 19:25:22
|
|
4
|
+
* Last: 2020-3-28 18:54:04, 2022-09-12 23:24:45, 2022-09-22 01:06:22, 2024-2-21 13:32:56, 2024-8-21 16:59:57
|
|
5
|
+
*/
|
|
1
6
|
import * as redis from '@litert/redis';
|
|
2
7
|
import * as ctr from '../sys/ctr';
|
|
3
8
|
import * as types from '../types';
|
|
9
|
+
/** --- 连接信息 --- */
|
|
4
10
|
export interface IConnectionInfo {
|
|
5
11
|
'id': number;
|
|
6
12
|
'last': number;
|
|
@@ -10,37 +16,181 @@ export interface IConnectionInfo {
|
|
|
10
16
|
'lost': boolean;
|
|
11
17
|
}
|
|
12
18
|
export declare class Pool {
|
|
19
|
+
/** --- 当前 Pool 对象的 kv 连接信息 --- */
|
|
13
20
|
private readonly _etc;
|
|
14
21
|
constructor(ctr: ctr.Ctr, etc?: types.IConfigKv);
|
|
22
|
+
/**
|
|
23
|
+
* --- 设定一个值 ---
|
|
24
|
+
* @param key
|
|
25
|
+
* @param val
|
|
26
|
+
* @param ttl 秒,0 为不限制
|
|
27
|
+
* @param mod 设置模式: 空,nx(key不存在才建立),xx(key存在才修改)
|
|
28
|
+
*/
|
|
15
29
|
set(key: string, val: object | string | number, ttl?: number, mod?: '' | 'nx' | 'xx'): Promise<boolean>;
|
|
30
|
+
/**
|
|
31
|
+
* --- 添加一个值,存在则不变 ---
|
|
32
|
+
* @param key
|
|
33
|
+
* @param val
|
|
34
|
+
* @param ttl 秒,0 为不限制
|
|
35
|
+
*/
|
|
16
36
|
add(key: string, val: object | string | number, ttl?: number): Promise<boolean>;
|
|
37
|
+
/**
|
|
38
|
+
* --- 替换一个存在的值 ---
|
|
39
|
+
* @param key
|
|
40
|
+
* @param val
|
|
41
|
+
* @param ttl 秒,0 为不限制
|
|
42
|
+
*/
|
|
17
43
|
replace(key: string, val: object | string | number, ttl?: number): Promise<boolean>;
|
|
44
|
+
/**
|
|
45
|
+
* --- 向已存在的值后追加数据 ---
|
|
46
|
+
* @param key
|
|
47
|
+
* @param val
|
|
48
|
+
*/
|
|
18
49
|
append(key: string, val: string): Promise<boolean>;
|
|
50
|
+
/**
|
|
51
|
+
* --- 向已存在的值之前追加数据 ---
|
|
52
|
+
* @param key
|
|
53
|
+
* @param val
|
|
54
|
+
*/
|
|
19
55
|
prepend(key: string, val: string): Promise<boolean>;
|
|
56
|
+
/**
|
|
57
|
+
* --- 检测 key 是否存在 ---
|
|
58
|
+
* @param keys
|
|
59
|
+
*/
|
|
20
60
|
exists(keys: string | string[]): Promise<number>;
|
|
61
|
+
/**
|
|
62
|
+
* --- 获取字符串 ---
|
|
63
|
+
* @param key
|
|
64
|
+
*/
|
|
21
65
|
get(key: string): Promise<string | null>;
|
|
66
|
+
/**
|
|
67
|
+
* --- 获取相应的剩余有效期秒数 ---
|
|
68
|
+
* @param key
|
|
69
|
+
*/
|
|
22
70
|
ttl(key: string): Promise<number | null>;
|
|
71
|
+
/**
|
|
72
|
+
* --- 获取相应的剩余有效期毫秒数 ---
|
|
73
|
+
* @param key
|
|
74
|
+
*/
|
|
23
75
|
pttl(key: string): Promise<number | null>;
|
|
76
|
+
/**
|
|
77
|
+
* --- 批量获取值 ---
|
|
78
|
+
* @param keys key 序列
|
|
79
|
+
*/
|
|
24
80
|
mSet(rows: Record<string, string | Buffer>): Promise<boolean>;
|
|
81
|
+
/**
|
|
82
|
+
* --- 批量获取值 ---
|
|
83
|
+
* @param keys key 序列
|
|
84
|
+
*/
|
|
25
85
|
mGet(keys: string[]): Promise<Record<string, string | null>>;
|
|
86
|
+
/**
|
|
87
|
+
* --- 获取 json 对象 ---
|
|
88
|
+
* @param key
|
|
89
|
+
*/
|
|
26
90
|
getJson(key: string): Promise<any | null>;
|
|
91
|
+
/**
|
|
92
|
+
* --- 删除已存在的值 ---
|
|
93
|
+
* @param keys
|
|
94
|
+
*/
|
|
27
95
|
del(keys: string | string[]): Promise<boolean>;
|
|
96
|
+
/**
|
|
97
|
+
* --- 自增 ---
|
|
98
|
+
* @param key
|
|
99
|
+
* @param num 整数或浮点正数
|
|
100
|
+
*/
|
|
28
101
|
incr(key: string, num?: number): Promise<number | false>;
|
|
102
|
+
/**
|
|
103
|
+
* --- 自减 ---
|
|
104
|
+
* @param key
|
|
105
|
+
* @param num 整数或浮点正数
|
|
106
|
+
*/
|
|
29
107
|
decr(key: string, num?: number): Promise<number | false>;
|
|
108
|
+
/**
|
|
109
|
+
* --- 仅修改过期时间不修改值 ---
|
|
110
|
+
* @param key
|
|
111
|
+
* @param ttl
|
|
112
|
+
*/
|
|
30
113
|
expire(key: string, ttl: number): Promise<boolean>;
|
|
114
|
+
/**
|
|
115
|
+
* --- 获取服务器上的所有 key 列表 ---
|
|
116
|
+
* @param pattern
|
|
117
|
+
*/
|
|
31
118
|
keys(pattern: string): Promise<string[] | false>;
|
|
119
|
+
/**
|
|
120
|
+
* --- 根据条件获取服务器上的 keys ---
|
|
121
|
+
* @param cursor
|
|
122
|
+
* @param pattern 例如 *
|
|
123
|
+
* @param count 获取的条数
|
|
124
|
+
*/
|
|
32
125
|
scan(cursor?: number, pattern?: string, count?: number): Promise<redis.IScanResult<string> | false>;
|
|
126
|
+
/**
|
|
127
|
+
* --- 清除当前所选数据库的所有内容 ---
|
|
128
|
+
*/
|
|
33
129
|
flushDb(): Promise<boolean>;
|
|
130
|
+
/**
|
|
131
|
+
* --- 发送 ping ---
|
|
132
|
+
*/
|
|
34
133
|
ping(): Promise<string | false>;
|
|
134
|
+
/**
|
|
135
|
+
* --- 设置哈希表值 ---
|
|
136
|
+
* @param key key 名
|
|
137
|
+
* @param field 字段名
|
|
138
|
+
* @param val 值
|
|
139
|
+
* @param mod 空,nx(key不存在才建立)
|
|
140
|
+
*/
|
|
35
141
|
hSet(key: string, field: string, val: object | string | number, mod?: '' | 'nx'): Promise<boolean>;
|
|
142
|
+
/**
|
|
143
|
+
* --- 批量设置哈希值 ---
|
|
144
|
+
* @param key key 名
|
|
145
|
+
* @param rows key / val 数组
|
|
146
|
+
*/
|
|
36
147
|
hMSet(key: string, rows: Record<string, object | string | number>): Promise<boolean>;
|
|
148
|
+
/**
|
|
149
|
+
* --- 获取哈希值 ---
|
|
150
|
+
* @param key
|
|
151
|
+
* @param field
|
|
152
|
+
*/
|
|
37
153
|
hGet(key: string, field: string): Promise<string | null>;
|
|
154
|
+
/**
|
|
155
|
+
* --- 获取哈希 json 对象 ---
|
|
156
|
+
* @param key
|
|
157
|
+
* @param field
|
|
158
|
+
*/
|
|
38
159
|
hGetJson(key: string, field: string): Promise<any | null>;
|
|
160
|
+
/**
|
|
161
|
+
* --- 批量获取哈希值 ---
|
|
162
|
+
* @param key
|
|
163
|
+
* @param fields
|
|
164
|
+
*/
|
|
39
165
|
hMGet(key: string, fields: string[]): Promise<Record<string, string | null>>;
|
|
166
|
+
/**
|
|
167
|
+
* --- 批量获取哈希键值对 ---
|
|
168
|
+
* @param key
|
|
169
|
+
*/
|
|
40
170
|
hGetAll(key: string): Promise<Record<string, string | null> | null>;
|
|
171
|
+
/**
|
|
172
|
+
* --- 删除哈希键 ---
|
|
173
|
+
* @param key
|
|
174
|
+
* @param fields 值序列
|
|
175
|
+
*/
|
|
41
176
|
hDel(key: string, fields: string | string[]): Promise<number>;
|
|
177
|
+
/**
|
|
178
|
+
* --- 判断哈希字段是否存在 ---
|
|
179
|
+
* @param key
|
|
180
|
+
* @param field
|
|
181
|
+
*/
|
|
42
182
|
hExists(key: string, field: string): Promise<boolean>;
|
|
183
|
+
/**
|
|
184
|
+
* --- 设置哈希自增自减 ---
|
|
185
|
+
* @param key key
|
|
186
|
+
* @param field 字段
|
|
187
|
+
* @param increment 正数或负数,整数或浮点
|
|
188
|
+
*/
|
|
43
189
|
hIncr(key: string, field: string, increment: number): Promise<number>;
|
|
190
|
+
/**
|
|
191
|
+
* --- 获取哈希所有字段 ---
|
|
192
|
+
* @param key
|
|
193
|
+
*/
|
|
44
194
|
hKeys(key: string): Promise<string[]>;
|
|
45
195
|
lPush(key: string, values: Array<string | Buffer>): Promise<number>;
|
|
46
196
|
rPush(key: string, values: Array<string | Buffer>): Promise<number>;
|
|
@@ -50,53 +200,258 @@ export declare class Pool {
|
|
|
50
200
|
bRPop(key: string | string[], timeout: number): Promise<Record<string, string>>;
|
|
51
201
|
lRange(key: string, start: number, stop: number): Promise<string[]>;
|
|
52
202
|
lLen(key: string): Promise<number>;
|
|
203
|
+
/**
|
|
204
|
+
* --- 从连接池获取一个连接,会被自动设置为使用中,需要在执行命令后解除占用 ---
|
|
205
|
+
*/
|
|
53
206
|
private _getConnection;
|
|
54
207
|
}
|
|
55
208
|
export declare class Connection {
|
|
209
|
+
/** --- 本连接最后一次使用时间 --- */
|
|
56
210
|
private _last;
|
|
211
|
+
/** --- kv 缓存连接对象 --- */
|
|
57
212
|
private readonly _link;
|
|
213
|
+
/** --- 当前连接是否正在被独占使用 --- */
|
|
58
214
|
private _using;
|
|
215
|
+
/** --- 当发生断开,则需从连接池移除连接 --- */
|
|
59
216
|
private _lost;
|
|
217
|
+
/** --- 当前的连接配置信息 --- */
|
|
60
218
|
private readonly _etc;
|
|
61
219
|
constructor(etc: types.IConfigKv, link: redis.ICommandClient);
|
|
220
|
+
/**
|
|
221
|
+
* --- 获取连接 etc 信息 ---
|
|
222
|
+
*/
|
|
62
223
|
getEtc(): types.IConfigKv;
|
|
224
|
+
/**
|
|
225
|
+
* --- 获取最后一次获取连接的时间 ---
|
|
226
|
+
*/
|
|
63
227
|
getLast(): number;
|
|
228
|
+
/**
|
|
229
|
+
* --- 将本条连接设置为不可用 ---
|
|
230
|
+
*/
|
|
64
231
|
setLost(): void;
|
|
232
|
+
/**
|
|
233
|
+
* --- 是否已经丢失 ---
|
|
234
|
+
*/
|
|
65
235
|
isLost(): boolean;
|
|
236
|
+
/**
|
|
237
|
+
* --- 将本条连接设置占用中 ---
|
|
238
|
+
*/
|
|
66
239
|
setUsing(): void;
|
|
240
|
+
/**
|
|
241
|
+
* --- 获取当前状态是否正在被使用中 ---
|
|
242
|
+
*/
|
|
67
243
|
isUsing(): boolean;
|
|
244
|
+
/**
|
|
245
|
+
* --- 取消占用 ---
|
|
246
|
+
*/
|
|
68
247
|
used(): void;
|
|
248
|
+
/**
|
|
249
|
+
* --- 设定最后使用时间 ---
|
|
250
|
+
*/
|
|
69
251
|
refreshLast(): void;
|
|
252
|
+
/**
|
|
253
|
+
* --- 断开此连接,一般情况下不使用 ---
|
|
254
|
+
*/
|
|
70
255
|
end(): Promise<void>;
|
|
256
|
+
/**
|
|
257
|
+
* --- 设定一个值 ---
|
|
258
|
+
* @param key
|
|
259
|
+
* @param val
|
|
260
|
+
* @param ttl 秒,0 为不限制
|
|
261
|
+
* @param mod 设置模式: 空,nx(key不存在才建立),xx(key存在才修改)
|
|
262
|
+
* @param etc 配置项,主要用 etc.pre
|
|
263
|
+
*/
|
|
71
264
|
set(key: string, val: object | string | number, ttl: number, mod: '' | 'nx' | 'xx', etc: types.IConfigKv): Promise<boolean>;
|
|
265
|
+
/**
|
|
266
|
+
* --- 添加一个值,存在则不变 ---
|
|
267
|
+
* @param key
|
|
268
|
+
* @param val
|
|
269
|
+
* @param ttl 秒,0 为不限制
|
|
270
|
+
* @param etc
|
|
271
|
+
*/
|
|
72
272
|
add(key: string, val: object | string | number, ttl: number, etc: types.IConfigKv): Promise<boolean>;
|
|
273
|
+
/**
|
|
274
|
+
* --- 替换一个存在的值 ---
|
|
275
|
+
* @param key
|
|
276
|
+
* @param val
|
|
277
|
+
* @param ttl 秒,0 为不限制
|
|
278
|
+
* @param etc
|
|
279
|
+
*/
|
|
73
280
|
replace(key: string, val: object | string | number, ttl: number, etc: types.IConfigKv): Promise<boolean>;
|
|
281
|
+
/**
|
|
282
|
+
* --- 向已存在的值后追加数据 ---
|
|
283
|
+
* @param key
|
|
284
|
+
* @param val
|
|
285
|
+
* @param etc
|
|
286
|
+
*/
|
|
74
287
|
append(key: string, val: string, etc: types.IConfigKv): Promise<boolean>;
|
|
288
|
+
/**
|
|
289
|
+
* --- 向已存在的值之前追加数据 ---
|
|
290
|
+
* @param key
|
|
291
|
+
* @param val
|
|
292
|
+
*/
|
|
75
293
|
prepend(key: string, val: string, etc: types.IConfigKv): Promise<boolean>;
|
|
294
|
+
/**
|
|
295
|
+
* --- 检测 key 是否存在 ---
|
|
296
|
+
* @param keys 单个或序列
|
|
297
|
+
* @param etc
|
|
298
|
+
*/
|
|
76
299
|
exists(keys: string | string[], etc: types.IConfigKv): Promise<number>;
|
|
300
|
+
/**
|
|
301
|
+
* --- 获取字符串 ---
|
|
302
|
+
* @param key
|
|
303
|
+
* @param etc
|
|
304
|
+
*/
|
|
77
305
|
get(key: string, etc: types.IConfigKv): Promise<string | null>;
|
|
306
|
+
/**
|
|
307
|
+
* --- 获取相应的剩余有效期秒数 ---
|
|
308
|
+
* @param key
|
|
309
|
+
* @param etc
|
|
310
|
+
*/
|
|
78
311
|
ttl(key: string, etc: types.IConfigKv): Promise<number | null>;
|
|
312
|
+
/**
|
|
313
|
+
* --- 获取相应的剩余有效期毫秒数 ---
|
|
314
|
+
* @param key
|
|
315
|
+
* @param etc
|
|
316
|
+
*/
|
|
79
317
|
pttl(key: string, etc: types.IConfigKv): Promise<number | null>;
|
|
318
|
+
/**
|
|
319
|
+
* --- 批量获取值 ---
|
|
320
|
+
* @param keys key 序列
|
|
321
|
+
* @param etc 顺序数组
|
|
322
|
+
*/
|
|
80
323
|
mGet(keys: string[], etc: types.IConfigKv): Promise<Record<string, string | null>>;
|
|
324
|
+
/**
|
|
325
|
+
* --- 批量设置哈希值 ---
|
|
326
|
+
* @param key key 名
|
|
327
|
+
* @param rows key / val 数组
|
|
328
|
+
* @param etc
|
|
329
|
+
*/
|
|
81
330
|
mSet(rows: Record<string, string | Buffer>, etc: types.IConfigKv): Promise<boolean>;
|
|
331
|
+
/**
|
|
332
|
+
* --- 获取 json 对象 ---
|
|
333
|
+
* @param key
|
|
334
|
+
* @param etc
|
|
335
|
+
*/
|
|
82
336
|
getJson(key: string, etc: types.IConfigKv): Promise<any | null>;
|
|
337
|
+
/**
|
|
338
|
+
* --- 删除已存在的值 ---
|
|
339
|
+
* @param keys
|
|
340
|
+
* @param etc
|
|
341
|
+
*/
|
|
83
342
|
del(keys: string | string[], etc: types.IConfigKv): Promise<boolean>;
|
|
343
|
+
/**
|
|
344
|
+
* --- 自增 ---
|
|
345
|
+
* @param key
|
|
346
|
+
* @param num 整数或浮点正数
|
|
347
|
+
* @param etc
|
|
348
|
+
*/
|
|
84
349
|
incr(key: string, num: number, etc: types.IConfigKv): Promise<number | false>;
|
|
350
|
+
/**
|
|
351
|
+
* --- 自减 ---
|
|
352
|
+
* @param key
|
|
353
|
+
* @param num 整数或浮点正数
|
|
354
|
+
* @param etc
|
|
355
|
+
*/
|
|
85
356
|
decr(key: string, num: number, etc: types.IConfigKv): Promise<number | false>;
|
|
357
|
+
/**
|
|
358
|
+
* --- 仅修改过期时间不修改值 ---
|
|
359
|
+
* @param key
|
|
360
|
+
* @param ttl
|
|
361
|
+
* @param etc
|
|
362
|
+
*/
|
|
86
363
|
expire(key: string, ttl: number, etc: types.IConfigKv): Promise<boolean>;
|
|
364
|
+
/**
|
|
365
|
+
* --- 获取服务器上的所有 key 列表 ---
|
|
366
|
+
* @param pattern
|
|
367
|
+
*/
|
|
87
368
|
keys(pattern: string, etc: types.IConfigKv): Promise<string[] | false>;
|
|
369
|
+
/**
|
|
370
|
+
* --- 根据条件获取服务器上的 keys ---
|
|
371
|
+
* @param cursor
|
|
372
|
+
* @param pattern 例如 *
|
|
373
|
+
* @param count 获取的条数
|
|
374
|
+
* @param etc
|
|
375
|
+
*/
|
|
88
376
|
scan(cursor: number, pattern: string, count: number, etc: types.IConfigKv): Promise<redis.IScanResult<string> | false>;
|
|
377
|
+
/**
|
|
378
|
+
* --- 清除当前所选数据库的所有内容 ---
|
|
379
|
+
*/
|
|
89
380
|
flushDb(): Promise<boolean>;
|
|
381
|
+
/**
|
|
382
|
+
* --- 发送 ping ---
|
|
383
|
+
*/
|
|
90
384
|
ping(): Promise<false | string>;
|
|
385
|
+
/**
|
|
386
|
+
* --- 设置哈希表值 ---
|
|
387
|
+
* @param key key 名
|
|
388
|
+
* @param field 字段名
|
|
389
|
+
* @param val 值
|
|
390
|
+
* @param mod 空,nx(key不存在才建立)
|
|
391
|
+
* @param etc
|
|
392
|
+
*/
|
|
91
393
|
hSet(key: string, field: string, val: object | string | number, mod: '' | 'nx', etc: types.IConfigKv): Promise<boolean>;
|
|
394
|
+
/**
|
|
395
|
+
* --- 批量设置哈希值 ---
|
|
396
|
+
* @param key key 名
|
|
397
|
+
* @param rows key / val 数组
|
|
398
|
+
* @param etc
|
|
399
|
+
*/
|
|
92
400
|
hMSet(key: string, rows: Record<string, object | string | number>, etc: types.IConfigKv): Promise<boolean>;
|
|
401
|
+
/**
|
|
402
|
+
* --- 获取哈希值 ---
|
|
403
|
+
* @param key
|
|
404
|
+
* @param field
|
|
405
|
+
* @param etc
|
|
406
|
+
*/
|
|
93
407
|
hGet(key: string, field: string, etc: types.IConfigKv): Promise<string | null>;
|
|
408
|
+
/**
|
|
409
|
+
* --- 获取哈希 json 对象 ---
|
|
410
|
+
* @param key
|
|
411
|
+
* @param field
|
|
412
|
+
* @param etc
|
|
413
|
+
*/
|
|
94
414
|
hGetJson(key: string, field: string, etc: types.IConfigKv): Promise<any | null>;
|
|
415
|
+
/**
|
|
416
|
+
* --- 批量获取哈希值 ---
|
|
417
|
+
* @param key
|
|
418
|
+
* @param fields
|
|
419
|
+
* @param etc
|
|
420
|
+
*/
|
|
95
421
|
hMGet(key: string, fields: string[], etc: types.IConfigKv): Promise<Record<string, string | null>>;
|
|
422
|
+
/**
|
|
423
|
+
* --- 批量获取哈希键值对 ---
|
|
424
|
+
* @param key
|
|
425
|
+
* @param etc
|
|
426
|
+
*/
|
|
96
427
|
hGetAll(key: string, etc: types.IConfigKv): Promise<Record<string, string | null> | null>;
|
|
428
|
+
/**
|
|
429
|
+
* --- 删除哈希键 ---
|
|
430
|
+
* @param key
|
|
431
|
+
* @param fields 值序列
|
|
432
|
+
* @param etc
|
|
433
|
+
*/
|
|
97
434
|
hDel(key: string, fields: string | string[], etc: types.IConfigKv): Promise<number>;
|
|
435
|
+
/**
|
|
436
|
+
* --- 判断哈希字段是否存在 ---
|
|
437
|
+
* @param key
|
|
438
|
+
* @param field
|
|
439
|
+
* @param etc
|
|
440
|
+
*/
|
|
98
441
|
hExists(key: string, field: string, etc: types.IConfigKv): Promise<boolean>;
|
|
442
|
+
/**
|
|
443
|
+
* --- 设置哈希自增自减 ---
|
|
444
|
+
* @param key key
|
|
445
|
+
* @param field 字段
|
|
446
|
+
* @param increment 正数或负数,整数或浮点
|
|
447
|
+
* @param etc
|
|
448
|
+
*/
|
|
99
449
|
hIncr(key: string, field: string, increment: number, etc: types.IConfigKv): Promise<number>;
|
|
450
|
+
/**
|
|
451
|
+
* --- 获取哈希所有字段 ---
|
|
452
|
+
* @param key
|
|
453
|
+
* @param etc
|
|
454
|
+
*/
|
|
100
455
|
hKeys(key: string, etc: types.IConfigKv): Promise<string[]>;
|
|
101
456
|
lPush(key: string, values: Array<string | Buffer>, etc: types.IConfigKv): Promise<number>;
|
|
102
457
|
rPush(key: string, values: Array<string | Buffer>, etc: types.IConfigKv): Promise<number>;
|
|
@@ -107,5 +462,12 @@ export declare class Connection {
|
|
|
107
462
|
lRange(key: string, start: number, stop: number, etc: types.IConfigKv): Promise<string[]>;
|
|
108
463
|
lLen(key: string, etc: types.IConfigKv): Promise<number>;
|
|
109
464
|
}
|
|
465
|
+
/**
|
|
466
|
+
* --- 获取 Kv Pool 对象 ---
|
|
467
|
+
* @param etc 配置信息可留空
|
|
468
|
+
*/
|
|
110
469
|
export declare function get(ctr: ctr.Ctr, etc?: types.IConfigKv): Pool;
|
|
470
|
+
/**
|
|
471
|
+
* --- 获取当前连接池中所有连接的信息 ---
|
|
472
|
+
*/
|
|
111
473
|
export declare function getConnectionList(): IConnectionInfo[];
|