mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-07 21:47:57 +08:00
test: redis with quit and error cases
This commit is contained in:
@@ -35,7 +35,7 @@ module.exports = function(app, options = {}) {
|
||||
|
||||
app.context.cache = {
|
||||
get: async (key) => {
|
||||
if (key) {
|
||||
if (key && available) {
|
||||
let value = await redisClient.get(key);
|
||||
if (value) {
|
||||
await redisClient.expire(key, config.cache.contentExpire);
|
||||
@@ -45,6 +45,9 @@ module.exports = function(app, options = {}) {
|
||||
}
|
||||
},
|
||||
set: async function(key, value, maxAge = config.cache.contentExpire) {
|
||||
if (!available) {
|
||||
return;
|
||||
}
|
||||
if (await redisClient.exists(key)) {
|
||||
logger.warn(`repeated key: ${key}, ${value}`);
|
||||
return;
|
||||
@@ -59,9 +62,10 @@ module.exports = function(app, options = {}) {
|
||||
await redisClient.setex(key, maxAge, value);
|
||||
}
|
||||
},
|
||||
client: redisClient,
|
||||
};
|
||||
globalCache.get = async (key) => {
|
||||
if (key) {
|
||||
if (key && available) {
|
||||
const value = await redisClient.get(key);
|
||||
return value;
|
||||
}
|
||||
@@ -81,7 +85,7 @@ module.exports = function(app, options = {}) {
|
||||
|
||||
app.context.cache = {
|
||||
get: (key) => {
|
||||
if (key) {
|
||||
if (key && available) {
|
||||
let value = routeCache.get(key);
|
||||
if (value) {
|
||||
value = value + '';
|
||||
@@ -96,13 +100,14 @@ module.exports = function(app, options = {}) {
|
||||
if (typeof value === 'object') {
|
||||
value = JSON.stringify(value);
|
||||
}
|
||||
if (key) {
|
||||
if (key && available) {
|
||||
return routeCache.set(key, value, maxAge * 1000);
|
||||
}
|
||||
},
|
||||
client: [pageCache, routeCache],
|
||||
};
|
||||
globalCache.get = (key) => {
|
||||
if (key) {
|
||||
if (key && available) {
|
||||
return pageCache.get(key);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user