mobiletto 1.1.23 → 1.1.25
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/package.json +1 -1
- package/util/redis.js +19 -8
package/package.json
CHANGED
package/util/redis.js
CHANGED
|
@@ -119,7 +119,7 @@ class MobilettoCache {
|
|
|
119
119
|
|
|
120
120
|
findMatchingKeys = async (pattern) => {
|
|
121
121
|
return await new Promise((resolve, reject) => {
|
|
122
|
-
this.scanner.scan(pattern, (err, matchingKeys) => {
|
|
122
|
+
this.scanner.scan(this.pfx(pattern), (err, matchingKeys) => {
|
|
123
123
|
if (err) reject(err)
|
|
124
124
|
resolve(matchingKeys)
|
|
125
125
|
})
|
|
@@ -128,36 +128,47 @@ class MobilettoCache {
|
|
|
128
128
|
|
|
129
129
|
applyToMatchingKeys = async (pattern, asyncFunc) => {
|
|
130
130
|
const results = []
|
|
131
|
+
let keyMatchCount = 0
|
|
132
|
+
const logPrefix = `applyToMatchingKeys(${pattern}, ${asyncFunc && asyncFunc.name ? asyncFunc.name : 'nameless function'})`
|
|
133
|
+
const start = Date.now()
|
|
131
134
|
return await new Promise((resolve, reject) => {
|
|
132
|
-
this.scanner.eachScan(pattern, {}, async (matchingKeys) => {
|
|
135
|
+
this.scanner.eachScan(this.pfx(pattern), {}, async (matchingKeys) => {
|
|
136
|
+
if (!matchingKeys || typeof matchingKeys.length !== 'number') {
|
|
137
|
+
const message = `${logPrefix}: eachScan received invalid matchingKeys = ${typeof matchingKeys !== 'undefined' ? matchingKeys : 'undefined'}`;
|
|
138
|
+
logger.error(message)
|
|
139
|
+
reject(message)
|
|
140
|
+
} else {
|
|
141
|
+
keyMatchCount += matchingKeys.length
|
|
142
|
+
}
|
|
133
143
|
for (const key of matchingKeys) {
|
|
134
144
|
asyncFunc(key).then(
|
|
135
145
|
(val) => {
|
|
136
146
|
if (typeof val !== 'undefined') {
|
|
137
|
-
logger.
|
|
147
|
+
logger.silly(`${logPrefix} found key ${key} = ${val}`)
|
|
138
148
|
results.push(val)
|
|
139
149
|
} else {
|
|
140
|
-
logger.
|
|
150
|
+
logger.silly(`${logPrefix} found key with undefined value: ${key}`)
|
|
141
151
|
}
|
|
142
152
|
},
|
|
143
153
|
(e) => {
|
|
144
|
-
const message =
|
|
154
|
+
const message = `${logPrefix} error with key ${key}: ${e}`;
|
|
145
155
|
logger.error(message)
|
|
146
156
|
reject(message)
|
|
147
157
|
})
|
|
148
158
|
}
|
|
149
159
|
}, (err, matchCount) => {
|
|
150
160
|
if (err) {
|
|
151
|
-
logger.error(
|
|
161
|
+
logger.error(`${logPrefix} error in final callback: ${err}`)
|
|
152
162
|
reject(err)
|
|
153
163
|
}
|
|
154
|
-
|
|
164
|
+
const duration = Date.now() - start
|
|
165
|
+
logger.debug(`${logPrefix} resolving with matchCount=${matchCount}, keyMatchCount=${keyMatchCount}, results.length=${results.length}, duration ${duration/1000} seconds`)
|
|
155
166
|
resolve(results)
|
|
156
167
|
})
|
|
157
168
|
})
|
|
158
169
|
}
|
|
159
170
|
|
|
160
|
-
removeMatchingKeys = async
|
|
171
|
+
removeMatchingKeys = async pattern => await this.applyToMatchingKeys(pattern, this.del)
|
|
161
172
|
|
|
162
173
|
flush = async () => {
|
|
163
174
|
this.counters.flush++
|