Registry / database / redis-on-workers

redis-on-workers

JSON →
library0.4.2jsnpmunverified

A Redis client for Cloudflare Workers using cloudflare:sockets. Current version: 0.4.2. Actively maintained with fast release cadence. Key differentiator: works natively in Cloudflare Workers environment without polyfills, supports TLS, raw Uint8Array commands, and can also run in Node.js with @arrowood.dev/socket. Minimal and lightweight compared to ioredis.

npm install redis-on-workers
INSTALL
IMPORT
SIG · REDIS-ON-WORKERS
R
redis-on-workers
databasejavascriptv0.4.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createRedis
import { createRedis } from 'redis-on-workers'
const createRedis = require('redis-on-workers')
Package is ESM-only; CommonJS require is unsupported.
RedisInstance
import type { RedisInstance } from 'redis-on-workers'
import { RedisInstance } from 'redis-on-workers'
Type-only import; use `import type` to avoid runtime errors.
CreateRedisOptions
import { CreateRedisOptions } from 'redis-on-workers'
import CreateRedisOptions from 'redis-on-workers'
Named export, not default.
redis.send
const result = await redis.send('GET', 'key')
const result = await redis.send(['GET', 'key'])
Accepts separate arguments, not an array.

Connects to Redis and performs a simple SET/GET, then closes the connection.

import { createRedis } from 'redis-on-workers'; const redis = createRedis(`redis://${process.env.REDIS_USER ?? ''}:${process.env.REDIS_PASS ?? ''}@${process.env.REDIS_HOST ?? 'localhost'}:${process.env.REDIS_PORT ?? '6379'}`); await redis.send('SET', 'hello', 'world'); const value = await redis.send('GET', 'hello'); console.log(value); // 'world' await redis.close();
Debug
Known issues
gotchaThe connection is lazy: it is established on the first command, not on createRedis(). Call 'await redis.connection()' to explicitly initiate.
fix
Use 'await redis.connection()' immediately after createRedis if you need to ensure the connection is available.
affects: all
gotchaUsing send() returns a string; for binary data use sendRaw/sendOnceRaw which return Uint8Array.
fix
Use sendRaw for raw bytes; use sendOnceRaw for a one-off command returning Uint8Array.
affects: all
breakingVersion 0.4.0 changed the default export to named exports; createRedis is no longer the default.
fix
Replace 'import createRedis from "redis-on-workers"' with 'import { createRedis } from "redis-on-workers"'.
affects: >=0.4.0
gotchaThe 'tls' option in CreateRedisOptions is not inferred from the URL scheme; you must set it explicitly if the URL does not use 'rediss'.
fix
Set tls: true in options or use 'rediss://' URL to enable TLS automatically.
affects: all
Errors
Common errors & fixes
SyntaxError: Cannot use import statement outside a module
Package is ESM-only, but project is configured as CommonJS or missing `"type": "module"` in package.json.
fix
Add `"type": "module"` to your package.json or use dynamic import() if stuck with CommonJS.
TypeError: createRedis is not a function
Using default import when the package only exports named exports.
fix
Use `import { createRedis } from 'redis-on-workers'` instead of `import createRedis from 'redis-on-workers'`.
Error: connect ECONNREFUSED <host>:<port>
Redis server is not running or host/port are incorrect.
fix
Ensure Redis is running and verify the URL string passed to createRedis.
Error: ERR AUTH <database>: authentication required
No password provided or invalid password.
fix
Include username:password in the Redis URL, e.g., `redis://user:pass@host:port`.
Upgrade
Version history
0.4.2latest on npm
Audit
Dependencies
@arrowood.dev/socketoptionalRequired to use the package in Node.js as a polyfill for cloudflare:sockets
Agent activity
14 hits · last 30 days
node
12
Meta
1
Resources
redis-on-workers — npm install redis-on-workers · libregistry