mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-12 06:27:10 +03:00
Support dragonfly with in memory cache
This commit is contained in:
@@ -167,7 +167,8 @@ addDefaults(config, {
|
|||||||
responseTimePause: 1000,
|
responseTimePause: 1000,
|
||||||
disableHashCache: false,
|
disableHashCache: false,
|
||||||
clientCacheSize: 2000,
|
clientCacheSize: 2000,
|
||||||
useCompression: false
|
useCompression: false,
|
||||||
|
dragonflyMode: false
|
||||||
},
|
},
|
||||||
redisRead: {
|
redisRead: {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ interface RedisConfig extends redis.RedisClientOptions {
|
|||||||
disableHashCache: boolean;
|
disableHashCache: boolean;
|
||||||
clientCacheSize: number;
|
clientCacheSize: number;
|
||||||
useCompression: boolean;
|
useCompression: boolean;
|
||||||
|
dragonflyMode: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface RedisReadOnlyConfig extends redis.RedisClientOptions {
|
interface RedisReadOnlyConfig extends redis.RedisClientOptions {
|
||||||
|
|||||||
@@ -180,6 +180,12 @@ if (config.redis?.enabled) {
|
|||||||
|
|
||||||
const del = client.del.bind(client);
|
const del = client.del.bind(client);
|
||||||
exportClient.del = (...keys) => {
|
exportClient.del = (...keys) => {
|
||||||
|
if (config.redis.dragonflyMode) {
|
||||||
|
for (const key of keys) {
|
||||||
|
void client.publish("__redis__:invalidate", key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (config.redis.useCompression) {
|
if (config.redis.useCompression) {
|
||||||
return del(...keys.map((key) => createKeyName(key)) as [RedisCommandArgument]);
|
return del(...keys.map((key) => createKeyName(key)) as [RedisCommandArgument]);
|
||||||
} else {
|
} else {
|
||||||
@@ -367,12 +373,15 @@ export function getRedisStats(): RedisStats {
|
|||||||
async function setupCacheClientListener(cacheClient: RedisClientType,
|
async function setupCacheClientListener(cacheClient: RedisClientType,
|
||||||
cache: LRUCache<RedisCommandArgument, string>) {
|
cache: LRUCache<RedisCommandArgument, string>) {
|
||||||
|
|
||||||
cacheConnectionClientId = String(await cacheClient.clientId());
|
if (!config.redis.dragonflyMode) {
|
||||||
|
cacheConnectionClientId = String(await cacheClient.clientId());
|
||||||
|
}
|
||||||
|
|
||||||
cacheClient.subscribe("__redis__:invalidate", (keys) => {
|
cacheClient.subscribe("__redis__:invalidate", (message) => {
|
||||||
if (keys) {
|
if (message) {
|
||||||
lastInvalidationMessage = Date.now();
|
lastInvalidationMessage = Date.now();
|
||||||
|
|
||||||
|
const keys = Buffer.isBuffer(message) ? [message.toString()] : message;
|
||||||
for (let key of keys) {
|
for (let key of keys) {
|
||||||
if (config.redis.useCompression) key = key.replace(/.c$/, "");
|
if (config.redis.useCompression) key = key.replace(/.c$/, "");
|
||||||
|
|
||||||
@@ -392,7 +401,7 @@ async function setupCacheClientListener(cacheClient: RedisClientType,
|
|||||||
async function setupCacheClientTracking(client: RedisClientType,
|
async function setupCacheClientTracking(client: RedisClientType,
|
||||||
cacheClient: RedisClientType) {
|
cacheClient: RedisClientType) {
|
||||||
|
|
||||||
if (!client || !cacheClient.isReady) return;
|
if (!client || !cacheClient.isReady || config.redis.dragonflyMode) return;
|
||||||
|
|
||||||
await client.sendCommand(["CLIENT", "TRACKING", "ON", "REDIRECT", cacheConnectionClientId, "BCAST"]);
|
await client.sendCommand(["CLIENT", "TRACKING", "ON", "REDIRECT", cacheConnectionClientId, "BCAST"]);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user