Skip to content

Commit

Permalink
Use @fedify/redis
Browse files Browse the repository at this point in the history
  • Loading branch information
dahlia committed Jun 22, 2024
1 parent 4490d53 commit 1737ef2
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 7 deletions.
1 change: 1 addition & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
DATABASE_URL=postgresql://user:password@localhost:5432/dbname
REDIS_URL=redis://localhost/0
SECRET_KEY=secret_key # generate a secret key with `openssl rand -base64 32`
LOG_LEVEL=info
BEHIND_PROXY=false
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ database and an S3-compatible object storage for media storage. You can use
the following environment variables to configure Hollo:

- `DATABASE_URL`: The URL of the PostgreSQL database.
- `REDIS_URL`: The URL of the Redis server.
- `SECRET_KEY`: The secret key for securing the session.
- `LOG_LEVEL`: The log level for the application. `debug`, `info`, `warning`,
`error`, and `fatal` are available.
Expand All @@ -82,6 +83,7 @@ The image exposes the port 3000, so you can run it like this:
~~~~ sh
docker run -d -p 3000:3000 \
-e DATABASE_URL=postgres://user:password@host:port/database \
-e REDIS_URL=redis://host:port/0 \
-e SECRET_KEY=your-secret-key \
-e LOG_LEVEL=info \
-e BEHIND_PROXY=true \
Expand Down
Binary file modified bun.lockb
Binary file not shown.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
"dependencies": {
"@aws-sdk/client-s3": "^3.577.0",
"@aws-sdk/credential-providers": "^3.577.0",
"@fedify/fedify": "0.10.0-dev.211",
"@fedify/fedify": "^0.11.0-dev.234",
"@fedify/markdown-it-hashtag": "0.2.0",
"@fedify/markdown-it-mention": "^0.1.1",
"@fedify/redis": "^0.1.1",
"@hono/zod-validator": "^0.2.1",
"@js-temporal/polyfill": "^0.4.4",
"@logtape/logtape": "^0.4.0",
Expand All @@ -25,6 +26,7 @@
"cheerio": "^1.0.0-rc.12",
"drizzle-orm": "^0.30.10",
"hono": "^4.3.4",
"ioredis": "^5.4.1",
"iso-639-1": "^3.1.2",
"markdown-it": "^14.1.0",
"markdown-it-replace-link": "^1.2.1",
Expand Down
14 changes: 8 additions & 6 deletions src/federation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@ import {
Create,
Delete,
Endpoints,
Federation,
Follow,
Image,
InProcessMessageQueue,
Like,
MemoryKvStore,
Note,
PropertyValue,
Reject,
Undo,
Update,
createFederation,
getActorClassByTypeName,
importJwk,
isActor,
} from "@fedify/fedify";
import { RedisKvStore, RedisMessageQueue } from "@fedify/redis";
import { getLogger } from "@logtape/logtape";
import { parse } from "@std/semver";
import { and, count, eq, ilike, inArray, like, sql } from "drizzle-orm";
import metadata from "../../package.json" with { type: "json" };
import db from "../db";
import redis, { createRedis } from "../redis";
import {
type NewLike,
accountOwners,
Expand All @@ -38,9 +38,11 @@ import { persistAccount } from "./account";
import { toTemporalInstant } from "./date";
import { persistPost, persistSharingPost, toObject } from "./post";

export const federation = new Federation({
kv: new MemoryKvStore(),
queue: new InProcessMessageQueue(),
export const federation = createFederation({
kv: new RedisKvStore(redis),
queue: new RedisMessageQueue(createRedis, {
loopInterval: { seconds: 2, milliseconds: 500 },
}),
});

federation
Expand Down
10 changes: 10 additions & 0 deletions src/redis.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Redis } from "ioredis";

export function createRedis(): Redis {
// biome-ignore lint/complexity/useLiteralKeys: tsc rants about this (TS4111)
const redisUrl = process.env["REDIS_URL"];
if (redisUrl == null) throw new Error("REDIS_URL must be defined");
return new Redis(redisUrl);
}

export default createRedis();

0 comments on commit 1737ef2

Please sign in to comment.