koatty_store 1.7.0 → 1.9.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: 2024-11-07 14:39:13
3
+ * @Date: 2025-11-02 08:37:37
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
  /**
@@ -32,17 +29,40 @@ export declare class CacheStore {
32
29
  */
33
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<default_2 | Cluster>;
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,26 @@ 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
+ */
355
+ /**
356
+ * 清理所有资源
357
+ * @private
358
+ */
296
359
  /**
297
360
  *
298
361
  *
@@ -314,6 +377,13 @@ declare class MemoryCache extends EventEmitter {
314
377
  * @memberof MemoryCache
315
378
  */
316
379
  end(): this;
380
+ /**
381
+ * 获取缓存统计信息
382
+ */
383
+ info(): any;
384
+ /**
385
+ * 估算内存使用量
386
+ */
317
387
  /**
318
388
  *
319
389
  *
@@ -322,7 +392,7 @@ declare class MemoryCache extends EventEmitter {
322
392
  * @returns {*}
323
393
  * @memberof MemoryCache
324
394
  */
325
- echo(message: string, callback?: Function): any;
395
+ echo(message: string, callback?: CallbackFunction): any;
326
396
  /**
327
397
  *
328
398
  *
@@ -331,7 +401,7 @@ declare class MemoryCache extends EventEmitter {
331
401
  * @returns {*}
332
402
  * @memberof MemoryCache
333
403
  */
334
- ping(message: string, callback?: Function): any;
404
+ ping(message: string, callback?: CallbackFunction): any;
335
405
  /**
336
406
  *
337
407
  *
@@ -340,7 +410,7 @@ declare class MemoryCache extends EventEmitter {
340
410
  * @returns {*}
341
411
  * @memberof MemoryCache
342
412
  */
343
- auth(password: string, callback?: Function): any;
413
+ auth(password: string, callback?: CallbackFunction): any;
344
414
  /**
345
415
  *
346
416
  *
@@ -349,8 +419,8 @@ declare class MemoryCache extends EventEmitter {
349
419
  * @returns {*}
350
420
  * @memberof MemoryCache
351
421
  */
352
- select(dbIndex: number, callback?: Function): any;
353
- get(key: string, callback?: Function): any;
422
+ select(dbIndex: number, callback?: CallbackFunction): any;
423
+ get(key: string, callback?: CallbackFunction): any;
354
424
  /**
355
425
  * set(key, value, ttl, pttl, notexist, onlyexist, callback)
356
426
  *
@@ -369,7 +439,7 @@ declare class MemoryCache extends EventEmitter {
369
439
  * @returns {*}
370
440
  * @memberof MemoryCache
371
441
  */
372
- ttl(key: string, callback?: Function): any;
442
+ ttl(key: string, callback?: CallbackFunction): any;
373
443
  /**
374
444
  *
375
445
  *
@@ -379,7 +449,7 @@ declare class MemoryCache extends EventEmitter {
379
449
  * @returns {*}
380
450
  * @memberof MemoryCache
381
451
  */
382
- expire(key: string, seconds: number, callback?: Function): any;
452
+ expire(key: string, seconds: number, callback?: CallbackFunction): any;
383
453
  /**
384
454
  *
385
455
  *
@@ -404,7 +474,7 @@ declare class MemoryCache extends EventEmitter {
404
474
  * @returns {*}
405
475
  * @memberof MemoryCache
406
476
  */
407
- incr(key: string, callback?: Function): any;
477
+ incr(key: string, callback?: CallbackFunction): Promise<any>;
408
478
  /**
409
479
  *
410
480
  *
@@ -414,7 +484,7 @@ declare class MemoryCache extends EventEmitter {
414
484
  * @returns {*}
415
485
  * @memberof MemoryCache
416
486
  */
