Giter Site home page Giter Site logo

kane50613 / redis-on-workers Goto Github PK

View Code? Open in Web Editor NEW
7.0 2.0 0.0 191 KB

Connect to your Redis server using cloudflare:sockets

License: MIT License

JavaScript 0.42% TypeScript 99.58%
cloudflare cloudflare-pages-functions cloudflare-workers edge redis socket

redis-on-workers's Introduction

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.

redis-on-workers's People

Contributors

kane50613 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

redis-on-workers's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/publish.yaml
  • actions/checkout v4
  • actions/setup-node v4
  • pnpm/action-setup v3
  • actions/cache v4
.github/workflows/test.yaml
  • actions/checkout v4
  • actions/setup-node v4
  • pnpm/action-setup v3
  • actions/cache v4
npm
package.json
  • @cloudflare/workers-types ^4.20240222.0
  • @types/node ^20.11.24
  • prettier ^3.2.5
  • prettier-plugin-organize-imports ^3.2.4
  • tsup ^8.0.2
  • tsx ^4.7.1
  • typescript ^5.3.3
  • vitest ^1.3.1
  • @arrowood.dev/socket ^0.2.0

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.