Lightweight Redis client library for Deno. Design principles:
- Must be fundamentally simple
- Use native Deno APIs and Deno's standard library without custom interfaces
- Encourage the use of actual Redis commands without intermediate abstractions
Must be run with --allow-net
permission.
import { sendCommand } from "https://deno.land/x/r2d2/mod.ts";
const redisConn = await Deno.connect({ port: 6379 });
// Returns "OK"
await sendCommand(redisConn, ["SET", "hello", "world"]);
// Returns "world"
await sendCommand(redisConn, ["GET", "hello"]);
If you don't care about the reply:
import { writeCommand } from "https://deno.land/x/r2d2/mod.ts";
const redisConn = await Deno.connect({ port: 6379 });
// Returns nothing
await writeCommand(redisConn, ["SHUTDOWN"]);
import {
sendCommand,
sendCommandRawReply,
} from "https://deno.land/x/r2d2/mod.ts";
const redisConn = await Deno.connect({ port: 6379 });
const value = new Uint8Array([0, 1, 2, 1, 2, 1, 2, 3]);
// Returns "OK"
await sendCommand(redisConn, ["SET", "binary", value]);
// Returns Uint8Array(8) [0, 1, 2, 1, 2, 1, 2, 3]
await sendCommandRawReply(redisConn, ["GET", "binary"]);
import { pipelineCommands } from "https://deno.land/x/r2d2/mod.ts";
const redisConn = await Deno.connect({ port: 6379 });
// Returns [1, 2, 3, 4]
await pipelineCommands(redisConn, [
["INCR", "X"],
["INCR", "X"],
["INCR", "X"],
["INCR", "X"],
]);
import { listenReplies, writeCommand } from "https://deno.land/x/r2d2/mod.ts";
const redisConn = await Deno.connect({ port: 6379 });
await writeCommand(redisConn, ["SUBSCRIBE", "mychannel"]);
for await (const reply of listenReplies(redisConn)) {
// Prints ["subscribe", "mychannel", 1] first iteration
console.log(reply);
}
Check out the documentation here.
deno task test
Note: Redis must be installed on your local machine. For installation instructions, see here.
deno task bench
Note: Redis must be installed on your local machine. For installation instructions, see here.
These resources, one way or another, inspired the creation of this module. If you're one of the authors, thank you.
- redis - 🦕 Redis client for Deno 🍕
- tiny-redis - TinyRedis is a Redis server and Redis protocol facilities developed with TypeScript and platformed on Deno.
- Native GET and SET operations on REDIS - article with a self-explanatory title.