Remove Redis client in api

This commit is contained in:
Hongbo Wu
2022-10-12 13:40:16 +08:00
parent f30a3599ed
commit 4b7950458c
6 changed files with 0 additions and 75 deletions

View File

@ -42,16 +42,6 @@ jobs:
--health-retries 10
ports:
- 9200
redis:
image: redis
# Set health checks to wait until redis has started
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 6379
steps:
- uses: actions/checkout@v2
with:
@ -87,7 +77,6 @@ jobs:
PG_DB: omnivore_test
PG_POOL_MAX: 10
ELASTIC_URL: http://localhost:${{ job.services.elastic.ports[9200] }}/
REDIS_URL: redis://localhost:${{ job.services.redis.ports[6379] }}
build-docker-images:
name: Build docker images
runs-on: ubuntu-latest

View File

@ -77,7 +77,6 @@
"pg": "^8.3.3",
"postgrator": "^4.2.0",
"private-ip": "^2.3.3",
"redis": "^4.3.1",
"sanitize-html": "^2.3.2",
"search-query-parser": "^1.6.0",
"snake-case": "^3.0.3",

View File

@ -46,7 +46,6 @@ import rateLimit from 'express-rate-limit'
import { webhooksServiceRouter } from './routers/svc/webhooks'
import { integrationsServiceRouter } from './routers/svc/integrations'
import { textToSpeechRouter } from './routers/text_to_speech'
import { connectRedisClient, redisClient } from './utils/redis'
const PORT = process.env.PORT || 4000
@ -105,25 +104,6 @@ export const createApp = (): {
app.use('/api/', apiLimiter)
}
// set user device from request header to Redis
app.use('/api/', async (req, res, next) => {
const client = req.header('X-OmnivoreClient')
const token =
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
req.header('Authorization') || (req.cookies['auth'] as string | undefined)
if (client && token) {
const key = `client:${token}`
if (!(await redisClient.exists(key))) {
await redisClient.set(key, client, {
EX: 600, // expires in 10 minutes
NX: true,
})
}
}
next()
})
// respond healthy to auto-scaler.
app.get('/_ah/health', (req, res) => res.sendStatus(200))
@ -168,8 +148,6 @@ const main = async (): Promise<void> => {
await initElasticsearch()
await connectRedisClient()
const { app, apollo, httpServer } = createApp()
await apollo.start()

View File

@ -97,10 +97,6 @@ interface BackendEnv {
gcp: {
location: string
}
redis: {
url?: string
cert?: string
}
}
/***
@ -156,8 +152,6 @@ const nullableEnvVars = [
'AZURE_SPEECH_KEY',
'AZURE_SPEECH_REGION',
'GCP_LOCATION',
'REDIS_URL',
'REDIS_CERT',
] // Allow some vars to be null/empty
/* If not in GAE and Prod/QA/Demo env (f.e. on localhost/dev env), allow following env vars to be null */
@ -287,11 +281,6 @@ export function getEnv(): BackendEnv {
location: parse('GCP_LOCATION'),
}
const redis = {
url: parse('REDIS_URL'),
cert: parse('REDIS_CERT'),
}
return {
pg,
client,
@ -312,7 +301,6 @@ export function getEnv(): BackendEnv {
readwise,
azure,
gcp,
redis,
}
}

View File

@ -1,25 +0,0 @@
import { createClient } from 'redis'
import { env } from '../env'
export const redisClient = createClient({
url: env.redis.url,
socket: {
tls: env.redis.url?.startsWith('rediss://'), // rediss:// is the protocol for TLS
cert: env.redis.cert?.replace(/\\n/g, '\n'), // replace \n with new line
rejectUnauthorized: false, // for self-signed certs
connectTimeout: 10000, // 10 seconds
reconnectStrategy(retries: number): number | Error {
if (retries > 10) {
return new Error('Retries exhausted')
}
return 1000
},
},
})
export const connectRedisClient = async () => {
redisClient.on('error', (err) => console.error('Redis Client Error', err))
await redisClient.connect()
console.log('Redis Client Connected')
}

View File

@ -1,7 +1,6 @@
import { createTestConnection } from './db'
import { initElasticsearch } from '../src/elastic'
import { startApolloServer } from './util'
import { connectRedisClient } from '../src/utils/redis'
export const mochaGlobalSetup = async () => {
await createTestConnection()
@ -10,9 +9,6 @@ export const mochaGlobalSetup = async () => {
await initElasticsearch()
console.log('elasticsearch initialized')
await connectRedisClient()
console.log('redis client connected')
await startApolloServer()
console.log('apollo server started')
}