Skip to main content

r2d2

Simple, lightweight Redis client library for Deno.

Usage

Basic commands

import { sendCommand } from "https://deno.land/x/r2d2/mod.ts";

const redisConn = await Deno.connect({ port: 6379 });

/** Resolves to "OK" */
await sendCommand(redisConn, ["SET", "hello", "world"]);

/** Prints "world" */
console.log(await sendCommand(redisConn, ["GET", "hello"]));

redisConn.close();

If you’d like to ignore the reply.

await sendCommand(redis, ["SHUTDOWN"], false);

Pipelining

import { pipelineCommands } from "https://deno.land/x/r2d2/mod.ts";

const redisConn = await Deno.connect({ port: 6379 });

// Resolves to [1, 2, 3, 4]
await pipelineCommands(redisConn, [
  ["INCR", "X"],
  ["INCR", "X"],
  ["INCR", "X"],
  ["INCR", "X"],
]);

Principles

  1. Designed to be fundamentally simple
  2. Takes advantage of native Deno APIs and Deno’s standard library without custom classes
  3. Promotes using Redis commands without intermediate abstractions

Prerequisites

Redis must be installed on your local machine (guide here). Doing so enables the use of the redis-server CLI tool, which is used to start a local Redis server for testing and benchmarks.

Testing

deno task test

Benchmarks

deno task bench