Skip to content

Commit

Permalink
Remove redis (#6247)
Browse files Browse the repository at this point in the history
  • Loading branch information
gc authored Dec 3, 2024
1 parent 2dfd888 commit 3cad6c3
Show file tree
Hide file tree
Showing 16 changed files with 10 additions and 349 deletions.
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ ROBOCHIMP_DATABASE_URL=postgresql://postgres:postgres@localhost:5436/robochimp_t
DATABASE_URL=postgresql://postgres:postgres@localhost:5435/osb_test

# Optional
#REDIS_PORT=6379
#TESTING_SERVER_ID=123456789012345678

# Dont change these:
Expand Down
11 changes: 1 addition & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,14 @@ services:
POSTGRES_PASSWORD: postgres
PGPORT: 5435

redis:
image: redis:latest
restart: always
environment:
- REDIS_PORT=6379
ports:
- "6379:6379"

app:
build:
context: .
dockerfile: Dockerfile
target: build-run
depends_on:
- db
- redis
environment:
ROBOCHIMP_DATABASE_URL: postgresql://postgres:postgres@db:5435/robochimp_integration_test?connection_limit=10&pool_timeout=0&schema=public
DATABASE_URL: postgresql://postgres:postgres@db:5435/osb_integration_test?connection_limit=10&pool_timeout=0&schema=public
WAIT_HOSTS: db:5435, redis:6379
WAIT_HOSTS: db:5435
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"test:types": "concurrently \"tsc --noEmit -p tests/unit\" \"tsc --noEmit -p tests/integration\" \"tsc --noEmit -p src\"",
"test:lint": "biome check --diagnostic-level=error",
"test:unit": "vitest run --config vitest.unit.config.mts",
"test:docker": "docker compose up --no-attach db --no-attach redis --build --abort-on-container-exit && docker compose down -v",
"test:docker": "docker compose up --no-attach db --build --abort-on-container-exit && docker compose down -v",
"test:watch": "vitest --config vitest.unit.config.mts --coverage",
"test:ci:unit": "pnpm concurrent \"pnpm test:unit\" \"pnpm test:lint\" \"tsc -p tests/integration\" \"tsc -p tests/unit\"",
"============MISC": "============",
Expand Down
2 changes: 1 addition & 1 deletion packages/toolkit/esbuild.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const baseConfig = {
entryPoints,
platform: 'node',
sourcemap: false,
external: ['discord.js', 'ioredis'],
external: ['discord.js'],
loader: {
'.json': 'copy'
}
Expand Down
1 change: 0 additions & 1 deletion packages/toolkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"deepmerge": "4.3.1",
"emoji-regex": "^10.2.1",
"fast-deep-equal": "^3.1.3",
"ioredis": "^5.4.1",
"math-expression-evaluator": "^1.3.14",
"pure-rand": "^6.1.0",
"zod": "^3.23.8"
Expand Down
61 changes: 0 additions & 61 deletions packages/toolkit/src/TSRedis.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/toolkit/src/structures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ export * from './lib/GeneralBank';
export * from './lib/SimpleTable';
export * from './lib/UserError';
export * from './lib/Stopwatch';
export * from './TSRedis';
67 changes: 0 additions & 67 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,6 @@ export const ParsedCustomEmojiWithGroups = /(?<animated>a?):(?<name>[^:]+):(?<id

const globalConfigSchema = z.object({
clientID: z.string().min(10).max(25),
redisPort: z.coerce.number().int().optional(),
botToken: z.string().min(1),
isCI: z.coerce.boolean().default(false),
isProduction: z.boolean(),
Expand All @@ -503,7 +502,6 @@ if (!process.env.BOT_TOKEN && !process.env.CI) {

export const globalConfig = globalConfigSchema.parse({
clientID: process.env.CLIENT_ID,
redisPort: process.env.REDIS_PORT,
botToken: process.env.BOT_TOKEN,
isCI: process.env.CI,
isProduction,
Expand Down
23 changes: 0 additions & 23 deletions src/lib/globals.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { isMainThread } from 'node:worker_threads';
import { TSRedis } from '@oldschoolgg/toolkit/structures';
import { PrismaClient } from '@prisma/client';
import { PrismaClient as RobochimpPrismaClient } from '@prisma/robochimp';

import { globalConfig } from './constants';
import { handleDeletedPatron, handleEditPatron } from './patreonUtils';

declare global {
var prisma: PrismaClient;
var redis: TSRedis;
var roboChimpClient: RobochimpPrismaClient;
}

Expand All @@ -35,23 +32,3 @@ function makeRobochimpPrismaClient(): RobochimpPrismaClient {
});
}
global.roboChimpClient = global.roboChimpClient || makeRobochimpPrismaClient();

function makeRedisClient(): TSRedis {
if (!globalConfig.isProduction && !process.env.TEST) console.log('Making Redis client...');
if (!isMainThread && !process.env.TEST) {
throw new Error('Redis client should only be created on the main thread.');
}
return new TSRedis({ mocked: !globalConfig.redisPort, port: globalConfig.redisPort });
}
global.redis = global.redis || makeRedisClient();

global.redis.subscribe(message => {
debugLog(`Received message from Redis: ${JSON.stringify(message)}`);
if (message.type === 'patron_tier_change') {
if (message.new_tier === 0) {
return handleDeletedPatron(message.discord_ids);
} else {
return handleEditPatron(message.discord_ids);
}
}
});
Loading

0 comments on commit 3cad6c3

Please sign in to comment.