问题描述
我需要具有3个不同的redis数据库,所以我有3个不同的redis客户端,如下所示:
const gCDCache = redis.createClient();
const CDCache = redis.createClient();
const vcsCache = redis.createClient();
我需要前2个缓存不持久,因为它们只是冷却缓存。 相反,第三个缓存需要保留,因为它包含一些重要数据。
是否可以在不同的客户端之间使用不同的持久性策略?
最好的方法是什么?
我在网上搜索了一下,但找不到答案,对此表示感谢,谢谢。
对于上下文,这是我的caches.js文件(那里有4个缓存):
// Bot redis caches
const redis = require("redis");
const { promisify } = require("util");
// Global Cooldown cache
const gCDCache = redis.createClient();
const setGCD = promisify(gCDCache.set).bind(gCDCache);
const getGCD = promisify(gCDCache.get).bind(gCDCache);
const existsGCD = promisify(gCDCache.exists).bind(gCDCache);
const delGCD = promisify(gCDCache.del).bind(gCDCache);
gCDCache.on("error",(error) => {
console.error(error);
});
// Cooldown cache
const CDCache = redis.createClient();
const getCD = promisify(CDCache.get).bind(CDCache);
const setCD = promisify(CDCache.set).bind(CDCache);
const existsCD = promisify(CDCache.exists).bind(CDCache);
const delCD = promisify(CDCache.del).bind(CDCache);
CDCache.on("error",(error) => {
console.error(error);
});
// Guild Settings Cache
const gCache = redis.createClient();
const setGuildSettings = promisify(gCache.set).bind(gCache);
const getGuildSettings = promisify(gCache.get).bind(gCache);
const existsGuildSettings = promisify(gCache.exists).bind(gCache);
const delGuildSettings = promisify(gCache.del).bind(gCache);
gCache.on("error",(error) => {
console.error(error);
});
// VCs Cache
const vcsCache = redis.createClient();
const setVCs = promisify(vcsCache.set).bind(vcsCache);
const getVCs = promisify(vcsCache.get).bind(vcsCache);
vcsCache.on("error",(error) => {
console.error(error);
});
const caches = {
gCache: gCache,setGuildSettings: setGuildSettings,getGuildSettings: getGuildSettings,existsGuildSettings: existsGuildSettings,delGuildSettings: delGuildSettings,vcsCache: vcsCache,setVCs: setVCs,getVCs: getVCs,gCDCache: gCDCache,setGCD: setGCD,getGCD: getGCD,existsGCD: existsGCD,delGCD: delGCD,CDCache: CDCache,getCD: getCD,setCD: setCD,existsCD: existsCD,delCD: delCD
}
module.exports.caches = caches;
console.log('Astro\'s Caches Loaded');
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)