feat: replace Redis with DragonflyDB
- Replace Redis server with DragonflyDB v1.40.1 (Redis protocol compatible) - Stop redis-server service, enable dragonfly service on 127.0.0.1:6379 - Configure dragonfly in /etc/dragonfly/dragonfly.conf (bind 127.0.0.1, maxmemory 2gb) - Update .env: remove REDIS_URL reference Improve database reliability: - Fix catalog-tree.ts: remove CAST(page_id AS CHAR) to enable index usage (122 rows vs 78k full scan) - Fix catalog-repair.ts: replace sql.raw() string interpolation with parameterized sql queries using quoteIdentifier() - Improve redis retry resilience: change retryStrategy to not give up after 3 attempts, enabling automatic reconnect after server restart Update documentation: - Update README: replace Redis references with DragonflyDB, add DragonflyDB setup section, update performance features list, update architecture diagram - biome and typecheck pass clean
This commit is contained in:
1 parent
9463c8d4da
commit
65e3915a5f
4 files changed
+89
-28
No files matched your search
@@ -13,7 +13,7 @@ Features a premium animated homepage (typewriter hero, floating orbs, scroll cou
|
||||
| Node.js | >= 22 | Required by Next.js 16 |
|
||||
| pnpm | >= 10.33.4 | Package manager (npm/yarn not supported) |
|
||||
| MySQL / MariaDB | 8.0+ / 10.6+ | Shared with the emulator |
|
||||
| Redis | 7.x+ | Optional — caching, rate limiting, SSE |
|
||||
| DragonflyDB | 1.x+ | Optional — caching, rate limiting, SSE (Redis-protocol compatible) |
|
||||
| Java | 17+ | Required only if building the emulator |
|
||||
| Maven | 3.9+ | Required only if building the emulator |
|
||||
|
||||
@@ -56,7 +56,7 @@ HOTEL_NAME=YourHotel
|
||||
APP_URL=http://localhost:3000
|
||||
```
|
||||
|
||||
See `.env.example` for all optional variables (RCON, email, Redis, OAuth, PayPal, etc.).
|
||||
See `.env.example` for all optional variables (RCON, email, DragonflyDB, OAuth, PayPal, etc.).
|
||||
|
||||
### 4. ORM Setup & Type Generation
|
||||
|
||||
@@ -121,6 +121,60 @@ Open `http://localhost:3000` in your browser.
|
||||
|
||||
---
|
||||
|
||||
## DragonflyDB (caching, rate limiting, SSE)
|
||||
|
||||
DragonflyDB is a drop-in, Redis-compatible in-memory datastore. The CMS connects to it
|
||||
via `REDIS_URL` using the `ioredis` client, so no application code changes are needed —
|
||||
every Redis command (`PING`, `GET`, `SETEX`, `DEL`, `INCR`, `PEXPIRE`, `PTTL`) works
|
||||
unchanged. It is optional: without it the CMS falls back to in-process memory.
|
||||
|
||||
### Install (Ubuntu/Debian)
|
||||
|
||||
```bash
|
||||
curl -fsSL -o /tmp/dragonfly_amd64.deb \
|
||||
https://github.com/dragonflydb/dragonfly/releases/download/v1.40.1/dragonfly_amd64.deb
|
||||
apt-get install -y /tmp/dragonfly_amd64.deb
|
||||
systemctl enable --now dragonfly
|
||||
```
|
||||
|
||||
This installs a `dragonfly` systemd service and a config file at `/etc/dragonfly/dragonfly.conf`.
|
||||
|
||||
### Configure
|
||||
|
||||
```ini
|
||||
--bind=127.0.0.1
|
||||
--port=6379
|
||||
--maxmemory=2gb
|
||||
--version_check=false
|
||||
```
|
||||
|
||||
- `--bind=127.0.0.1` keeps it private on the machine (matches `REDIS_URL=redis://127.0.0.1:6379`).
|
||||
- `--port=6379` is the default Redis port, so `.env` stays unchanged.
|
||||
- `--maxmemory` must be at least `0.25GiB` per CPU thread (e.g. `2gb` on a 6-thread server).
|
||||
- `--version_check=false` disables the periodic outbound update check.
|
||||
- Snapshots are written to `--dir` (`/var/lib/dragonfly/dump-*.dfs`).
|
||||
|
||||
### Point the CMS at it
|
||||
|
||||
```dotenv
|
||||
REDIS_URL=redis://127.0.0.1:6379?connect_timeout=2
|
||||
```
|
||||
|
||||
### Useful commands
|
||||
|
||||
```bash
|
||||
redis-cli PING # → PONG
|
||||
redis-cli FLUSHALL # clear the cache
|
||||
systemctl status dragonfly # service health
|
||||
```
|
||||
|
||||
Verify everything is wired up via the health endpoint:
|
||||
`/api/health` should report `"redis": true`. The ioredis client automatically reconnects
|
||||
after a DragonflyDB restart.
|
||||
|
||||
> **Note:** if an old Redis install still occupies port 6379, stop it first:
|
||||
> `systemctl disable --now redis-server`.
|
||||
|
||||
## Nginx Configuration
|
||||
|
||||
The CMS is designed to run behind an nginx reverse proxy. Below is a reference configuration covering SSL termination, WebSocket upgrade, proxy caching, and the Habbo imager integration.
|
||||
@@ -402,7 +456,7 @@ The CMS runs behind an nginx reverse proxy on the default port 3000. Static asse
|
||||
| **View Transitions API** | Native browser transitions between page navigations |
|
||||
| **Lenis Smooth Scroll** | Fluid, customizable scrolling (respects `prefers-reduced-motion`) |
|
||||
| **Server-Sent Events** | Real-time radio now-playing & listeners via SSE (no polling) |
|
||||
| **Redis Caching** | Caches API responses (home, radio config) up to 30s in Redis |
|
||||
| **DragonflyDB Caching** | Caches API responses (home, radio config) up to 30s in DragonflyDB |
|
||||
| **Bundle Analyzer** | Run `pnpm analyze` to visualize and optimize bundle sizes |
|
||||
| **RCON (TCP Socket)** | Live commands to the emulator (credits, badges, kick, ban) |
|
||||
| **Streaming & Suspense** | Next.js App Router streaming for fast page loads |
|
||||
@@ -437,9 +491,9 @@ The CMS runs behind an nginx reverse proxy on the default port 3000. Static asse
|
||||
│ │ ├── auth/ # NextAuth, password hashing, 2FA, SSO tickets
|
||||
│ │ ├── services/ # RCON, email, currency, PayPal, alerts
|
||||
│ │ ├── db.ts # Drizzle connection singleton (runtime)
|
||||
│ │ ├── cached-db.ts # Redis-backed query cache helpers
|
||||
│ │ ├── redis.ts # Redis client (ioredis)
|
||||
│ │ ├── redis-cache.ts # Redis caching utility for API routes
|
||||
│ │ ├── cached-db.ts # DragonflyDB-backed query cache helpers
|
||||
│ │ ├── redis.ts # Cache client (ioredis → DragonflyDB)
|
||||
│ │ ├── redis-cache.ts # Caching utility for API routes (uses DragonflyDB)
|
||||
│ │ ├── cache.ts # In-memory cache fallback
|
||||
│ │ ├── motion.ts # Framer Motion animation variants
|
||||
│ │ └── use-event-source.ts # React hook for SSE subscriptions
|
||||
|
||||
Reference in new issue
Block a user