feat: cache server

This commit is contained in:
ThatOneCalculator 2023-07-06 11:50:34 -07:00
parent 53ec5f7048
commit f5c7b6f55f
4 changed files with 44 additions and 9 deletions

View file

@ -67,6 +67,20 @@ redis:
#db: 1 #db: 1
#user: default #user: default
# ┌─────────────────────────────┐
#───┘ Cache server configuration └─────────────────────────────────────
# A Redis-compatible server (DragonflyDB, Keydb, Redis) for caching
# If left blank, it will use the Redis server from above
#cacheServer:
#host: localhost
#port: 6379
#family: 0 # 0=Both, 4=IPv4, 6=IPv6
#pass: example-pass
#prefix: example-prefix
#db: 1
# Please configure either MeiliSearch *or* Sonic. # Please configure either MeiliSearch *or* Sonic.
# If both MeiliSearch and Sonic configurations are present, MeiliSearch will take precedence. # If both MeiliSearch and Sonic configurations are present, MeiliSearch will take precedence.

View file

@ -104,7 +104,10 @@ If you have access to a server that supports one of the sources below, I recomme
- 🦔 [Sonic](https://crates.io/crates/sonic-server) - 🦔 [Sonic](https://crates.io/crates/sonic-server)
- [MeiliSearch](https://www.meilisearch.com/) - [MeiliSearch](https://www.meilisearch.com/)
- [ElasticSearch](https://www.elastic.co/elasticsearch/) - [ElasticSearch](https://www.elastic.co/elasticsearch/)
- Caching server
- 🐲 At least [Dragonfly](https://www.dragonflydb.io/) v1.4.0 (recommended)
- 👻 [KeyDB](https://keydb.dev/) (untested)
- 🍱 Another [Redis](https://redis.io/) server, at least v6
### 🏗️ Build dependencies ### 🏗️ Build dependencies
- 🦀 At least [Rust](https://www.rust-lang.org/) v1.68.0 - 🦀 At least [Rust](https://www.rust-lang.org/) v1.68.0
@ -161,6 +164,10 @@ psql postgres -c "create database calckey with encoding = 'UTF8';"
In Calckey's directory, fill out the `db` section of `.config/default.yml` with the correct information, where the `db` key is `calckey`. In Calckey's directory, fill out the `db` section of `.config/default.yml` with the correct information, where the `db` key is `calckey`.
## 💰 Caching server
If you experience a lot of traffic, it's a good idea to set up another Redis-compatible caching server. If you don't set one one up, it'll falll back to the mandatory Redis server.
## 🔎 Set up search ## 🔎 Set up search
### 🦔 Sonic ### 🦔 Sonic

View file

@ -26,6 +26,16 @@ export type Source = {
user?: string; user?: string;
tls?: { [y: string]: string }; tls?: { [y: string]: string };
}; };
cacheServer: {
host: string;
port: number;
family?: number;
pass?: string;
db?: number;
prefix?: string;
user?: string;
tls?: { [z: string]: string };
};
elasticsearch: { elasticsearch: {
host: string; host: string;
port: number; port: number;

View file

@ -2,15 +2,19 @@ import Redis from "ioredis";
import config from "@/config/index.js"; import config from "@/config/index.js";
export function createConnection() { export function createConnection() {
let source = config.redis;
if (config.cacheServer) {
source = config.cacheServer;
}
return new Redis({ return new Redis({
port: config.redis.port, port: source.port,
host: config.redis.host, host: source.host,
family: config.redis.family ?? 0, family: source.family ?? 0,
password: config.redis.pass, password: source.pass,
username: config.redis.user ?? "default", username: source.user ?? "default",
keyPrefix: `${config.redis.prefix}:`, keyPrefix: `${source.prefix}:`,
db: config.redis.db || 0, db: source.db || 0,
tls: config.redis.tls, tls: source.tls,
}); });
} }