Skip to content

A self-hostable bookmark-everything app (links, notes and images) with AI-based automatic tagging and full text search

chore: move away from ioredis to node-redis client

Mohamed Bassem774b2559264c
diff --git a/packages/plugins/package.json b/packages/plugins/package.json
index 15a183a9..5b83cc9a 100644
--- a/packages/plugins/package.json
+++ b/packages/plugins/package.json
@@ -24,9 +24,9 @@
"@restatedev/restate-sdk": "^1.10.3",
"@restatedev/restate-sdk-clients": "^1.10.3",
"async-mutex": "^0.4.1",
- "ioredis": "^5.4.2",
"liteque": "^0.7.0",
- "meilisearch": "^0.45.0"
+ "meilisearch": "^0.45.0",
+ "redis": "^5.11.0"
},
"devDependencies": {
"@karakeep/prettier-config": "workspace:^0.1.0",
diff --git a/packages/plugins/ratelimit-redis/src/index.ts b/packages/plugins/ratelimit-redis/src/index.ts
index 5a1bdd63..56a830da 100644
--- a/packages/plugins/ratelimit-redis/src/index.ts
+++ b/packages/plugins/ratelimit-redis/src/index.ts
@@ -1,4 +1,5 @@
-import Redis from "ioredis";
+import type { RedisClientType } from "redis";
+import { createClient } from "redis";
import type {
RateLimitClient,
@@ -10,9 +11,9 @@ import { PluginProvider } from "@karakeep/shared/plugins";
const KEY_PREFIX = "ratelimit:v1";
export class RedisRateLimiter implements RateLimitClient {
- private redis: Redis;
+ private redis: RedisClientType;
- constructor(redis: Redis) {
+ constructor(redis: RedisClientType) {
this.redis = redis;
}
@@ -66,17 +67,20 @@ export class RedisRateLimiter implements RateLimitClient {
end
`;
- const result = (await this.redis.eval(
- luaScript,
- 2,
- rateLimitKey,
- rateLimitSequenceKey,
- now.toString(),
- config.windowMs.toString(),
- config.maxRequests.toString(),
- )) as [number, number];
+ const result = await this.redis.eval(luaScript, {
+ keys: [rateLimitKey, rateLimitSequenceKey],
+ arguments: [
+ now.toString(),
+ config.windowMs.toString(),
+ config.maxRequests.toString(),
+ ],
+ });
+
+ if (!Array.isArray(result) || result.length < 2) {
+ throw new Error("Unexpected Redis eval result");
+ }
- const [allowed, resetInSeconds] = result;
+ const [allowed, resetInSeconds] = result.map((value) => Number(value));
if (allowed === 1) {
return { allowed: true };
@@ -97,7 +101,7 @@ export class RedisRateLimiter implements RateLimitClient {
const rateLimitKey = `${KEY_PREFIX}:${config.name}:${key}`;
const rateLimitSequenceKey = `${rateLimitKey}:seq`;
try {
- await this.redis.del(rateLimitKey, rateLimitSequenceKey);
+ await this.redis.del([rateLimitKey, rateLimitSequenceKey]);
} catch (error) {
console.error("Redis rate limit reset error:", error);
}
@@ -107,16 +111,13 @@ export class RedisRateLimiter implements RateLimitClient {
try {
let cursor = "0";
do {
- const [nextCursor, keys] = await this.redis.scan(
- cursor,
- "MATCH",
- `${KEY_PREFIX}:*`,
- "COUNT",
- 100,
- );
+ const { cursor: nextCursor, keys } = await this.redis.scan(cursor, {
+ MATCH: `${KEY_PREFIX}:*`,
+ COUNT: 100,
+ });
cursor = nextCursor;
if (keys.length > 0) {
- await this.redis.del(...keys);
+ await this.redis.del(keys);
}
} while (cursor !== "0");
} catch (error) {
@@ -125,7 +126,9 @@ export class RedisRateLimiter implements RateLimitClient {
}
async disconnect() {
- await this.redis.quit();
+ if (this.redis.isOpen) {
+ await this.redis.quit();
+ }
}
}
@@ -144,11 +147,12 @@ export class RedisRateLimitProvider implements PluginProvider<RateLimitClient> {
this.options = options;
}
- private createRedisClient(): Redis {
- return new Redis(this.options.url, {
- lazyConnect: true,
- maxRetriesPerRequest: 0,
- retryStrategy: () => 3_000,
+ private createRedisClient(): RedisClientType {
+ return createClient({
+ url: this.options.url,
+ socket: {
+ reconnectStrategy: () => 3_000,
+ },
});
}
diff --git a/packages/plugins/ratelimit-redis/src/tests/docker-compose.yml b/packages/plugins/ratelimit-redis/src/tests/docker-compose.yml
index 27f8d250..7cd5d738 100644
--- a/packages/plugins/ratelimit-redis/src/tests/docker-compose.yml
+++ b/packages/plugins/ratelimit-redis/src/tests/docker-compose.yml
@@ -1,5 +1,5 @@
services:
redis:
- image: redis:7-alpine
+ image: redis:8-alpine
ports:
- "${REDIS_PORT:-6379}:6379"
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 1cfcd846..b3e74179 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -1283,15 +1283,15 @@ importers:
async-mutex:
specifier: ^0.4.1
version: 0.4.1
- ioredis:
- specifier: ^5.4.2
- version: 5.10.0
liteque:
specifier: ^0.7.0
meilisearch:
specifier: ^0.45.0
version: 0.45.0
+ redis:
+ specifier: ^5.11.0
+ version: 5.11.0
devDependencies:
'@karakeep/prettier-config':
specifier: workspace:^0.1.0
@@ -4055,9 +4055,6 @@ packages:
cpu: [x64]
os: [win32]
- '@ioredis/[email protected]':
- resolution: {integrity: sha512-JH8ZL/ywcJyR9MmJ5BNqZllXNZQqQbnVZOqpPQqE1vHiFgAw4NHbvE0FOduNU8IX9babitBT46571OnPTT0Zcw==}
-
'@isaacs/[email protected]':
resolution: {integrity: sha512-yzMTt9lEb8Gv7zRioUilSglI0c0smZ9k5D65677DLWLtWJaXIS3CqcGyUFByYKlnUj6TkjLVs54fBl6+TiGQDQ==}
engines: {node: 20 || >=22}
@@ -5445,6 +5442,39 @@ packages:
'@react-navigation/[email protected]':
resolution: {integrity: sha512-1tJHg4KKRJuQ1/EvJxatrMef3NZXEPzwUIUZ3n1yJ2t7Q97siwRtbynRpQG9/69ebbtiZ8W3ScOZF/OmhvM4Rg==}
+ '@redis/[email protected]':
+ resolution: {integrity: sha512-KYiVilAhAFN3057afUb/tfYJpsEyTkQB+tQcn5gVVA7DgcNOAj8lLxe4j8ov8BF6I9C1Fe/kwlbuAICcTMX8Lw==}
+ engines: {node: '>= 18'}
+ peerDependencies:
+ '@redis/client': ^5.11.0
+
+ '@redis/[email protected]':
+ resolution: {integrity: sha512-GHoprlNQD51Xq2Ztd94HHV94MdFZQ3CVrpA04Fz8MVoHM0B7SlbmPEVIjwTbcv58z8QyjnrOuikS0rWF03k5dQ==}
+ engines: {node: '>= 18'}
+ peerDependencies:
+ '@node-rs/xxhash': ^1.1.0
+ peerDependenciesMeta:
+ '@node-rs/xxhash':
+ optional: true
+
+ '@redis/[email protected]':
+ resolution: {integrity: sha512-1iAy9kAtcD0quB21RbPTbUqqy+T2Uu2JxucwE+B4A+VaDbIRvpZR6DMqV8Iqaws2YxJYB3GC5JVNzPYio2ErUg==}
+ engines: {node: '>= 18'}
+ peerDependencies:
+ '@redis/client': ^5.11.0
+
+ '@redis/[email protected]':
+ resolution: {integrity: sha512-g1l7f3Rnyk/xI99oGHIgWHSKFl45Re5YTIcO8j/JE8olz389yUFyz2+A6nqVy/Zi031VgPDWscbbgOk8hlhZ3g==}
+ engines: {node: '>= 18'}
+ peerDependencies:
+ '@redis/client': ^5.11.0
+
+ '@redis/[email protected]':
+ resolution: {integrity: sha512-TWFeOcU4xkj0DkndnOyhtxvX1KWD+78UHT3XX3x3XRBUGWeQrKo3jqzDsZwxbggUgf9yLJr/akFHXru66X5UQA==}
+ engines: {node: '>= 18'}
+ peerDependencies:
+ '@redis/client': ^5.11.0
+
'@redocly/[email protected]':
resolution: {integrity: sha512-io1JpnwtIcvojV7QKDUSIuMN/ikdOUd1ReEnUnMKGfDVridQZ31J0MmIuqwuRjWDZfmvr+Q0MqCcfHM2gTivOg==}
@@ -8134,10 +8164,6 @@ packages:
resolution: {integrity: sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==}
engines: {node: '>=0.4.0'}
- resolution: {integrity: sha512-HVQE3AAb/pxF8fQAoiqpvg9i3evqug3hoiwakOyZAwJm+6vZehbkYXZ0l4JxS+I3QxM97v5aaRNhj8v5oBhekw==}
- engines: {node: '>=0.10'}
-
resolution: {integrity: sha512-7emPTl6Dpo6JRXOXjLRxck+FlLRX5847cLKEn00PLAgc3g2hTZZgr+e4c2v6QpSmLeFP3n5yUo7ft6avBK/5jQ==}
engines: {node: '>= 0.6'}
@@ -9890,10 +9916,6 @@ packages:
resolution: {integrity: sha512-phJfQVBuaJM5raOpJjSfkiD6BpbCE4Ns//LaXl6wGYtUBY83nWS6Rf9tXm2e8VaK60JEjYldbPif/A2B1C2gNA==}
- resolution: {integrity: sha512-HVBe9OFuqs+Z6n64q09PQvP1/R4Bm+30PAyyD4wIEqssh3v9L21QjCVk4kRLucMBcDokJTcLjsGeVRlq/nH6DA==}
- engines: {node: '>=12.22.0'}
-
resolution: {integrity: sha512-zHtQzGojZXTwZTHQqra+ETKd4Sn3vgi7uBmlPoXVWZqYvuKmtI0l/VZTjqGmJY9x88GGOaZ9+G9ES8hC4T4X8g==}
engines: {node: '>= 12'}
@@ -10681,12 +10703,6 @@ packages:
resolution: {integrity: sha512-FT1yDzDYEoYWhnSGnpE/4Kj1fLZkDFyqRb7fNt6FdYOSxlUWAtp42Eh6Wb0rGIv/m9Bgo7x4GhQbm5Ys4SG5ow==}
- resolution: {integrity: sha512-qjxPLHd3r5DnsdGacqOMU6pb/avJzdh9tFX2ymgoZE27BmjXrNy/y4LoaiTeAb+O3gL8AfpJGtqfX/ae2leYYQ==}
-
- resolution: {integrity: sha512-chi4NHZlZqZD18a0imDHnZPrDeBbTtVN7GXMwuGdRH9qotxAjYs3aVLKc7zNOG9eddR5Ksd8rvFEBc9SsggPpg==}
-
resolution: {integrity: sha512-oSXzaWypCMHkPC3NvBEaPHf0KsA5mvPrOPgQWDsbg8n7orZ290M0BmC/jgRZ4vcJ6DTAhjrsSYgdsW/F+MFOBA==}
@@ -13499,13 +13515,9 @@ packages:
resolution: {integrity: sha512-cjwII1MdIIVloKvC9ErQ+OgAtwHBmcZ0Bg4ciz78FtbT8In39aAYbaA7zvxQ61xVMSPE8WxhLwLbhif4Js2C+g==}
- resolution: {integrity: sha512-1qny3OExCf0UvUV/5wpYKf2YwPcOqXzkwKKSmKHiE6ZMQs5heeE/c8eXK+PNllPvmjgAbfnsbpkGZWy8cBpn9w==}
- engines: {node: '>=4'}
-
- resolution: {integrity: sha512-DJnGAeenTdpMEH6uAJRK/uiyEIH9WVsUmoLwzudwGJUwZPp80PDBWPHXSAGNPwNvIXAbe7MSUB1zQFugFml66A==}
- engines: {node: '>=4'}
+ resolution: {integrity: sha512-YwXjATVDT+AuxcyfOwZn046aml9jMlQPvU1VXIlLDVAExe0u93aTfPYSeRgG4p9Q/Jlkj+LXJ1XEoFV+j2JKcQ==}
+ engines: {node: '>= 18'}
resolution: {integrity: sha512-+P3TjtnP0k/FEjcBL5FZpoovtvrTNT/UXd4/sluaSyrURlSlhLSzEdfsTBW7WsKB6yPvgd7q/iZPICFjW4o57Q==}
@@ -14309,9 +14321,6 @@ packages:
resolution: {integrity: sha512-WjlahMgHmCJpqzU8bIBy4qtsZdU9lRlcZE3Lvyej6t4tuOuv1vk57OW3MBrj6hXBFx/nNoC9MPMTcr5YA7NQbg==}
engines: {node: '>=6'}
- resolution: {integrity: sha512-qoRRSyROncaz1z0mvYqIE4lCd9p2R90i6GxW3uZv5ucSu8tU7B5HXUP1gG8pVZsYNVaXjk8ClXHPttLyxAL48A==}
-
resolution: {integrity: sha512-OpZ3zP+jT1PI7I8nemJX4AKmAX070ZkYPVWV/AaKTJl+tXCTGyVdC1a4SL8RUQYEwk/f34ZX8UTykN68FwrqAA==}
engines: {node: '>= 0.6'}
@@ -18947,7 +18956,7 @@ snapshots:
'@emotion/[email protected]':
dependencies:
'@babel/helper-module-imports': 7.27.1
- '@babel/runtime': 7.28.4
+ '@babel/runtime': 7.28.6
'@emotion/hash': 0.9.2
'@emotion/memoize': 0.9.0
'@emotion/serialize': 1.3.3
@@ -19755,8 +19764,6 @@ snapshots:
optional: true
- '@ioredis/[email protected]': {}
-
'@isaacs/[email protected]': {}
'@isaacs/[email protected]':
@@ -21437,6 +21444,26 @@ snapshots:
dependencies:
nanoid: 3.3.11
+ dependencies:
+ '@redis/client': 5.11.0
+
+ '@redis/[email protected]':
+ dependencies:
+ cluster-key-slot: 1.1.2
+
+ dependencies:
+ '@redis/client': 5.11.0
+
+ dependencies:
+ '@redis/client': 5.11.0
+
+ dependencies:
+ '@redis/client': 5.11.0
+
'@redocly/[email protected]':
dependencies:
fast-deep-equal: 3.1.3
@@ -24525,8 +24552,6 @@ snapshots:
-
@@ -24665,7 +24690,7 @@ snapshots:
dependencies:
- '@babel/runtime': 7.28.4
+ '@babel/runtime': 7.28.6
csstype: 3.2.3
@@ -26527,20 +26552,6 @@ snapshots:
dependencies:
loose-envify: 1.4.0
- dependencies:
- '@ioredis/commands': 1.5.1
- cluster-key-slot: 1.1.2
- debug: 4.4.3
- denque: 2.1.0
- lodash.defaults: 4.2.0
- lodash.isarguments: 3.1.0
- redis-errors: 1.2.0
- redis-parser: 3.0.0
- standard-as-callback: 2.1.0
- transitivePeerDependencies:
- - supports-color
-
dependencies:
jsbn: 1.1.0
@@ -27359,10 +27370,6 @@ snapshots:
-
-
@@ -31259,11 +31266,15 @@ snapshots:
unified: 11.0.5
vfile: 6.0.3
-
dependencies:
- redis-errors: 1.2.0
+ '@redis/bloom': 5.11.0(@redis/[email protected])
+ '@redis/client': 5.11.0
+ '@redis/json': 5.11.0(@redis/[email protected])
+ '@redis/search': 5.11.0(@redis/[email protected])
+ '@redis/time-series': 5.11.0(@redis/[email protected])
+ transitivePeerDependencies:
+ - '@node-rs/xxhash'
dependencies:
@@ -32276,8 +32287,6 @@ snapshots:
dependencies:
type-fest: 0.7.1
-