417
- incrby(key: string, amount: number, callback?: Function): any;
487
+ incrby(key: string, amount: number, callback?: CallbackFunction): Promise<any>;
418
488
  /**
419
489
  *
420
490
  *
@@ -423,7 +493,7 @@ declare class MemoryCache extends EventEmitter {
423
493
  * @returns {*}
424
494
  * @memberof MemoryCache
425
495
  */
426
- decr(key: string, callback?: Function): any;
496
+ decr(key: string, callback?: CallbackFunction): Promise<any>;
427
497
  /**
428
498
  *
429
499
  *
@@ -433,8 +503,8 @@ declare class MemoryCache extends EventEmitter {
433
503
  * @returns {*}
434
504
  * @memberof MemoryCache
435
505
  */
436
- decrby(key: string, amount: number, callback?: Function): any;
437
- hset(key: string, field: string, value: string | number, callback?: Function): any;
506
+ decrby(key: string, amount: number, callback?: CallbackFunction): Promise<any>;
507
+ hset(key: string, field: string, value: string | number, timeout?: number, callback?: CallbackFunction): any;
438
508
  /**
439
509
  *
440
510
  *
@@ -444,7 +514,7 @@ declare class MemoryCache extends EventEmitter {
444
514
  * @returns {*}
445
515
  * @memberof MemoryCache
446
516
  */
447
- hget(key: string, field: string, callback?: Function): any;
517
+ hget(key: string, field: string, callback?: CallbackFunction): any;
448
518
  /**
449
519
  *
450
520
  *
@@ -454,7 +524,7 @@ declare class MemoryCache extends EventEmitter {
454
524
  * @returns {*}
455
525
  * @memberof MemoryCache
456
526
  */
457
- hexists(key: string, field: string, callback?: Function): any;
527
+ hexists(key: string, field: string, callback?: CallbackFunction): any;
458
528
  /**
459
529
  *
460
530
  *
@@ -472,7 +542,7 @@ declare class MemoryCache extends EventEmitter {
472
542
  * @returns {*}
473
543
  * @memberof MemoryCache
474
544
  */
475
- hlen(key: string, callback?: Function): any;
545
+ hlen(key: string, callback?: CallbackFunction): any;
476
546
  /**
477
547
  *
478
548
  *
@@ -483,7 +553,7 @@ declare class MemoryCache extends EventEmitter {
483
553
  * @returns {*}
484
554
  * @memberof MemoryCache
485
555
  */
486
- hincrby(key: string, field: string, value: any, callback?: Function): any;
556
+ hincrby(key: string, field: string, value: any, callback?: CallbackFunction): Promise<any>;
487
557
  /**
488
558
  *
489
559
  *
@@ -492,7 +562,7 @@ declare class MemoryCache extends EventEmitter {
492
562
  * @returns {*}
493
563
  * @memberof MemoryCache
494
564
  */
495
- hgetall(key: string, callback?: Function): any;
565
+ hgetall(key: string, callback?: CallbackFunction): any;
496
566
  /**
497
567
  *
498
568
  *
@@ -501,7 +571,7 @@ declare class MemoryCache extends EventEmitter {
501
571
  * @returns {*}
502
572
  * @memberof MemoryCache
503
573
  */
504
- hkeys(key: string, callback?: Function): any;
574
+ hkeys(key: string, callback?: CallbackFunction): any;
505
575
  /**
506
576
  *
507
577
  *
@@ -510,7 +580,7 @@ declare class MemoryCache extends EventEmitter {
510
580
  * @returns {*}
511
581
  * @memberof MemoryCache
512
582
  */
513
- hvals(key: string, callback?: Function): any;
583
+ hvals(key: string, callback?: CallbackFunction): any;
514
584
  /**
515
585
  *
516
586
  *
@@ -519,7 +589,7 @@ declare class MemoryCache extends EventEmitter {
519
589
  * @returns {*}
520
590
  * @memberof MemoryCache
521
591
  */
