Skip to content

This project tests TCP Redis connectivity in Cloudflare Workers using the `ioredis` client library.

Notifications You must be signed in to change notification settings

akazwz/workers-redis

Repository files navigation

Workers Redis TCP Test

This project tests TCP Redis connectivity in Cloudflare Workers using the ioredis client library.

Overview

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.

Features

  • Simple Redis connectivity test
  • Built with Hono web framework
  • Uses ioredis client
  • TypeScript support
  • Cloudflare Workers deployment ready

Prerequisites

  • Node.js (v18 or higher)
  • pnpm package manager
  • Cloudflare account with Workers access
  • Redis instance (with TCP/TLS support)

Installation

  1. Clone the repository:
git clone https://github.com/akazwz/workers-redis.git
cd workers-redis
  1. Install dependencies:
pnpm install
  1. Set up environment variables:
cp .dev.example.vars .dev.vars
  1. Edit .dev.vars and add your Redis URL:
REDIS_URL=rediss://your-redis-url

Development

Start the development server:

pnpm dev

The worker will be available at http://localhost:8787

API Endpoints

GET /redis

Tests Redis connectivity by setting and getting a test value.

Response:

  • Success: { "value": "test" }
  • Error: { "error": "error message" }

Example:

curl http://localhost:8787/redis

Deployment

  1. Configure your Redis URL as a secret in Cloudflare Workers:
wrangler secret put REDIS_URL
  1. Deploy to Cloudflare Workers:
pnpm deploy

Configuration

The project uses wrangler.jsonc for Cloudflare Workers configuration:

  • Node.js Compatibility: Enabled via nodejs_compat flag
  • Observability: Enabled for monitoring
  • Compatibility Date: Set to ensure stable API behavior

Redis Requirements

Your Redis instance must support:

  • TCP connections (port 6379) or TLS connections (port 6380)
  • External connections from Cloudflare Workers
  • Authentication if required

Recommended Redis Providers

  • Upstash Redis - Serverless Redis with HTTP API (recommended)
  • Redis Cloud - Managed Redis service
  • AWS ElastiCache - With proper VPC configuration

Testing

The /redis endpoint performs a simple connectivity test:

  1. Connects to Redis using the provided URL
  2. Sets a key test with value test
  3. Retrieves the key value
  4. Returns the result

Redis URL Format

# Standard Redis
redis://username:password@host:port

# Redis with TLS
rediss://username:password@host:port

# With database selection
redis://username:password@host:port/db

Test Results

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.

Resources

About

This project tests TCP Redis connectivity in Cloudflare Workers using the `ioredis` client library.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published