Created
March 25, 2020 16:57
-
-
Save qingant/bf8e4493178b57f18fafe0a8fe8fe94e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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