node-karin 0.7.0 → 0.7.1
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/lib/db/redis_level.d.ts +5 -9
- package/lib/db/redis_level.js +18 -15
- package/package.json +1 -1
package/lib/db/redis_level.d.ts
CHANGED
|
@@ -10,25 +10,21 @@ export default class RedisLevel {
|
|
|
10
10
|
get(key: string): Promise<string | null>;
|
|
11
11
|
/**
|
|
12
12
|
* set 设置数据
|
|
13
|
-
* @param
|
|
14
|
-
* @param
|
|
15
|
-
* @param
|
|
16
|
-
* @param [options.EX] 过期时间 单位秒
|
|
17
|
-
* @returns {Promise<void>|Error}
|
|
13
|
+
* @param key 键
|
|
14
|
+
* @param value 值
|
|
15
|
+
* @param options 选项
|
|
18
16
|
*/
|
|
19
17
|
set(key: string, value: string, options?: {
|
|
20
18
|
EX: number;
|
|
21
19
|
} | undefined): Promise<void>;
|
|
22
20
|
/**
|
|
23
21
|
* del 删除数据
|
|
24
|
-
* @param
|
|
25
|
-
* @returns {Promise<void>|Error}
|
|
22
|
+
* @param key 键
|
|
26
23
|
*/
|
|
27
24
|
del(key: string): Promise<void>;
|
|
28
25
|
/**
|
|
29
26
|
* keys 获取所有键
|
|
30
|
-
* @param
|
|
31
|
-
* @returns {Promise<string[]>|Error} 键列表
|
|
27
|
+
* @param prefix 前缀
|
|
32
28
|
*/
|
|
33
29
|
keys(prefix?: string): Promise<string[]>;
|
|
34
30
|
/**
|
package/lib/db/redis_level.js
CHANGED
|
@@ -89,11 +89,9 @@ export default class RedisLevel {
|
|
|
89
89
|
|
|
90
90
|
/**
|
|
91
91
|
* set 设置数据
|
|
92
|
-
* @param
|
|
93
|
-
* @param
|
|
94
|
-
* @param
|
|
95
|
-
* @param [options.EX] 过期时间 单位秒
|
|
96
|
-
* @returns {Promise<void>|Error}
|
|
92
|
+
* @param key 键
|
|
93
|
+
* @param value 值
|
|
94
|
+
* @param options 选项
|
|
97
95
|
*/
|
|
98
96
|
async set (key, value, options) {
|
|
99
97
|
if (options && options.EX) {
|
|
@@ -104,8 +102,7 @@ export default class RedisLevel {
|
|
|
104
102
|
|
|
105
103
|
/**
|
|
106
104
|
* del 删除数据
|
|
107
|
-
* @param
|
|
108
|
-
* @returns {Promise<void>|Error}
|
|
105
|
+
* @param key 键
|
|
109
106
|
*/
|
|
110
107
|
async del (key) {
|
|
111
108
|
this.#expireMap.delete(key)
|
|
@@ -114,22 +111,28 @@ export default class RedisLevel {
|
|
|
114
111
|
|
|
115
112
|
/**
|
|
116
113
|
* keys 获取所有键
|
|
117
|
-
* @param
|
|
118
|
-
* @returns {Promise<string[]>|Error} 键列表
|
|
114
|
+
* @param prefix 前缀
|
|
119
115
|
*/
|
|
120
116
|
async keys (prefix = '') {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
117
|
+
/** 去掉末尾的* */
|
|
118
|
+
prefix = prefix.replace(/\*$/, '')
|
|
119
|
+
const list = await this.#level.keys({ gte: prefix, lt: `${prefix}\xFF` }).all()
|
|
120
|
+
this.#checkKeys(list)
|
|
121
|
+
return list
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* 给一个kyes 检查是否过期
|
|
126
|
+
* @param keys 键数组
|
|
127
|
+
*/
|
|
128
|
+
async #checkKeys (keys) {
|
|
129
|
+
for (const key of keys) {
|
|
124
130
|
const expire = this.#expireMap.get(key)
|
|
125
131
|
if (expire && expire < Date.now()) {
|
|
126
132
|
await this.#level.del(key)
|
|
127
133
|
this.#expireMap.delete(key)
|
|
128
|
-
} else {
|
|
129
|
-
keys.push(key)
|
|
130
134
|
}
|
|
131
135
|
}
|
|
132
|
-
return keys
|
|
133
136
|
}
|
|
134
137
|
|
|
135
138
|
/**
|