feat/redis cache connector: Add Redis Cache Connector with TTL, Namespacing, and Retry Support #125
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add Redis Cache Connector with TTL, Namespacing, Retry Support, and Demo Agent
📌 Summary
This PR introduces a Redis cache connector for SmythOS SRE projects along with a demo AI agent that shows cache hit/miss behavior in practice.
✨ Features
set/get/del/keys/flushNamespace/quit API
JSON auto-serialization & parsing
TTL support (per key + global default)
Namespacing to prevent collisions across agents
Retries with exponential backoff for reliability
TLS support (rediss:// or REDIS_TLS=true)
Demo AI Agent that wraps an LLM (OpenAI, Google Gemini, or mock fallback) and logs [CACHE MISS] and [CACHE HIT]
✅ Verification Steps
Start Redis locally:
npm run redis:up
npm run redis:ping # expect "PONG"
Run connector smoke check:
npm run redis:cache-check
Expected output:
get(hello) -> world
get(obj) -> { a: 1, b: 'x' }
keys(*) -> [...]
after del(hello) -> null
✅ Connector smoke passed
Run automated tests:
npm run test:redis
✅ All 5 tests pass
Run the AI agent demo:
npm run agent:demo:prompt
Example output:
[CACHE MISS] key=demo-llm:... → querying model...
[CACHE STORE] key=demo-llm:... → saved with TTL=120s
OUT 1: ...
[CACHE HIT] key=demo-llm:...
OUT 2: ...
✅ Demo complete (second call faster due to cache)
🧪 Test Coverage
String roundtrip
TTL expiration behavior
JSON object storage/retrieval
keys() returns namespaced keys
del() removes items
📂 Folder Structure
src/
connectors/
redis/
index.ts # main connector
utils/
retry.ts # retry/backoff helper
agents/
cached-llm.ts # Redis-cached LLM wrapper
adapters.ts # OpenAI, Google, Mock adapters
scripts/
redis-cache-check.ts # smoke test
demo-agent.ts # demo agent with cache
test/
redis.test.ts # automated tests