522
- llen(key: string, callback?: Function): any;
592
+ llen(key: string, callback?: CallbackFunction): any;
523
593
  /**
524
594
  *
525
595
  *
@@ -529,17 +599,21 @@ declare class MemoryCache extends EventEmitter {
529
599
  * @returns {*}
530
600
  * @memberof MemoryCache
531
601
  */
532
- rpush(key: string, value: string | number, callback?: Function): any;
602
+ rpush(key: string, value: string | number, callback?: CallbackFunction): any;
533
603
  /**
534
- *
535
- *
536
- * @param {string} key
537
- * @param {(string | number)} value
538
- * @param {Function} [callback]
539
- * @returns {*}
540
- * @memberof MemoryCache
604
+ * List:从左侧推入
605
+ * @param key
606
+ * @param value
607
+ * @param callback
608
+ */
609
+ lpush(key: string, value: any, callback?: CallbackFunction): any;
610
+ /**
611
+ * List:获取指定索引的元素
612
+ * @param key
613
+ * @param index
614
+ * @param callback
541
615
  */
542
- lpush(key: string, value: string | number, callback?: Function): any;
616
+ lindex(key: string, index: number, callback?: CallbackFunction): any;
543
617
  /**
544
618
  *
545
619
  *
@@ -548,7 +622,7 @@ declare class MemoryCache extends EventEmitter {
548
622
  * @returns {*}
549
623
  * @memberof MemoryCache
550
624
  */
551
- lpop(key: string, callback?: Function): any;
625
+ lpop(key: string, callback?: CallbackFunction): any;
552
626
  /**
553
627
  *
554
628
  *
@@ -557,7 +631,7 @@ declare class MemoryCache extends EventEmitter {
557
631
  * @returns {*}
558
632
  * @memberof MemoryCache
559
633
  */
560
- rpop(key: string, callback?: Function): any;
634
+ rpop(key: string, callback?: CallbackFunction): any;
561
635
  /**
562
636
  *
563
637
  *
@@ -568,7 +642,7 @@ declare class MemoryCache extends EventEmitter {
568
642
  * @returns {*}
569
643
  * @memberof MemoryCache
570
644
  */
571
- lrange(key: string, start: number, stop: number, callback?: Function): any;
645
+ lrange(key: string, start: number, stop: number, callback?: CallbackFunction): any;
572
646
  /**
573
647
  *
574
648
  *
@@ -586,7 +660,7 @@ declare class MemoryCache extends EventEmitter {
586
660
  * @returns {*}
587
661
  * @memberof MemoryCache
588
662
  */
589
- scard(key: string, callback?: Function): any;
663
+ scard(key: string, callback?: CallbackFunction): any;
590
664
  /**
591
665
  *
592
666
  *
@@ -596,7 +670,7 @@ declare class MemoryCache extends EventEmitter {
596
670
  * @returns {*}
597
671
  * @memberof MemoryCache
598
672
  */
599
- sismember(key: string, member: string, callback?: Function): any;
673
+ sismember(key: string, member: string, callback?: CallbackFunction): any;
600
674
  /**
601
675
  *
602
676
  *
@@ -605,7 +679,7 @@ declare class MemoryCache extends EventEmitter {
605
679
  * @returns {*}
606
680
  * @memberof MemoryCache
607
681
  */
608
- smembers(key: string, callback?: Function): any;
682
+ smembers(key: string, callback?: CallbackFunction): any;
609
683
  /**
610
684
  *
611
685
  *
@@ -615,7 +689,7 @@ declare class MemoryCache extends EventEmitter {
615
689
  * @returns {*}
616
690
  * @memberof MemoryCache
617
691
  */
618
- spop(key: string, count?: number, callback?: Function): any;
692
+ spop(key: string, count?: number, callback?: CallbackFunction): any;
619
693
  /**
620
694
  *
621
695
  *
@@ -635,8 +709,8 @@ declare class MemoryCache extends EventEmitter {
635
709
  * @returns {*}
636
710
  * @memberof MemoryCache
637
711
  */
