Skip to content

Instantly share code, notes, and snippets.

@qingant
Created March 25, 2020 16:57
Show Gist options
  • Save qingant/bf8e4493178b57f18fafe0a8fe8fe94e to your computer and use it in GitHub Desktop.
Save qingant/bf8e4493178b57f18fafe0a8fe8fe94e to your computer and use it in GitHub Desktop.
import { encode, RedisValueOf, RedisParser, show } from "https://raw.githubusercontent.com/qingant/tiny-redis/master/mod.ts";
import { parse as argParse } from "https://deno.land/std/flags/mod.ts";
const { args } = Deno;
const config = argParse(args);
const opts = {
port: config.p || 6666,
hostname: config.h || "127.0.0.1"
};
const main = async () => {
// connect to redis server
const conn = await Deno.connect(opts);
// create a redis command and encode it to [Uint8Array]
const cmdEncoded = encode(RedisValueOf.array([
"INFO",
"MEMORY"
]));
// send the command to redis server
for (let i in cmdEncoded) {
await conn.write(cmdEncoded[i]);
}
// create a parser and get the result
const p = new RedisParser(conn);
const req = await p.parse();
console.log(show(req));
};
await main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment