mirror of
https://github.com/Ryujinx/Ryujinx-Ldn-Website.git
synced 2025-08-11 11:11:06 +00:00
Add REDIS_SOCKET env var and prefer it over REDIS_URL
This commit is contained in:
parent
e676e87276
commit
3b7c0b80a1
|
@ -21,11 +21,12 @@
|
|||
This app can be configured using the following environment variables:
|
||||
|
||||
| Name | Description | Default value | Notes |
|
||||
| :---------- | ----------------------------------------------------------------------------------------- | :-----------: | ---------------------------------------------------------------------- |
|
||||
| :------------- | ----------------------------------------------------------------------------------------- | :-----------: | ---------------------------------------------------------------------- |
|
||||
| `NODE_ENV` | This should be set to `production` or `development` depending on the current environment. | `""` | |
|
||||
| `HOST` | The address this server should be listening on. | `"127.0.0.1"` | |
|
||||
| `PORT` | The port this server should be using. | `3000` | |
|
||||
| `REDIS_URL` | The URL of the redis server. | `""` | Format: `redis[s]://[[username][:password]@][host][:port][/db-number]` |
|
||||
| `REDIS_SOCKET` | The path to the unix socket of the redis server. | `""` | If this is not empty `REDIS_URL` will be ignored. |
|
||||
|
||||
## Contribute
|
||||
|
||||
|
|
30
src/app.ts
30
src/app.ts
|
@ -1,6 +1,12 @@
|
|||
import express from "express";
|
||||
import actuator from "express-actuator";
|
||||
import { createClient } from "redis";
|
||||
import {
|
||||
RedisClientOptions,
|
||||
RedisFunctions,
|
||||
RedisModules,
|
||||
RedisScripts,
|
||||
createClient,
|
||||
} from "redis";
|
||||
import winston from "winston";
|
||||
import apiRouter from "./api";
|
||||
import { errorLogger, requestLogger } from "./middleware";
|
||||
|
@ -20,12 +26,26 @@ export const logger = loggerInstance.child({
|
|||
source: "Node",
|
||||
});
|
||||
|
||||
// Init Redis client
|
||||
export const redisClient = createClient({
|
||||
url: process.env.REDIS_URL,
|
||||
const redisClientOptions: RedisClientOptions<
|
||||
RedisModules,
|
||||
RedisFunctions,
|
||||
RedisScripts
|
||||
> = {
|
||||
// NOTE: Enable this if we ever start using cluster mode
|
||||
// readonly: true,
|
||||
});
|
||||
};
|
||||
|
||||
// Prefer unix socket over REDIS_URL
|
||||
if (process.env.REDIS_SOCKET != null && process.env.REDIS_SOCKET.length > 0) {
|
||||
redisClientOptions.socket = {
|
||||
path: process.env.REDIS_SOCKET,
|
||||
};
|
||||
} else {
|
||||
redisClientOptions.url = process.env.REDIS_URL;
|
||||
}
|
||||
|
||||
// Init Redis client
|
||||
export const redisClient = createClient(redisClientOptions);
|
||||
|
||||
redisClient.on("error", (err: Error) =>
|
||||
loggerInstance.error(err.message, {
|
||||
|
|
Loading…
Reference in a new issue