mobiletto 1.1.24 → 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 +17 -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,38 +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'})`
|
|
131
133
|
const start = Date.now()
|
|
132
134
|
return await new Promise((resolve, reject) => {
|
|
133
|
-
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
|
+
}
|
|
134
143
|
for (const key of matchingKeys) {
|
|
135
144
|
asyncFunc(key).then(
|
|
136
145
|
(val) => {
|
|
137
146
|
if (typeof val !== 'undefined') {
|
|
138
|
-
logger.silly(
|
|
147
|
+
logger.silly(`${logPrefix} found key ${key} = ${val}`)
|
|
139
148
|
results.push(val)
|
|
140
149
|
} else {
|
|
141
|
-
logger.silly(
|
|
150
|
+
logger.silly(`${logPrefix} found key with undefined value: ${key}`)
|
|
142
151
|
}
|
|
143
152
|
},
|
|
144
153
|
(e) => {
|
|
145
|
-
const message =
|
|
154
|
+
const message = `${logPrefix} error with key ${key}: ${e}`;
|
|
146
155
|
logger.error(message)
|
|
147
156
|
reject(message)
|
|
148
157
|
})
|
|
149
158
|
}
|
|
150
159
|
}, (err, matchCount) => {
|
|
151
160
|
if (err) {
|
|
152
|
-
logger.error(
|
|
161
|
+
logger.error(`${logPrefix} error in final callback: ${err}`)
|
|
153
162
|
reject(err)
|
|
154
163
|
}
|
|
155
164
|
const duration = Date.now() - start
|
|
156
|
-
logger.debug(
|
|
165
|
+
logger.debug(`${logPrefix} resolving with matchCount=${matchCount}, keyMatchCount=${keyMatchCount}, results.length=${results.length}, duration ${duration/1000} seconds`)
|
|
157
166
|
resolve(results)
|
|
158
167
|
})
|
|
159
168
|
})
|
|
160
169
|
}
|
|
161
170
|
|
|
162
|
-
removeMatchingKeys = async
|
|
171
|
+
removeMatchingKeys = async pattern => await this.applyToMatchingKeys(pattern, this.del)
|
|
163
172
|
|
|
164
173
|
flush = async () => {
|
|
165
174
|
this.counters.flush++
|