This project tests TCP Redis connectivity in Cloudflare Workers using the ioredis client library.
Cloudflare Workers have limited support for TCP connections. This project serves as a test to verify whether Redis connections work properly in the Workers environment using the Node.js compatibility layer.
- Simple Redis connectivity test
- Built with Hono web framework
- Uses ioredis client
- TypeScript support
- Cloudflare Workers deployment ready
- Node.js (v18 or higher)
- pnpm package manager
- Cloudflare account with Workers access
- Redis instance (with TCP/TLS support)
- Clone the repository:
git clone https://github.com/akazwz/workers-redis.git
cd workers-redis- Install dependencies:
pnpm install- Set up environment variables:
cp .dev.example.vars .dev.vars- Edit
.dev.varsand add your Redis URL:
REDIS_URL=rediss://your-redis-url
Start the development server:
pnpm devThe worker will be available at http://localhost:8787
Tests Redis connectivity by setting and getting a test value.
Response:
- Success:
{ "value": "test" } - Error:
{ "error": "error message" }
Example:
curl http://localhost:8787/redis- Configure your Redis URL as a secret in Cloudflare Workers:
wrangler secret put REDIS_URL- Deploy to Cloudflare Workers:
pnpm deployThe project uses wrangler.jsonc for Cloudflare Workers configuration:
- Node.js Compatibility: Enabled via
nodejs_compatflag - Observability: Enabled for monitoring
- Compatibility Date: Set to ensure stable API behavior
Your Redis instance must support:
- TCP connections (port 6379) or TLS connections (port 6380)
- External connections from Cloudflare Workers
- Authentication if required
- Upstash Redis - Serverless Redis with HTTP API (recommended)
- Redis Cloud - Managed Redis service
- AWS ElastiCache - With proper VPC configuration
The /redis endpoint performs a simple connectivity test:
- Connects to Redis using the provided URL
- Sets a key
testwith valuetest - Retrieves the key value
- Returns the result
# Standard Redis
redis://username:password@host:port
# Redis with TLS
rediss://username:password@host:port
# With database selection
redis://username:password@host:port/db
✅ TCP Redis connections work in Cloudflare Workers!
This project successfully demonstrates that Cloudflare Workers can connect to Redis using TCP with the Node.js compatibility layer enabled.