638
- smove(sourcekey: string, destkey: string, member: string, callback?: Function): any;
639
- discard(callback?: Function, silent?: boolean): any;
712
+ smove(sourcekey: string, destkey: string, member: string, callback?: CallbackFunction): any;
713
+ discard(callback?: CallbackFunction, silent?: boolean): any;
640
714
  /**
641
715
  *
642
716
  *
@@ -775,6 +849,134 @@ declare class MemoryCache extends EventEmitter {
775
849
  * @returns {*}
776
850
  * @memberof MemoryCache
777
851
  */
852
+ /**
853
+ * 字符串追加操作
854
+ * @param key
855
+ * @param value
856
+ * @param callback
857
+ */
858
+ append(key: string, value: string, callback?: CallbackFunction): any;
859
+ /**
860
+ * 获取字符串长度
861
+ * @param key
862
+ * @param callback
863
+ */
864
+ strlen(key: string, callback?: CallbackFunction): any;
865
+ /**
866
+ * 获取子字符串
867
+ * @param key
868
+ * @param start
869
+ * @param end
870
+ * @param callback
871
+ */
872
+ getrange(key: string, start: number, end: number, callback?: CallbackFunction): any;
873
+ /**
874
+ * 设置子字符串
875
+ * @param key
876
+ * @param offset
877
+ * @param value
878
+ * @param callback
879
+ */
880
+ setrange(key: string, offset: number, value: string, callback?: CallbackFunction): any;
881
+ /**
882
+ * 批量获取
883
+ * @param keys
884
+ * @param callback
885
+ */
886
+ mget(...keys: any[]): any;
887
+ /**
888
+ * 批量设置
889
+ * @param keyValuePairs
890
+ * @param callback
891
+ */
892
+ mset(...keyValuePairs: any[]): any;
893
+ /**
894
+ * 获取所有键
895
+ * @param pattern
896
+ * @param callback
897
+ */
898
+ keys(pattern?: string, callback?: CallbackFunction): any;
899
+ /**
900
+ * 简单的模式匹配
901
+ * @param key
902
+ * @param pattern
903
+ */
904
+ /**
905
+ * 获取随机键
906
+ * @param callback
907
+ */
908
+ randomkey(callback?: CallbackFunction): any;
909
+ /**
910
+ * 重命名键
911
+ * @param oldKey
912
+ * @param newKey
913
+ * @param callback
914
+ */
915
+ rename(oldKey: string, newKey: string, callback?: CallbackFunction): any;
916
+ /**
917
+ * 安全重命名键(目标键不存在时才重命名)
918
+ * @param oldKey
919
+ * @param newKey
920
+ * @param callback
921
+ */
922
+ renamenx(oldKey: string, newKey: string, callback?: CallbackFunction): any;
923
+ /**
924
+ * 获取键的类型
925
+ * @param key
926
+ * @param callback
927
+ */
928
+ type(key: string, callback?: CallbackFunction): any;
929
+ /**
930
+ * 清空当前数据库
931
+ * @param callback
932
+ */
933
+ flushdb(callback?: CallbackFunction): any;
934
+ /**
935
+ * 清空所有数据库
936
+ * @param callback
937
+ */
938
+ flushall(callback?: CallbackFunction): any;
939
+ /**
940
+ * 获取数据库大小
941
+ * @param callback
942
+ */
943
+ dbsize(callback?: CallbackFunction): any;
944
+ /**
945
+ * Sorted Set基础实现 - 添加成员
946
+ * @param key
947
+ * @param score
948
+ * @param member
949
+ * @param callback
950
+ */
951
+ zadd(key: string, score: number, member: string, callback?: CallbackFunction): any;
952
+ /**
953
+ * Sorted Set - 获取成员分数
954
+ * @param key
955
+ * @param member
956
+ * @param callback
957
+ */
958
+ zscore(key: string, member: string, callback?: CallbackFunction): any;
959
+ /**
960
+ * Sorted Set - 获取范围内的成员
961
+ * @param key
962
+ * @param start
963
+ * @param stop
964
+ * @param callback
965
+ */
966
+ zrange(key: string, start: number, stop: number, callback?: CallbackFunction): any;
967
+ /**
968
+ * Sorted Set - 获取成员数量
969
+ * @param key
970
+ * @param callback
971
+ */
972
+ zcard(key: string, callback?: CallbackFunction): any;
973
+ /**
974
+ * Sorted Set - 删除成员
975
+ * @param key
976
+ * @param member
977
+ * @param callback
978
+ */
979
+ zrem(key: string, member: string, callback?: CallbackFunction): any;
778
980
  }
