Attributes
Includes Deno configuration
Repository
Current version released
2 years ago
r2d2
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 use of actual Redis commands without intermediate abstractions
Usage
Must be run with --allow-net
permission.
Single command
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"]);
Multiple commands (pipelining)
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"],
]);
Pub/sub
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 [_, channel, message] of listenReplies(redisConn)) {
// Prints "mychannel" says 1
console.log(`${channel} says ${message}`);
await writeCommand(redisConn, ["UNSUBSCRIBE"]);
break;
}
Single command, no reply
import { writeCommand } from "https://deno.land/x/r2d2/mod.ts";
const redisConn = await Deno.connect({ port: 6379 });
// Returns nothing
await writeCommand(redisConn, ["SHUTDOWN"]);
Documentation
Check out the documentation here.
Testing
deno task test
Note: Redis must be installed on your local machine. For installation instructions, see here.
Benchmarks
deno task bench
Note: Redis must be installed on your local machine. For installation instructions, see here.
Related
- redis - 🦕 Redis client for Deno 🍕