mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-27 01:48:33 +03:00
Revert adding redis compression
This reverts commitfce311377fand2ad51842cc
This commit is contained in:
@@ -6,7 +6,6 @@ import { RedisClientOptions } from "@redis/client/dist/lib/client";
|
||||
import { RedisReply } from "rate-limit-redis";
|
||||
import { db } from "../databases/databases";
|
||||
import { Postgres } from "../databases/Postgres";
|
||||
import { compress, uncompress } from "lz4-napi";
|
||||
|
||||
export interface RedisStats {
|
||||
activeRequests: number;
|
||||
@@ -17,11 +16,8 @@ export interface RedisStats {
|
||||
|
||||
interface RedisSB {
|
||||
get(key: RedisCommandArgument): Promise<string>;
|
||||
getCompressed(key: RedisCommandArgument): Promise<string>;
|
||||
set(key: RedisCommandArgument, value: RedisCommandArgument, options?: SetOptions): Promise<string>;
|
||||
setCompressed(key: RedisCommandArgument, value: RedisCommandArgument, options?: SetOptions): Promise<string>;
|
||||
setEx(key: RedisCommandArgument, seconds: number, value: RedisCommandArgument): Promise<string>;
|
||||
setExCompressed(key: RedisCommandArgument, seconds: number, value: RedisCommandArgument): Promise<string>;
|
||||
del(...keys: [RedisCommandArgument]): Promise<number>;
|
||||
increment?(key: RedisCommandArgument): Promise<RedisCommandRawReply[]>;
|
||||
sendCommand(args: RedisCommandArguments, options?: RedisClientOptions): Promise<RedisReply>;
|
||||
@@ -30,17 +26,14 @@ interface RedisSB {
|
||||
}
|
||||
|
||||
let exportClient: RedisSB = {
|
||||
get: () => Promise.resolve(null),
|
||||
getCompressed: () => Promise.resolve(null),
|
||||
set: () => Promise.resolve(null),
|
||||
setCompressed: () => Promise.resolve(null),
|
||||
setEx: () => Promise.resolve(null),
|
||||
setExCompressed: () => Promise.resolve(null),
|
||||
del: () => Promise.resolve(null),
|
||||
increment: () => Promise.resolve(null),
|
||||
sendCommand: () => Promise.resolve(null),
|
||||
quit: () => Promise.resolve(null),
|
||||
ttl: () => Promise.resolve(null),
|
||||
get: () => new Promise((resolve) => resolve(null)),
|
||||
set: () => new Promise((resolve) => resolve(null)),
|
||||
setEx: () => new Promise((resolve) => resolve(null)),
|
||||
del: () => new Promise((resolve) => resolve(null)),
|
||||
increment: () => new Promise((resolve) => resolve(null)),
|
||||
sendCommand: () => new Promise((resolve) => resolve(null)),
|
||||
quit: () => new Promise((resolve) => resolve(null)),
|
||||
ttl: () => new Promise((resolve) => resolve(null)),
|
||||
};
|
||||
|
||||
let lastClientFail = 0;
|
||||
@@ -63,24 +56,8 @@ if (config.redis?.enabled) {
|
||||
const readClient = config.redisRead?.enabled ? createClient(config.redisRead) : null;
|
||||
connectionPromise = client.connect();
|
||||
void readClient?.connect(); // void as we don't care about the promise
|
||||
exportClient = client as unknown as RedisSB;
|
||||
exportClient = client as RedisSB;
|
||||
|
||||
exportClient.getCompressed = (key) => {
|
||||
return exportClient.get(key).then((reply) => {
|
||||
if (reply === null) return null;
|
||||
return uncompress(Buffer.from(reply, "base64")).then((decompressed) => decompressed.toString("utf-8"));
|
||||
});
|
||||
};
|
||||
exportClient.setCompressed = (key, value, options) => {
|
||||
return compress(Buffer.from(value as string, "utf-8")).then((compressed) =>
|
||||
exportClient.set(key, compressed.toString("base64"), options)
|
||||
);
|
||||
};
|
||||
exportClient.setExCompressed = (key, seconds, value) => {
|
||||
return compress(Buffer.from(value as string, "utf-8")).then((compressed) =>
|
||||
exportClient.setEx(key, seconds, compressed.toString("base64"))
|
||||
);
|
||||
};
|
||||
|
||||
const get = client.get.bind(client);
|
||||
const getRead = readClient?.get?.bind(readClient);
|
||||
|
||||
Reference in New Issue
Block a user