make redis optional for backend

This commit is contained in:
Hongbo Wu
2024-01-04 21:55:41 +08:00
parent 0cf7054ce6
commit 32a58e49f9
3 changed files with 9 additions and 14 deletions

View File

@ -31,18 +31,6 @@ services:
depends_on:
postgres:
condition: service_healthy
redis:
image: "redis:6.0.9-alpine"
container_name: "omnivore-redis"
ports:
- "6379:6379"
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 15s
timeout: 90s
expose:
- 6379
api:
build:

View File

@ -158,7 +158,10 @@ const main = async (): Promise<void> => {
// as healthy.
await appDataSource.initialize()
await redisClient.connect()
// redis is optional
if (env.redis.url) {
await redisClient.connect()
}
const { app, apollo, httpServer } = createApp()

View File

@ -6,6 +6,7 @@ import { EntityLabel } from '../entity/entity_label'
import { Highlight } from '../entity/highlight'
import { Label } from '../entity/label'
import { LibraryItem, LibraryItemState } from '../entity/library_item'
import { env } from '../env'
import { BulkActionType, InputMaybe, SortParams } from '../generated/graphql'
import { createPubSubClient, EntityType } from '../pubsub'
import {
@ -818,7 +819,10 @@ export const createLibraryItem = async (
userId
)
await setRecentlySavedItemInRedis(userId, newLibraryItem.originalUrl)
// set recently saved item in redis if redis is enabled
if (env.redis.url) {
await setRecentlySavedItemInRedis(userId, newLibraryItem.originalUrl)
}
if (skipPubSub) {
return newLibraryItem