Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ TRACING=dev
# file uploads
FILE_UPLOADS_DOWNLOAD_SECRET=gPM8DTrrAdCMPYaNM99sH6hgtJfPWuEV

# redis
REDIS_ENABLED=true
REDIS_PORT=6379
REDIS_HOST=localhost
REDIS_PASSWORD=vivid
# valkey
VALKEY_ENABLED=true
VALKEY_PORT=6379
VALKEY_HOST=localhost
VALKEY_PASSWORD=vivid

# oauth2-proxy
OAUTH2_PROXY_VERSION=^7.12.0
Expand Down
28 changes: 14 additions & 14 deletions demo/site/cache-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,30 @@ import { CacheHandler as NextCacheHandler } from "next/dist/server/lib/increment

import { getOrCreateCounter, getOrCreateHistogram } from "./opentelemetry-metrics";

const REDIS_HOST = process.env.REDIS_HOST;
if (!REDIS_HOST) {
throw new Error("REDIS_HOST is required");
const VALKEY_HOST = process.env.VALKEY_HOST;
if (!VALKEY_HOST) {
throw new Error("VALKEY_HOST is required");
}

const REDIS_PORT = parseInt(process.env.REDIS_PORT || "6379", 10);
const VALKEY_PORT = parseInt(process.env.VALKEY_PORT || "6379", 10);

const REDIS_PASSWORD = process.env.REDIS_PASSWORD;
if (!REDIS_PASSWORD) {
throw new Error("REDIS_PASSWORD is required");
const VALKEY_PASSWORD = process.env.VALKEY_PASSWORD;
if (!VALKEY_PASSWORD) {
throw new Error("VALKEY_PASSWORD is required");
}

const REDIS_KEY_PREFIX = process.env.REDIS_KEY_PREFIX || "";
const VALKEY_KEY_PREFIX = process.env.VALKEY_KEY_PREFIX || "";

const CACHE_HANDLER_DEBUG = process.env.CACHE_HANDLER_DEBUG === "true";

const CACHE_TTL_IN_S = 24 * 60 * 60; // 1 day

const redis = new Redis({
enableOfflineQueue: false,
host: REDIS_HOST,
keyPrefix: REDIS_KEY_PREFIX,
password: REDIS_PASSWORD,
port: REDIS_PORT,
host: VALKEY_HOST,
keyPrefix: VALKEY_KEY_PREFIX,
password: VALKEY_PASSWORD,
port: VALKEY_PORT,
enableAutoPipelining: true,
});

Expand Down Expand Up @@ -92,7 +92,7 @@ export default class CacheHandler {
const redisResponse = await redis.get(key);
if (isFallbackInUse) {
isFallbackInUse = false;
console.info(`${new Date().toISOString()} [${REDIS_HOST} up] Switching back to redis cache`);
console.info(`${new Date().toISOString()} [${VALKEY_HOST} up] Switching back to redis cache`);
}
if (!redisResponse) {
cacheMissCount.add(1);
Expand All @@ -115,7 +115,7 @@ export default class CacheHandler {

// fallback to in-memory cache
if (!isFallbackInUse) {
console.warn(`${new Date().toISOString()} | [${REDIS_HOST} down] switching to fallback in-memory cache`);
console.warn(`${new Date().toISOString()} | [${VALKEY_HOST} down] switching to fallback in-memory cache`);
isFallbackInUse = true;
}

Expand Down
4 changes: 2 additions & 2 deletions demo/site/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ const nextConfig = {
],
},
],
cacheHandler: process.env.REDIS_ENABLED === "true" ? import.meta.resolve("./dist/cache-handler.js").replace("file://", "") : undefined,
cacheMaxMemorySize: process.env.REDIS_ENABLED === "true" ? 0 : undefined, // disable default in-memory caching
cacheHandler: process.env.VALKEY_ENABLED === "true" ? import.meta.resolve("./dist/cache-handler.js").replace("file://", "") : undefined,
cacheMaxMemorySize: process.env.VALKEY_ENABLED === "true" ? 0 : undefined, // disable default in-memory caching
rewrites: () => {
return {
afterFiles: [
Expand Down
12 changes: 6 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ services:
COLLECTOR_OTLP_ENABLED: "true"
COLLECTOR_OTLP_HTTP_HOST_PORT: 0.0.0.0:4318

redis:
image: redis:7
valkey:
image: valkey/valkey:8
pull_policy: weekly
command: redis-server --maxmemory 256M --maxmemory-policy allkeys-lru --loglevel warning --requirepass ${REDIS_PASSWORD}
command: valkey-server --maxmemory 256M --maxmemory-policy allkeys-lru --loglevel warning --requirepass ${VALKEY_PASSWORD}
ports:
- "127.0.0.1:${REDIS_PORT}:6379"
- "127.0.0.1:${VALKEY_PORT}:6379"
networks:
- redis
- valkey

mailpit:
image: axllent/mailpit
Expand All @@ -64,7 +64,7 @@ services:
networks:
postgres:
driver: bridge
redis:
valkey:
driver: bridge

volumes:
Expand Down