koatty_store 1.6.2 → 1.8.0

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/index.d.ts CHANGED
@@ -1,16 +1,13 @@
1
1
  /*!
2
2
  * @Author: richen
3
- * @Date: 2023-12-20 19:12:12
3
+ * @Date: 2025-06-09 12:32:53
4
4
  * @License: BSD (3-Clause)
5
5
  * @Copyright (c) - <richenlin(at)gmail.com>
6
6
  * @HomePage: https://koatty.org/
7
7
  */
8
- /// <reference types="node" />
9
-
10
8
  import { Cluster } from 'ioredis';
11
9
  import { ClusterOptions } from 'ioredis';
12
- import { default as default_2 } from 'ioredis/built/cluster';
13
- import { default as default_3 } from 'ioredis/built/Redis';
10
+ import { default as default_2 } from 'ioredis';
14
11
  import { EventEmitter } from 'events';
15
12
  import genericPool from 'generic-pool';
16
13
  import { Redis } from 'ioredis';
@@ -22,7 +19,7 @@ import { RedisOptions } from 'ioredis';
22
19
  * @export
23
20
  * @class Store
24
21
  */
25
- export declare class CacheStore {
22
+ export declare class CacheStore implements CacheStoreInterface {
26
23
  client: MemoryStore | RedisStore;
27
24
  options: StoreOptions;
28
25
  /**
@@ -30,19 +27,42 @@ export declare class CacheStore {
30
27
  * @param {StoreOptions} options
31
28
  * @memberof CacheStore
32
29
  */
33
- constructor(options: StoreOptions);
30
+ constructor(options?: StoreOptions);
34
31
  /**
35
- *
36
- *
32
+ * 获取单例实例,支持多配置实例管理
33
+ * @static
34
+ * @param {StoreOptions} [options]
35
+ * @param {string} [instanceKey='default'] 实例键名,用于区分不同配置的实例
36
+ * @returns {CacheStore}
37
+ */
38
+ static getInstance(options?: StoreOptions, instanceKey?: string): CacheStore;
39
+ /**
40
+ * 生成配置哈希
41
+ * @private
42
+ * @static
43
+ * @param {StoreOptions} options
44
+ * @returns {string}
45
+ */
46
+ /**
47
+ * 清理指定实例
48
+ * @static
49
+ * @param {string} [instanceKey='default']
50
+ */
51
+ static clearInstance(instanceKey?: string): Promise<void>;
52
+ /**
53
+ * 清理所有实例
37
54
  * @static
38
- * @returns
39
55
  */
40
- static getInstance(options: StoreOptions): CacheStore;
41
- getConnection(): MemoryCache | Promise<default_2 | default_3>;
56
+ static clearAllInstances(): Promise<void>;
57
+ getConnection(): MemoryCache | Promise<Cluster | default_2>;
42
58
  close(): Promise<void>;
43
59
  release(conn: any): Promise<void>;
44
- defineCommand(name: string, scripts: any): Promise<any>;
45
- getCompare(name: string, value: string | number): Promise<any>;
60
+ /**
61
+ * 获取底层实现客户端,用于访问特定实现的功能
62
+ * 例如:Redis的defineCommand, getCompare等
63
+ * @returns {MemoryStore | RedisStore}
64
+ */
65
+ getRawClient(): MemoryStore | RedisStore;
46
66
  /**
47
67
  * handler for native client
48
68
  *
@@ -55,7 +75,7 @@ export declare class CacheStore {
55
75
  * 字符串获取
56
76
  * @param name
57
77
  */
58
- get(name: string): Promise<any>;
78
+ get(name: string): Promise<string | null>;
59
79
  /**
60
80
  * 字符串写入
61
81
  * @param name
@@ -63,61 +83,56 @@ export declare class CacheStore {
63
83
  * @param timeout
64
84
  * @returns {Promise}
65
85
  */
66
- set(name: string, value: string | number, timeout?: number): Promise<any>;
86
+ set(name: string, value: string | number, timeout?: number): Promise<string>;
67
87
  /**
68
88
  * 以秒为单位,返回给定 key 的剩余生存时间
69
89
  * @param name
70
90
  * @returns {*}
71
91
  */
72
- ttl(name: string): Promise<any>;
92
+ ttl(name: string): Promise<number>;
73
93
  /**
74
94
  * 设置key超时属性
75
95
  * @param name
76
96
  * @param timeout
77
97
  */
78
- expire(name: string, timeout?: number): Promise<any>;
79
- /**
80
- * 删除key
81
- * @param name
82
- */
83
- rm(name: string): Promise<any>;
98
+ expire(name: string, timeout: number): Promise<number>;
84
99
  /**
85
100
  *
86
101
  *
87
102
  * @param {*} name
88
103
  * @returns
89
104
  */
90
- del(name: string): Promise<any>;
105
+ del(name: string): Promise<number>;
91
106
  /**
92
107
  * 判断key是否存在
93
108
  * @param name
94
109
  */
95
- exists(name: string): Promise<any>;
110
+ exists(name: string): Promise<number>;
96
111
  /**
97
112
  * 自增
98
113
  * @param name
99
114
  */
100
- incr(name: string): Promise<any>;
115
+ incr(name: string): Promise<number>;
101
116
  /**
102
117
  * 自减
103
118
  * @param name
104
119
  * @returns {*}
105
120
  */
106
- decr(name: string): Promise<any>;
121
+ decr(name: string): Promise<number>;
107
122
  /**
108
123
  * 将 key 所储存的值增加增量
109
124
  * @param name
110
125
  * @param incr
111
126
  * @returns {*}
112
127
  */
113
- incrby(name: string, incr?: number): Promise<any>;
128
+ incrby(name: string, increment: number): Promise<number>;
114
129
  /**
115
130
  * 将 key 所储存的值减去减量
116
131
  *
117
132
  * @param {any} name
118
133
  * @param {any} decr
119
134
  */
120
- decrby(name: string, decr?: number): Promise<any>;
135
+ decrby(name: string, decrement: number): Promise<number>;
121
136
  /**
122
137
  * 哈希写入
123
138
  * @param name
@@ -125,42 +140,42 @@ export declare class CacheStore {
125
140
  * @param value
126
141
  * @param timeout
127
142
  */
128
- hset(name: string, key: string, value: string | number, timeout?: number): Promise<any[]>;
143
+ hset(name: string, key: string, value: string | number, timeout?: number): Promise<number>;
129
144
  /**
130
145
  * 哈希获取
131
146
  * @param name
132
147
  * @param key
133
148
  * @returns {*}
134
149
  */
135
- hget(name: string, key: string): Promise<any>;
150
+ hget(name: string, key: string): Promise<string | null>;
136
151
  /**
137
152
  * 查看哈希表 hashKey 中,给定域 key 是否存在
138
153
  * @param name
139
154
  * @param key
140
155
  * @returns {*}
141
156
  */
142
- hexists(name: string, key: string): Promise<any>;
157
+ hexists(name: string, key: string): Promise<number>;
143
158
  /**
144
159
  * 哈希删除
145
160
  * @param name
146
161
  * @param key
147
162
  * @returns {*}
148
163
  */
149
- hdel(name: string, key: string): Promise<any[]>;
164
+ hdel(name: string, key: string): Promise<number>;
150
165
  /**
151
166
  * 返回哈希表 key 中域的数量
152
167
  * @param name
153
168
  * @returns {*}
154
169
  */
155
- hlen(name: string): Promise<any>;
170
+ hlen(name: string): Promise<number>;
156
171
  /**
157
172
  * 给哈希表指定key,增加increment
158
173
  * @param name
159
174
  * @param key
160
- * @param incr
175
+ * @param increment
161
176
  * @returns {*}
162
177
  */
163
- hincrby(name: string, key: string, incr?: number): Promise<any>;
178
+ hincrby(name: string, key: string, increment: number): Promise<number>;
164
179
  /**
165
180
  * 返回哈希表所有key-value
166
181
  * @param name
@@ -172,26 +187,26 @@ export declare class CacheStore {
172
187
  * @param name
173
188
  * @returns {*}
174
189
  */
175
- hkeys(name: string): Promise<any>;
190
+ hkeys(name: string): Promise<string[]>;
176
191
  /**
177
192
  * 返回哈希表所有value
178
193
  * @param name
179
194
  * @returns {*}
180
195
  */
181
- hvals(name: string): Promise<any>;
196
+ hvals(name: string): Promise<any[]>;
182
197
  /**
183
198
  * 判断列表长度,若不存在则表示为空
184
199
  * @param name
185
200
  * @returns {*}
186
201
  */
187
- llen(name: string): Promise<any>;
202
+ llen(name: string): Promise<number>;
188
203
  /**
189
204
  * 将值插入列表表尾
190
205
  * @param name
191
206
  * @param value
192
207
  * @returns {*}
193
208
  */
194
- rpush(name: string, value: string | number): Promise<any>;
209
+ rpush(name: string, value: string | number): Promise<number>;
195
210
  /**
196
211
  *
197
212
  *
@@ -200,13 +215,13 @@ export declare class CacheStore {
200
215
  * @returns {*}
201
216
  * @memberof RedisStore
202
217
  */
203
- lpush(name: string, value: string | number): Promise<any>;
218
+ lpush(name: string, value: string | number): Promise<number>;
204
219
  /**
205
220
  * 将列表表头取出,并去除
206
221
  * @param name
207
222
  * @returns {*}
208
223
  */
209
- lpop(name: string): Promise<any>;
224
+ lpop(name: string): Promise<string | null>;
210
225
  /**
211
226
  *
212
227
  *
@@ -214,7 +229,7 @@ export declare class CacheStore {
214
229
  * @returns {*}
215
230
  * @memberof RedisStore
216
231
  */
217
- rpop(name: string): Promise<any>;
232
+ rpop(name: string): Promise<string | null>;
218
233
  /**
219
234
  * 返回列表 key 中指定区间内的元素,区间以偏移量 start 和 stop 指定
220
235
  * @param name
@@ -222,7 +237,7 @@ export declare class CacheStore {
222
237
  * @param stop
223
238
  * @returns {*}
224
239
  */
225
- lrange(name: string, start: number, stop: number): Promise<any>;
240
+ lrange(name: string, start: number, stop: number): Promise<any[]>;
226
241
  /**
227
242
  * 集合新增
228
243
  * @param name
@@ -230,26 +245,26 @@ export declare class CacheStore {
230
245
  * @param timeout
231
246
  * @returns {*}
232
247
  */
233
- sadd(name: string, value: string | number, timeout?: number): Promise<any[]>;
248
+ sadd(name: string, value: string | number, timeout?: number): Promise<number>;
234
249
  /**
235
250
  * 返回集合的基数(集合中元素的数量)
236
251
  * @param name
237
252
  * @returns {*}
238
253
  */
239
- scard(name: string): Promise<any>;
254
+ scard(name: string): Promise<number>;
240
255
  /**
241
256
  * 判断 member 元素是否集合的成员
242
257
  * @param name
243
258
  * @param key
244
259
  * @returns {*}
245
260
  */
246
- sismember(name: string, key: string): Promise<any>;
261
+ sismember(name: string, key: string): Promise<number>;
247
262
  /**
248
263
  * 返回集合中的所有成员
249
264
  * @param name
250
265
  * @returns {*}
251
266
  */
252
- smembers(name: string): Promise<any>;
267
+ smembers(name: string): Promise<any[]>;
253
268
  /**
254
269
  * 移除并返回集合中的一个随机元素
255
270
  * @param name
@@ -262,7 +277,7 @@ export declare class CacheStore {
262
277
  * @param key
263
278
  * @returns {*}
264
279
  */
265
- srem(name: string, key: string): Promise<any>;
280
+ srem(name: string, key: string): Promise<number>;
266
281
  /**
267
282
  * 将 member 元素从 source 集合移动到 destination 集合
268
283
  * @param source
@@ -270,17 +285,49 @@ export declare class CacheStore {
270
285
  * @param member
271
286
  * @returns {*}
272
287
  */
273
- smove(source: string, destination: string, member: string): Promise<any>;
288
+ smove(source: string, destination: string, member: string): Promise<number>;
274
289
  }
275
290
 
276
291
  declare interface CacheStoreInterface {
277
- getConnection(): void;
292
+ getConnection(): any;
278
293
  close(): Promise<void>;
279
294
  release(conn: any): Promise<void>;
280
- defineCommand(name: string, scripts: any): void;
281
- getCompare(name: string, value: string | number): Promise<any>;
295
+ get?(name: string): Promise<string | null>;
296
+ set?(name: string, value: string | number, timeout?: number): Promise<string>;
297
+ del?(name: string): Promise<number>;
298
+ exists?(name: string): Promise<number>;
299
+ ttl?(name: string): Promise<number>;
300
+ expire?(name: string, timeout: number): Promise<number>;
301
+ incr?(name: string): Promise<number>;
302
+ decr?(name: string): Promise<number>;
303
+ incrby?(name: string, increment: number): Promise<number>;
304
+ decrby?(name: string, decrement: number): Promise<number>;
305
+ hset?(name: string, key: string, value: string | number, timeout?: number): Promise<number>;
306
+ hget?(name: string, key: string): Promise<string | null>;
307
+ hdel?(name: string, key: string): Promise<number>;
308
+ hexists?(name: string, key: string): Promise<number>;
309
+ hgetall?(name: string): Promise<any>;
310
+ hkeys?(name: string): Promise<string[]>;
311
+ hvals?(name: string): Promise<any[]>;
312
+ hlen?(name: string): Promise<number>;
313
+ hincrby?(name: string, key: string, increment: number): Promise<number>;
314
+ lpush?(name: string, value: string | number): Promise<number>;
315
+ rpush?(name: string, value: string | number): Promise<number>;
316
+ lpop?(name: string): Promise<string | null>;
317
+ rpop?(name: string): Promise<string | null>;
318
+ llen?(name: string): Promise<number>;
319
+ lrange?(name: string, start: number, stop: number): Promise<any[]>;
320
+ sadd?(name: string, value: string | number, timeout?: number): Promise<number>;
321
+ srem?(name: string, key: string): Promise<number>;
322
+ scard?(name: string): Promise<number>;
323
+ sismember?(name: string, key: string): Promise<number>;
324
+ smembers?(name: string): Promise<any[]>;
325
+ spop?(name: string): Promise<any>;
326
+ smove?(source: string, destination: string, member: string): Promise<number>;
282
327
  }
283
328
 
329
+ declare type CallbackFunction<T = any> = (err: Error | null, result?: T) => void;
330
+
284
331
  declare class MemoryCache extends EventEmitter {
285
332
  options: MemoryCacheOptions;
286
333
  currentDBIndex: number;
@@ -289,10 +336,22 @@ declare class MemoryCache extends EventEmitter {
289
336
  multiMode: boolean;
290
337
  /**
291
338
  * Creates an instance of MemoryCache.
292
- * @param {*} options
339
+ * @param {MemoryCacheOptions} options
293
340
  * @memberof MemoryCache
294
341
  */
295
342
  constructor(options: MemoryCacheOptions);
343
+ /**
344
+ * 创建LRU缓存实例
345
+ */
346
+ /**
347
+ * 启动TTL检查定时器
348
+ */
349
+ /**
350
+ * 清理过期键
351
+ */
352
+ /**
353
+ * 停止TTL检查
354
+ */
296
355
  /**
297
356
  *
298
357
  *
@@ -314,6 +373,13 @@ declare class MemoryCache extends EventEmitter {
314
373
  * @memberof MemoryCache
315
374
  */
316
375
  end(): this;
376
+ /**
377
+ * 获取缓存统计信息
378
+ */
379
+ info(): any;
380
+ /**
381
+ * 估算内存使用量
382
+ */
317
383
  /**
318
384
  *
319
385
  *
@@ -322,7 +388,7 @@ declare class MemoryCache extends EventEmitter {
322
388
  * @returns {*}
323
389
  * @memberof MemoryCache
324
390
  */
325
- echo(message: string, callback?: Function): any;
391
+ echo(message: string, callback?: CallbackFunction): any;
326
392
  /**
327
393
  *
328
394
  *
@@ -331,7 +397,7 @@ declare class MemoryCache extends EventEmitter {
331
397
  * @returns {*}
332
398
  * @memberof MemoryCache
333
399
  */
334
- ping(message: string, callback?: Function): any;
400
+ ping(message: string, callback?: CallbackFunction): any;
335
401
  /**
336
402
  *
337
403
  *
@@ -340,7 +406,7 @@ declare class MemoryCache extends EventEmitter {
340
406
  * @returns {*}
341
407
  * @memberof MemoryCache
342
408
  */
343
- auth(password: string, callback?: Function): any;
409
+ auth(password: string, callback?: CallbackFunction): any;
344
410
  /**
345
411
  *
346
412
  *
@@ -349,8 +415,8 @@ declare class MemoryCache extends EventEmitter {
349
415
  * @returns {*}
350
416
  * @memberof MemoryCache
351
417
  */
352
- select(dbIndex: number, callback?: Function): any;
353
- get(key: string, callback?: Function): any;
418
+ select(dbIndex: number, callback?: CallbackFunction): any;
419
+ get(key: string, callback?: CallbackFunction): any;
354
420
  /**
355
421
  * set(key, value, ttl, pttl, notexist, onlyexist, callback)
356
422
  *
@@ -369,7 +435,7 @@ declare class MemoryCache extends EventEmitter {
369
435
  * @returns {*}
370
436
  * @memberof MemoryCache
371
437
  */
372
- ttl(key: string, callback?: Function): any;
438
+ ttl(key: string, callback?: CallbackFunction): any;
373
439
  /**
374
440
  *
375
441
  *
@@ -379,7 +445,7 @@ declare class MemoryCache extends EventEmitter {
379
445
  * @returns {*}
380
446
  * @memberof MemoryCache
381
447
  */
382
- expire(key: string, seconds: number, callback?: Function): any;
448
+ expire(key: string, seconds: number, callback?: CallbackFunction): any;
383
449
  /**
384
450
  *
385
451
  *
@@ -404,7 +470,7 @@ declare class MemoryCache extends EventEmitter {
404
470
  * @returns {*}
405
471
  * @memberof MemoryCache
406
472
  */
407
- incr(key: string, callback?: Function): any;
473
+ incr(key: string, callback?: CallbackFunction): any;
408
474
  /**
409
475
  *
410
476
  *
@@ -414,7 +480,7 @@ declare class MemoryCache extends EventEmitter {
414
480
  * @returns {*}
415
481
  * @memberof MemoryCache
416
482
  */
417
- incrby(key: string, amount: number, callback?: Function): any;
483
+ incrby(key: string, amount: number, callback?: CallbackFunction): any;
418
484
  /**
419
485
  *
420
486
  *
@@ -423,7 +489,7 @@ declare class MemoryCache extends EventEmitter {
423
489
  * @returns {*}
424
490
  * @memberof MemoryCache
425
491
  */
426
- decr(key: string, callback?: Function): any;
492
+ decr(key: string, callback?: CallbackFunction): any;
427
493
  /**
428
494
  *
429
495
  *
@@ -433,8 +499,8 @@ declare class MemoryCache extends EventEmitter {
433
499
  * @returns {*}
434
500
  * @memberof MemoryCache
435
501
  */
436
- decrby(key: string, amount: number, callback?: Function): any;
437
- hset(key: string, field: string, value: string | number, callback?: Function): any;
502
+ decrby(key: string, amount: number, callback?: CallbackFunction): any;
503
+ hset(key: string, field: string, value: string | number, callback?: CallbackFunction): any;
438
504
  /**
439
505
  *
440
506
  *
@@ -444,7 +510,7 @@ declare class MemoryCache extends EventEmitter {
444
510
  * @returns {*}
445
511
  * @memberof MemoryCache
446
512
  */
447
- hget(key: string, field: string, callback?: Function): any;
513
+ hget(key: string, field: string, callback?: CallbackFunction): any;
448
514
  /**
449
515
  *
450
516
  *
@@ -454,7 +520,7 @@ declare class MemoryCache extends EventEmitter {
454
520
  * @returns {*}
455
521
  * @memberof MemoryCache
456
522
  */
457
- hexists(key: string, field: string, callback?: Function): any;
523
+ hexists(key: string, field: string, callback?: CallbackFunction): any;
458
524
  /**
459
525
  *
460
526
  *
@@ -472,7 +538,7 @@ declare class MemoryCache extends EventEmitter {
472
538
  * @returns {*}
473
539
  * @memberof MemoryCache
474
540
  */
475
- hlen(key: string, callback?: Function): any;
541
+ hlen(key: string, callback?: CallbackFunction): any;
476
542
  /**
477
543
  *
478
544
  *
@@ -483,7 +549,7 @@ declare class MemoryCache extends EventEmitter {
483
549
  * @returns {*}
484
550
  * @memberof MemoryCache
485
551
  */
486
- hincrby(key: string, field: string, value: any, callback?: Function): any;
552
+ hincrby(key: string, field: string, value: any, callback?: CallbackFunction): any;
487
553
  /**
488
554
  *
489
555
  *
@@ -492,7 +558,7 @@ declare class MemoryCache extends EventEmitter {
492
558
  * @returns {*}
493
559
  * @memberof MemoryCache
494
560
  */
495
- hgetall(key: string, callback?: Function): any;
561
+ hgetall(key: string, callback?: CallbackFunction): any;
496
562
  /**
497
563
  *
498
564
  *
@@ -501,7 +567,7 @@ declare class MemoryCache extends EventEmitter {
501
567
  * @returns {*}
502
568
  * @memberof MemoryCache
503
569
  */
504
- hkeys(key: string, callback?: Function): any;
570
+ hkeys(key: string, callback?: CallbackFunction): any;
505
571
  /**
506
572
  *
507
573
  *
@@ -510,7 +576,7 @@ declare class MemoryCache extends EventEmitter {
510
576
  * @returns {*}
511
577
  * @memberof MemoryCache
512
578
  */
513
- hvals(key: string, callback?: Function): any;
579
+ hvals(key: string, callback?: CallbackFunction): any;
514
580
  /**
515
581
  *
516
582
  *
@@ -519,7 +585,7 @@ declare class MemoryCache extends EventEmitter {
519
585
  * @returns {*}
520
586
  * @memberof MemoryCache
521
587
  */
522
- llen(key: string, callback?: Function): any;
588
+ llen(key: string, callback?: CallbackFunction): any;
523
589
  /**
524
590
  *
525
591
  *
@@ -529,17 +595,21 @@ declare class MemoryCache extends EventEmitter {
529
595
  * @returns {*}
530
596
  * @memberof MemoryCache
531
597
  */
532
- rpush(key: string, value: string | number, callback?: Function): any;
598
+ rpush(key: string, value: string | number, callback?: CallbackFunction): any;
533
599
  /**
534
- *
535
- *
536
- * @param {string} key
537
- * @param {(string | number)} value
538
- * @param {Function} [callback]
539
- * @returns {*}
540
- * @memberof MemoryCache
600
+ * List:从左侧推入
601
+ * @param key
602
+ * @param value
603
+ * @param callback
604
+ */
605
+ lpush(key: string, value: any, callback?: CallbackFunction): any;
606
+ /**
607
+ * List:获取指定索引的元素
608
+ * @param key
609
+ * @param index
610
+ * @param callback
541
611
  */
542
- lpush(key: string, value: string | number, callback?: Function): any;
612
+ lindex(key: string, index: number, callback?: CallbackFunction): any;
543
613
  /**
544
614
  *
545
615
  *
@@ -548,7 +618,7 @@ declare class MemoryCache extends EventEmitter {
548
618
  * @returns {*}
549
619
  * @memberof MemoryCache
550
620
  */
551
- lpop(key: string, callback?: Function): any;
621
+ lpop(key: string, callback?: CallbackFunction): any;
552
622
  /**
553
623
  *
554
624
  *
@@ -557,7 +627,7 @@ declare class MemoryCache extends EventEmitter {
557
627
  * @returns {*}
558
628
  * @memberof MemoryCache
559
629
  */
560
- rpop(key: string, callback?: Function): any;
630
+ rpop(key: string, callback?: CallbackFunction): any;
561
631
  /**
562
632
  *
563
633
  *
@@ -568,7 +638,7 @@ declare class MemoryCache extends EventEmitter {
568
638
  * @returns {*}
569
639
  * @memberof MemoryCache
570
640
  */
571
- lrange(key: string, start: number, stop: number, callback?: Function): any;
641
+ lrange(key: string, start: number, stop: number, callback?: CallbackFunction): any;
572
642
  /**
573
643
  *
574
644
  *
@@ -586,7 +656,7 @@ declare class MemoryCache extends EventEmitter {
586
656
  * @returns {*}
587
657
  * @memberof MemoryCache
588
658
  */
589
- scard(key: string, callback?: Function): any;
659
+ scard(key: string, callback?: CallbackFunction): any;
590
660
  /**
591
661
  *
592
662
  *
@@ -596,7 +666,7 @@ declare class MemoryCache extends EventEmitter {
596
666
  * @returns {*}
597
667
  * @memberof MemoryCache
598
668
  */
599
- sismember(key: string, member: string, callback?: Function): any;
669
+ sismember(key: string, member: string, callback?: CallbackFunction): any;
600
670
  /**
601
671
  *
602
672
  *
@@ -605,7 +675,7 @@ declare class MemoryCache extends EventEmitter {
605
675
  * @returns {*}
606
676
  * @memberof MemoryCache
607
677
  */
608
- smembers(key: string, callback?: Function): any;
678
+ smembers(key: string, callback?: CallbackFunction): any;
609
679
  /**
610
680
  *
611
681
  *
@@ -615,7 +685,7 @@ declare class MemoryCache extends EventEmitter {
615
685
  * @returns {*}
616
686
  * @memberof MemoryCache
617
687
  */
618
- spop(key: string, count?: number, callback?: Function): any;
688
+ spop(key: string, count?: number, callback?: CallbackFunction): any;
619
689
  /**
620
690
  *
621
691
  *
@@ -635,8 +705,8 @@ declare class MemoryCache extends EventEmitter {
635
705
  * @returns {*}
636
706
  * @memberof MemoryCache
637
707
  */
638
- smove(sourcekey: string, destkey: string, member: string, callback?: Function): any;
639
- discard(callback?: Function, silent?: boolean): any;
708
+ smove(sourcekey: string, destkey: string, member: string, callback?: CallbackFunction): any;
709
+ discard(callback?: CallbackFunction, silent?: boolean): any;
640
710
  /**
641
711
  *
642
712
  *
@@ -775,6 +845,134 @@ declare class MemoryCache extends EventEmitter {
775
845
  * @returns {*}
776
846
  * @memberof MemoryCache
777
847
  */
848
+ /**
849
+ * 字符串追加操作
850
+ * @param key
851
+ * @param value
852
+ * @param callback
853
+ */
854
+ append(key: string, value: string, callback?: CallbackFunction): any;
855
+ /**
856
+ * 获取字符串长度
857
+ * @param key
858
+ * @param callback
859
+ */
860
+ strlen(key: string, callback?: CallbackFunction): any;
861
+ /**
862
+ * 获取子字符串
863
+ * @param key
864
+ * @param start
865
+ * @param end
866
+ * @param callback
867
+ */
868
+ getrange(key: string, start: number, end: number, callback?: CallbackFunction): any;
869
+ /**
870
+ * 设置子字符串
871
+ * @param key
872
+ * @param offset
873
+ * @param value
874
+ * @param callback
875
+ */
876
+ setrange(key: string, offset: number, value: string, callback?: CallbackFunction): any;
877
+ /**
878
+ * 批量获取
879
+ * @param keys
880
+ * @param callback
881
+ */
882
+ mget(...keys: any[]): any;
883
+ /**
884
+ * 批量设置
885
+ * @param keyValuePairs
886
+ * @param callback
887
+ */
888
+ mset(...keyValuePairs: any[]): any;
889
+ /**
890
+ * 获取所有键
891
+ * @param pattern
892
+ * @param callback
893
+ */
894
+ keys(pattern?: string, callback?: CallbackFunction): any;
895
+ /**
896
+ * 简单的模式匹配
897
+ * @param key
898
+ * @param pattern
899
+ */
900
+ /**
901
+ * 获取随机键
902
+ * @param callback
903
+ */
904
+ randomkey(callback?: CallbackFunction): any;
905
+ /**
906
+ * 重命名键
907
+ * @param oldKey
908
+ * @param newKey
909
+ * @param callback
910
+ */
911
+ rename(oldKey: string, newKey: string, callback?: CallbackFunction): any;
912
+ /**
913
+ * 安全重命名键(目标键不存在时才重命名)
914
+ * @param oldKey
915
+ * @param newKey
916
+ * @param callback
917
+ */
918
+ renamenx(oldKey: string, newKey: string, callback?: CallbackFunction): any;
919
+ /**
920
+ * 获取键的类型
921
+ * @param key
922
+ * @param callback
923
+ */
924
+ type(key: string, callback?: CallbackFunction): any;
925
+ /**
926
+ * 清空当前数据库
927
+ * @param callback
928
+ */
929
+ flushdb(callback?: CallbackFunction): any;
930
+ /**
931
+ * 清空所有数据库
932
+ * @param callback
933
+ */
934
+ flushall(callback?: CallbackFunction): any;
935
+ /**
936
+ * 获取数据库大小
937
+ * @param callback
938
+ */
939
+ dbsize(callback?: CallbackFunction): any;
940
+ /**
941
+ * Sorted Set基础实现 - 添加成员
942
+ * @param key
943
+ * @param score
944
+ * @param member
945
+ * @param callback
946
+ */
947
+ zadd(key: string, score: number, member: string, callback?: CallbackFunction): any;
948
+ /**
949
+ * Sorted Set - 获取成员分数
950
+ * @param key
951
+ * @param member
952
+ * @param callback
953
+ */
954
+ zscore(key: string, member: string, callback?: CallbackFunction): any;
955
+ /**
956
+ * Sorted Set - 获取范围内的成员
957
+ * @param key
958
+ * @param start
959
+ * @param stop
960
+ * @param callback
961
+ */
962
+ zrange(key: string, start: number, stop: number, callback?: CallbackFunction): any;
963
+ /**
964
+ * Sorted Set - 获取成员数量
965
+ * @param key
966
+ * @param callback
967
+ */
968
+ zcard(key: string, callback?: CallbackFunction): any;
969
+ /**
970
+ * Sorted Set - 删除成员
971
+ * @param key
972
+ * @param member
973
+ * @param callback
974
+ */
975
+ zrem(key: string, member: string, callback?: CallbackFunction): any;
778
976
  }
779
977
 
780
978
  /**
@@ -784,6 +982,11 @@ declare class MemoryCache extends EventEmitter {
784
982
  */
785
983
  declare interface MemoryCacheOptions {
786
984
  database: number;
985
+ maxKeys?: number;
986
+ maxMemory?: number;
987
+ evictionPolicy?: 'lru' | 'lfu' | 'random';
988
+ ttlCheckInterval?: number;
989
+ maxAge?: number;
787
990
  }
788
991
 
789
992
  declare class MemoryStore implements CacheStoreInterface {
@@ -813,19 +1016,19 @@ declare class MemoryStore implements CacheStoreInterface {
813
1016
  /**
814
1017
  * release
815
1018
  *
816
- * @param {*} conn
1019
+ * @param {*} _conn
817
1020
  * @returns {*} {Promise<void>}
818
1021
  * @memberof MemoryStore
819
1022
  */
820
- release(conn: any): Promise<void>;
1023
+ release(_conn: any): Promise<void>;
821
1024
  /**
822
1025
  * defineCommand
823
1026
  *
824
- * @param {string} name
825
- * @param {*} scripts
1027
+ * @param {string} _name
1028
+ * @param {*} _scripts
826
1029
  * @memberof MemoryStore
827
1030
  */
828
- defineCommand(name: string, scripts: any): Promise<void>;
1031
+ defineCommand(_name: string, _scripts: any): Promise<void>;
829
1032
  /**
830
1033
  * get and compare value
831
1034
  *
@@ -835,6 +1038,10 @@ declare class MemoryStore implements CacheStoreInterface {
835
1038
  * @memberof MemoryStore
836
1039
  */
837
1040
  getCompare(name: string, value: string | number): Promise<any>;
1041
+ /**
1042
+ * 获取缓存统计信息
1043
+ */
1044
+ getStats(): any;
838
1045
  }
839
1046
 
840
1047
  declare interface MemoryStoreOpt {
@@ -842,6 +1049,10 @@ declare interface MemoryStoreOpt {
842
1049
  keyPrefix?: string;
843
1050
  db?: number;
844
1051
  timeout?: number;
1052
+ maxKeys?: number;
1053
+ maxMemory?: number;
1054
+ evictionPolicy?: 'lru' | 'lfu' | 'random';
1055
+ ttlCheckInterval?: number;
845
1056
  }
846
1057
 
847
1058
  /**
@@ -861,21 +1072,26 @@ declare class RedisStore implements CacheStoreInterface {
861
1072
  */
862
1073
  constructor(options: RedisStoreOpt);
863
1074
  /**
864
- * create connection by native
1075
+ * create connection by native with improved error handling
865
1076
  *
866
1077
  * @param {number} [connNum=0]
867
1078
  * @returns {*} {Promise<Redis | Cluster>}
868
1079
  * @memberof RedisStore
869
1080
  */
870
1081
  /**
871
- * get connection from pool
1082
+ * 计划重连,使用指数退避策略
1083
+ * @private
1084
+ * @param {number} connNum
1085
+ */
1086
+ /**
1087
+ * get connection from pool with improved configuration
872
1088
  *
873
1089
  * @returns {*}
874
1090
  * @memberof RedisStore
875
1091
  */
876
1092
  getConnection(): Promise<Cluster | Redis>;
877
1093
  /**
878
- * close connection
1094
+ * close connection with proper cleanup
879
1095
  *
880
1096
  * @returns {*}
881
1097
  * @memberof RedisStore