添加 Redis 支持
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2026-04-09 15:57:28 +08:00
parent cd689aba98
commit 5e5f13a949
6 changed files with 67 additions and 0 deletions

View File

@ -38,6 +38,11 @@ export default defineConfig({
access: 'secret',
default: 'https://legacy.passthem.top/api',
}),
REDIS_URL: envField.string({
context: 'server',
access: 'secret',
default: '',
}),
},
},
})

53
package-lock.json generated
View File

@ -14,6 +14,7 @@
"@astrojs/vue": "^6.0.1",
"@iconify-json/material-symbols": "^1.2.65",
"@iconify-json/mdi": "^1.2.3",
"@keyv/redis": "^5.1.6",
"@markdoc/markdoc": "^0.5.7",
"@traptitech/markdown-it-katex": "^3.6.0",
"@types/react": "^19.2.14",
@ -1977,6 +1978,23 @@
"@jridgewell/sourcemap-codec": "^1.4.14"
}
},
"node_modules/@keyv/redis": {
"version": "5.1.6",
"resolved": "https://registry.npmjs.org/@keyv/redis/-/redis-5.1.6.tgz",
"integrity": "sha512-eKvW6pspvVaU5dxigaIDZr635/Uw6urTXL3gNbY9WTR8d3QigZQT+r8gxYSEOsw4+1cCBsC4s7T2ptR0WC9LfQ==",
"license": "MIT",
"dependencies": {
"@redis/client": "^5.10.0",
"cluster-key-slot": "^1.1.2",
"hookified": "^1.13.0"
},
"engines": {
"node": ">= 18"
},
"peerDependencies": {
"keyv": "^5.6.0"
}
},
"node_modules/@keyv/serialize": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@keyv/serialize/-/serialize-1.1.1.tgz",
@ -2089,6 +2107,26 @@
"integrity": "sha512-wwQAWhWSuHaag8c4q/KN/vCoeOJYshAIvMQwD4GpSb3OiZklFfvAgmj0VCBBImRpuF/aFgIRzllXlVX93Jevww==",
"license": "MIT"
},
"node_modules/@redis/client": {
"version": "5.11.0",
"resolved": "https://registry.npmjs.org/@redis/client/-/client-5.11.0.tgz",
"integrity": "sha512-GHoprlNQD51Xq2Ztd94HHV94MdFZQ3CVrpA04Fz8MVoHM0B7SlbmPEVIjwTbcv58z8QyjnrOuikS0rWF03k5dQ==",
"license": "MIT",
"dependencies": {
"cluster-key-slot": "1.1.2"
},
"engines": {
"node": ">= 18"
},
"peerDependencies": {
"@node-rs/xxhash": "^1.1.0"
},
"peerDependenciesMeta": {
"@node-rs/xxhash": {
"optional": true
}
}
},
"node_modules/@rolldown/pluginutils": {
"version": "1.0.0-rc.2",
"resolved": "https://registry.npmjs.org/@rolldown/pluginutils/-/pluginutils-1.0.0-rc.2.tgz",
@ -3939,6 +3977,15 @@
"node": ">=6"
}
},
"node_modules/cluster-key-slot": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/cluster-key-slot/-/cluster-key-slot-1.1.2.tgz",
"integrity": "sha512-RMr0FhtfXemyinomL4hrWcYJxmX6deFdCxpJzhDttxgO1+bcCnkk+9drydLVDmAMG7NE6aN/fl4F7ucU/90gAA==",
"license": "Apache-2.0",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/colorette": {
"version": "2.0.20",
"resolved": "https://registry.npmjs.org/colorette/-/colorette-2.0.20.tgz",
@ -5642,6 +5689,12 @@
"integrity": "sha512-Yc+BQe8SvoXH1643Qez1zqLRmbA5rCL+sSmk6TVos0LWVfNIB7PGncdlId77WzLGSIB5KaWgTaNTs2lNVEI6VQ==",
"license": "MIT"
},
"node_modules/hookified": {
"version": "1.15.1",
"resolved": "https://registry.npmjs.org/hookified/-/hookified-1.15.1.tgz",
"integrity": "sha512-MvG/clsADq1GPM2KGo2nyfaWVyn9naPiXrqIe4jYjXNZQt238kWyOGrsyc/DmRAQ+Re6yeo6yX/yoNCG5KAEVg==",
"license": "MIT"
},
"node_modules/html-escaper": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-3.0.3.tgz",

View File

@ -32,6 +32,7 @@
"@astrojs/vue": "^6.0.1",
"@iconify-json/material-symbols": "^1.2.65",
"@iconify-json/mdi": "^1.2.3",
"@keyv/redis": "^5.1.6",
"@markdoc/markdoc": "^0.5.7",
"@traptitech/markdown-it-katex": "^3.6.0",
"@types/react": "^19.2.14",

View File

@ -0,0 +1,4 @@
import { REDIS_URL } from 'astro:env/server'
import KeyvRedis from '@keyv/redis'
export const storage = REDIS_URL ? new KeyvRedis(REDIS_URL) : new Map()

View File

@ -3,10 +3,12 @@ import './server-only.ts'
import type { RenderableTreeNode } from '@markdoc/markdoc'
import KeyV from 'keyv'
import { createHash } from 'node:crypto'
import { storage } from './keyv-cache.server.ts'
const markdocVersion = '1'
export const markdocCache = new KeyV<RenderableTreeNode>({
store: storage,
namespace: `markdoc-cache-${markdocVersion}`,
ttl: 1000 * 60 * 60 * 24 * 7,
})

View File

@ -10,10 +10,12 @@ import { ensureShikiEngine } from '../lib/markdown'
import Markdoc from '@markdoc/markdoc'
import KeyV from 'keyv'
import { createHash } from 'node:crypto'
import { storage } from '../lib/keyv-cache.server'
export const prerender = false
const renderCache = new KeyV<string>({
store: storage,
namespace: 'markdoc-rss',
})