feat(xo-server/collection/redis#_get): return undefined if missing

Related to #7281
This commit is contained in:
Julien Fontanet 2024-01-05 13:52:45 +01:00
parent 0f00c7e393
commit 9be3c40ead

View File

@ -192,12 +192,21 @@ export default class Redis extends Collection {
)
}
/**
* Fetches the record in the database
*
* Returns undefined if not present.
*/
async #get(key) {
const { redis } = this
let model
try {
model = await redis.get(key).then(JSON.parse)
const json = await redis.get(key)
if (json !== null) {
model = JSON.parse(json)
}
} catch (error) {
if (!error.message.startsWith('WRONGTYPE')) {
throw error