Added a method to get all raw keys in the redis cache adapter

This allows for easy access to the raw, unprocessed, keys that a site has
stored in the cache. These include all key prefixes.
This commit is contained in:
Joe Grigg 2023-03-13 09:20:36 +00:00 committed by Fabien 'egg' O'Carroll
parent ed38760c6d
commit a50ef81148

View File

@ -83,6 +83,14 @@ class AdapterCacheRedis extends BaseCacheAdapter {
}); });
} }
async #getKeys() {
const primaryNode = this.#getPrimaryRedisNode();
if (primaryNode === null) {
return [];
}
return await this.#scanNodeForKeys(primaryNode);
}
/** /**
* This is a recommended way to build cache key prefixes from * This is a recommended way to build cache key prefixes from
* the cache-manager package. Might be a good contribution to make * the cache-manager package. Might be a good contribution to make
@ -144,12 +152,7 @@ class AdapterCacheRedis extends BaseCacheAdapter {
*/ */
async keys() { async keys() {
try { try {
const primaryNode = this.#getPrimaryRedisNode(); return (await this.#getKeys()).map((key) => {
if (primaryNode === null) {
return [];
}
const rawKeys = await this.#scanNodeForKeys(primaryNode);
return rawKeys.map((key) => {
return this._removeKeyPrefix(key); return this._removeKeyPrefix(key);
}); });
} catch (err) { } catch (err) {