81 lines
2.7 KiB
TypeScript
81 lines
2.7 KiB
TypeScript
/**
|
|
* Dragonfly (Redis replacement) configuration using Yup
|
|
* High-performance caching and event streaming
|
|
*/
|
|
import { cleanEnv, envValidators } from './env-utils';
|
|
|
|
const { str, port, num, bool } = envValidators;
|
|
|
|
/**
|
|
* Dragonfly configuration with validation and defaults
|
|
*/
|
|
export const dragonflyConfig = cleanEnv(process.env, {
|
|
// Dragonfly Connection
|
|
DRAGONFLY_HOST: str('localhost', 'Dragonfly host'),
|
|
DRAGONFLY_PORT: port(6379, 'Dragonfly port'),
|
|
DRAGONFLY_PASSWORD: str('', 'Dragonfly password (if auth enabled)'),
|
|
DRAGONFLY_USERNAME: str('', 'Dragonfly username (if ACL enabled)'),
|
|
|
|
// Database Selection
|
|
DRAGONFLY_DATABASE: num(0, 'Dragonfly database number (0-15)'),
|
|
|
|
// Connection Pool Settings
|
|
DRAGONFLY_MAX_RETRIES: num(3, 'Maximum retry attempts'),
|
|
DRAGONFLY_RETRY_DELAY: num(50, 'Retry delay in ms'),
|
|
DRAGONFLY_CONNECT_TIMEOUT: num(10000, 'Connection timeout in ms'),
|
|
DRAGONFLY_COMMAND_TIMEOUT: num(5000, 'Command timeout in ms'),
|
|
|
|
// Pool Configuration
|
|
DRAGONFLY_POOL_SIZE: num(10, 'Connection pool size'),
|
|
DRAGONFLY_POOL_MIN: num(1, 'Minimum pool connections'),
|
|
DRAGONFLY_POOL_MAX: num(20, 'Maximum pool connections'),
|
|
|
|
// TLS Settings
|
|
DRAGONFLY_TLS: bool(false, 'Enable TLS for Dragonfly connection'),
|
|
DRAGONFLY_TLS_CERT_FILE: str('', 'Path to TLS certificate file'),
|
|
DRAGONFLY_TLS_KEY_FILE: str('', 'Path to TLS key file'),
|
|
DRAGONFLY_TLS_CA_FILE: str('', 'Path to TLS CA certificate file'),
|
|
DRAGONFLY_TLS_SKIP_VERIFY: bool(false, 'Skip TLS certificate verification'),
|
|
|
|
// Performance Settings
|
|
DRAGONFLY_ENABLE_KEEPALIVE: bool(true, 'Enable TCP keepalive'),
|
|
DRAGONFLY_KEEPALIVE_INTERVAL: num(60, 'Keepalive interval in seconds'),
|
|
|
|
// Clustering (if using cluster mode)
|
|
DRAGONFLY_CLUSTER_MODE: bool(false, 'Enable cluster mode'),
|
|
DRAGONFLY_CLUSTER_NODES: str('', 'Comma-separated list of cluster nodes (host:port)'),
|
|
|
|
// Memory and Cache Settings
|
|
DRAGONFLY_MAX_MEMORY: str('2gb', 'Maximum memory usage'),
|
|
DRAGONFLY_CACHE_MODE: bool(true, 'Enable cache mode'),
|
|
});
|
|
|
|
// Export typed configuration object
|
|
export type DragonflyConfig = typeof dragonflyConfig;
|
|
|
|
// Export individual config values for convenience
|
|
export const {
|
|
DRAGONFLY_HOST,
|
|
DRAGONFLY_PORT,
|
|
DRAGONFLY_PASSWORD,
|
|
DRAGONFLY_USERNAME,
|
|
DRAGONFLY_DATABASE,
|
|
DRAGONFLY_MAX_RETRIES,
|
|
DRAGONFLY_RETRY_DELAY,
|
|
DRAGONFLY_CONNECT_TIMEOUT,
|
|
DRAGONFLY_COMMAND_TIMEOUT,
|
|
DRAGONFLY_POOL_SIZE,
|
|
DRAGONFLY_POOL_MIN,
|
|
DRAGONFLY_POOL_MAX,
|
|
DRAGONFLY_TLS,
|
|
DRAGONFLY_TLS_CERT_FILE,
|
|
DRAGONFLY_TLS_KEY_FILE,
|
|
DRAGONFLY_TLS_CA_FILE,
|
|
DRAGONFLY_TLS_SKIP_VERIFY,
|
|
DRAGONFLY_ENABLE_KEEPALIVE,
|
|
DRAGONFLY_KEEPALIVE_INTERVAL,
|
|
DRAGONFLY_CLUSTER_MODE,
|
|
DRAGONFLY_CLUSTER_NODES,
|
|
DRAGONFLY_MAX_MEMORY,
|
|
DRAGONFLY_CACHE_MODE,
|
|
} = dragonflyConfig;
|