25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
/**
* Formats Redis TTL (seconds) as a compact human-readable remaining time:
* 从大到小取前两个非零单位,例如:
* 45 → 45s / 45秒
* 3661 → 1h 1m / 1小时 1分钟
* 93784 → 1d 2h / 1天 2小时
*
* Returns null for ttl === -1 (no expiry) or ttl <= 0.
*/
type TranslateFn = (key: string, options?: Record<string, unknown>) => string;
export function formatTtl(ttl: number, t: TranslateFn): string | null {
if (ttl === -1) return null;
if (ttl <= 0) return null;
const days = Math.floor(ttl / 86_400);
const hours = Math.floor((ttl % 86_400) / 3_600);
const minutes = Math.floor((ttl % 3_600) / 60);
const seconds = ttl % 60;
// 按从大到小排列四个单位,只保留前两个非零单位,避免展示过长
const units: Array<[number, string]> = [
[days, "redis.ttlDay"],
[hours, "redis.ttlHour"],
[minutes, "redis.ttlMinute"],
[seconds, "redis.ttlSecond"],
];
return units
.filter(([value]) => value > 0)
.slice(0, 2)
.map(([value, key]) => t(key, { count: value }))
.join(" ");
}