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.
@@ -10,25 +10,21 @@ export default class RedisLevel {
10
10
  get(key: string): Promise<string | null>;
11
11
  /**
12
12
  * set 设置数据
13
- * @param {string} key 键
14
- * @param {string} value 值
15
- * @param {object} [options] 选项
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 {string} key 键
25
- * @returns {Promise<void>|Error}
22
+ * @param key 键
26
23
  */
27
24
  del(key: string): Promise<void>;
28
25
  /**
29
26
  * keys 获取所有键
30
- * @param {string} [prefix] 前缀
31
- * @returns {Promise<string[]>|Error} 键列表
27
+ * @param prefix 前缀
32
28
  */
33
29
  keys(prefix?: string): Promise<string[]>;
34
30
  /**
@@ -89,11 +89,9 @@ export default class RedisLevel {
89
89
 
90
90
  /**
91
91
  * set 设置数据
92
- * @param {string} key 键
93
- * @param {string} value 值
94
- * @param {object} [options] 选项
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 {string} key 键
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 {string} [prefix] 前缀
118
- * @returns {Promise<string[]>|Error} 键列表
114
+ * @param prefix 前缀
119
115
  */
120
116
  async keys (prefix = '') {
121
- const keys = []
122
- for await (const key of this.#level.keys({ gte: prefix, lt: prefix + '\xFF' })) {
123
- // Check if the key has expired
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
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-karin",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "private": false,
5
5
  "description": "基于 Kritor 进行开发的nodejs机器人框架",
6
6
  "homepage": "https://github.com/KarinJS/Karin",