[BUG] RedisBackend connection always times out (lazyConnect never triggers) and lacks support for STORAGE_CACHE_USERNAME
Bug Description
RedisBackend.connect() always throws a 1 s timeout because it forces lazyConnect: true but never explicitly starts the handshake.
Additionally, .env lacks STORAGE_CACHE_USERNAME, so Redis ACL username cannot be provided via environment variables.
Steps to Reproduce
Steps to reproduce the behavior:
- Clone the repo and install dependencies
git clone https://github.com/campfirein/cipher.git
cd cipher && pnpm i
- Create a minimal repro minimal-repro.ts
import { RedisBackend } from '@/storage/backend/redis-backend'
const redis = new RedisBackend({
type: 'redis',
host: '127.0.0.1',
port: 6379,
database: 0,
options: { username: 'default' } // show username need
})
await redis.connect() // will timeout after 1 s
- Run it
npx tsx minimal-repro.ts
- Observe Redis connection failed: timeout in console.
Expected Behavior
-
await redis.connect() should establish the connection and emit ready within a reasonable (and configurable) timeout.
-
Username should be configurable via STORAGE_CACHE_USERNAME, analogous to STORAGE_CACHE_PASSWORD.
Actual Behavior
-
Always throws Redis connection failed: timeout.
-
Username can only be hard-coded through options.username.
Screenshots
N/A (CLI reproduction is sufficient).
Environment Information
- OS: macOS
- Node.js version:v23.5.0
- pnpm version:10.0.0
- Redis version:7.2.6
Logs and Error Messages
⏳ connecting …
❌ Error: Error: Redis connection failed: timeout
at Timeout._onTimeout (../cipher/src/core/storage/backend/redis-backend.ts:126:13)
at listOnTimeout (node:internal/timers:614:17)
at process.processTimers (node:internal/timers:549:7)
Additional Context
While reading and debugging the code I noticed:
- lazyConnect is true but this.redis.connect() is never called, so the handshake never starts.
- The hard-coded 1 s timer means any delay is treated as a failure.
- .env.example lacks a username field, and the config loader doesn’t read it.
Possible Solution
-
Call this.redis.connect() inside RedisBackend.connect() or default lazyConnect to false.
-
Add STORAGE_CACHE_USERNAME to .env and inject it via options.username.
-
Make the connection timeout configurable (e.g., REDIS_CONNECT_TIMEOUT_MS).
Checklist
- [✓] I have searched for similar issues before creating this one
- [ ✓] I have provided all the requested information above
- [ x ] I have tested this on the latest version
Thanks for the awesome project — I’m really enjoying reading the code and experimenting with Cipher. Looking forward to your feedback! 🙌
thanks for your report issue. I'll tackle this in day
@WakeUp-Jin Please check out our latest commit to see if your issue has been fixed!
@WakeUp-Jin I'll close this issue. Feel free to reopen it if you have any problem!