@hile/ioredis
Create Redis clients manually or as Hile services with lifecycle cleanup.Choose This Package When
Use When
Use these packages when an app needs managed startup, singleton resources, dependency ordering, environment-file loading, graceful shutdown, logs, Redis, or SQL database connections.Do Not Use When
- Do not use
loadService()at module top level. - Do not use
auto_load_packagesfor file paths. It accepts package names only. - Do not use the default
@hile/ioredisor@hile/typeormservices when one app needs multiple Redis or database connections; define separate services with separate keys.
Install
Imports
Copy-Paste Example
More Examples
Usepackage.json auto-load for integration services that default-export a Hile service:
Runtime And Lifecycle Notes
defineService(key, fn)registers a service factory and does not execute it.loadService(service)executes the factory on first call and returns the cached value afterwards.- The
shutdowncallback registers teardown functions; they run in LIFO order. - The container tracks dependencies when service factories call
loadService(). container.shutdown()triggers registered teardowns.@hile/bootstraploads env files first, setsNODE_ENV, imports auto-load packages, scans boot files, and installs exit hooks.@hile/logger.createLogger()returns{ logger, teardown }.@hile/ioredis.createRedis()waits forconnect.@hile/typeorm.createDataSource()initializes a TypeORMDataSource.
Anti-Patterns
- Reusing one service key for unrelated factories.
- Missing
shutdown()callbacks for network connections or servers. - Assuming TypeORM env config fills entities automatically when
TYPEORM_ENTITIESis not set. - Calling
transaction()and manually committing; the helper commits or rolls back internally.
Verification Checklist
- Boot files default-export
defineService(...). - Long-lived resources register teardown callbacks.
auto_load_packagescontains package names, not local files.hile start --devcan findsrc/**/*.boot.ts.- Production build emits
dist/**/*.boot.js.
Related Recipes
Redis Cache With Singleflight
Complete Example
Package-Local AI Guide
This package also shipsAI.md in npm so agents can read accurate examples after installation.