779
981
 
780
982
  /**
@@ -784,11 +986,15 @@ declare class MemoryCache extends EventEmitter {
784
986
  */
785
987
  declare interface MemoryCacheOptions {
786
988
  database: number;
989
+ maxKeys?: number;
990
+ maxMemory?: number;
991
+ evictionPolicy?: 'lru' | 'lfu' | 'random';
992
+ ttlCheckInterval?: number;
993
+ maxAge?: number;
787
994
  }
788
995
 
789
- declare class MemoryStore implements CacheStoreInterface {
790
- client: any;
791
- pool: any;
996
+ declare class MemoryStore {
997
+ client: MemoryCache;
792
998
  options: MemoryStoreOpt;
793
999
  /**
794
1000
  * Creates an instance of MemoryStore.
@@ -835,6 +1041,10 @@ declare class MemoryStore implements CacheStoreInterface {
835
1041
  * @memberof MemoryStore
836
1042
  */
837
1043
  getCompare(name: string, value: string | number): Promise<any>;
1044
+ /**
1045
+ * 获取缓存统计信息
1046
+ */
1047
+ getStats(): any;
838
1048
  }
839
1049
 
840
1050
  declare interface MemoryStoreOpt {
@@ -842,6 +1052,10 @@ declare interface MemoryStoreOpt {
842
1052
  keyPrefix?: string;
843
1053
  db?: number;
844
1054
  timeout?: number;
1055
+ maxKeys?: number;
1056
+ maxMemory?: number;
1057
+ evictionPolicy?: 'lru' | 'lfu' | 'random';
1058
+ ttlCheckInterval?: number;
845
1059
  }
846
1060
 
847
1061
  /**
@@ -850,7 +1064,7 @@ declare interface MemoryStoreOpt {
850
1064
  * @export
851
1065
  * @class RedisStore
852
1066
  */
853
- declare class RedisStore implements CacheStoreInterface {
1067
+ declare class RedisStore {
854
1068
  options: RedisStoreOpt;
855
1069
  pool: genericPool.Pool<Redis | Cluster>;
856
1070
  client: Redis | Cluster;
@@ -861,21 +1075,26 @@ declare class RedisStore implements CacheStoreInterface {
861
1075
  */
862
1076
  constructor(options: RedisStoreOpt);
863
1077
  /**
864
- * create connection by native
1078
+ * create connection by native with improved error handling
865
1079
  *
866
1080
  * @param {number} [connNum=0]
867
1081
  * @returns {*} {Promise<Redis | Cluster>}
868
1082
  * @memberof RedisStore
869
1083
  */
870
1084
  /**
871
- * get connection from pool
1085
+ * 计划重连,使用指数退避策略
1086
+ * @private
1087
+ * @param {number} connNum
1088
+ */
1089
+ /**
1090
+ * get connection from pool with improved configuration
872
1091
  *
873
1092
  * @returns {*}
874
1093
  * @memberof RedisStore
875
1094
  */
876
- getConnection(): Promise<Cluster | Redis>;
1095
+ getConnection(): Promise<Redis | Cluster>;
877
1096
  /**
878
- * close connection
1097
+ * close connection with proper cleanup
879
1098
  *
880
1099
  * @returns {*}
881
1100
  * @memberof RedisStore