redis-on-workers
TypeScript icon, indicating that this package has built-in type declarations

0.2.9 • Public • Published

redis-on-workers

Connect to your Redis server using cloudflare:sockets.

This package is designed to work with Cloudflare Workers, but it can also be used in node.js thanks to the implementation of cloudflare:sockets for node.js.

Installation

npm install redis-on-workers

Usage

Minimal

This is the minimal example to connect to a Redis server.

import { createRedis } from "redis-on-workers";

const redis = createRedis({
  url: "redis://<username>:<password>@<host>:<port>",
});

await redis("SET", "foo", "bar");

const value = await redis("GET", "foo");

console.log(value); // bar

Raw Uint8Array

This is useful if you want to store binary data. For example, you can store protobuf messages in Redis.

import { createRedis } from "redis-on-workers";

const redis = createRedis({
  url: "redis://<username>:<password>@<host>:<port>",
});

await redis.raw("SET", "foo", "bar");

const value = await redis.raw("GET", "foo");

const decoder = new TextDecoder();

console.log(decoder.decode(value)); // bar

Node.js

Please install the node.js polyfill for cloudflare:sockets to use this package in node.js.

npm install @arrowood.dev/socket

API

createRedis(options: RedisOptions): Redis

Create a new Redis client, does NOT connect to the server yet, the connection will be established when the first command is sent.

RedisOptions

  • url (string): The URL of the Redis server.
  • tls (boolean): Whether to use TLS. Default: false.
  • logger (function): A function to log debug messages.
  • connectFn (function): Polyfill for cloudflare:sockets's connect function if you're using it in node.js. Default: undefined.

Package Sidebar

Install

npm i redis-on-workers

Weekly Downloads

6

Version

0.2.9

License

MIT

Unpacked Size

33.1 kB

Total Files

7

Last publish

Collaborators

  • gary50613