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