mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-11 07:40:26 +08:00
refactor: optimize redis operation
This commit is contained in:
@@ -38,20 +38,16 @@ module.exports = function(app, options = {}) {
|
|||||||
if (key && available) {
|
if (key && available) {
|
||||||
let value = await redisClient.get(key);
|
let value = await redisClient.get(key);
|
||||||
if (value) {
|
if (value) {
|
||||||
await redisClient.expire(key, config.cache.contentExpire);
|
redisClient.expire(key, config.cache.contentExpire);
|
||||||
value = value + '';
|
value = value + '';
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
set: async function(key, value, maxAge = config.cache.contentExpire) {
|
set: function(key, value, maxAge = config.cache.contentExpire) {
|
||||||
if (!available) {
|
if (!available) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (await redisClient.exists(key)) {
|
|
||||||
logger.warn(`repeated key: ${key}, ${value}`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!value || value === 'undefined') {
|
if (!value || value === 'undefined') {
|
||||||
value = '';
|
value = '';
|
||||||
}
|
}
|
||||||
@@ -59,7 +55,7 @@ module.exports = function(app, options = {}) {
|
|||||||
value = JSON.stringify(value);
|
value = JSON.stringify(value);
|
||||||
}
|
}
|
||||||
if (key) {
|
if (key) {
|
||||||
await redisClient.setex(key, maxAge, value);
|
redisClient.setex(key, maxAge, value);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
client: redisClient,
|
client: redisClient,
|
||||||
|
|||||||
Reference in New Issue
Block a user