Deno: 读取 Redis 数据
读取了在以下程序中创建的数据。
Deno:创建 Redis 数据。
程序
// ---------------------------------------------------------------
// redis_read.ts
//
// Feb/27/2023
//
// ---------------------------------------------------------------
import { connect } from "https://deno.land/x/redis/mod.ts"
// ---------------------------------------------------------------
function display_line_proc (key:string,json_str:string)
{
const data = JSON.parse (json_str)
var out_str: string = key + "\t"
out_str += data.name + "\t"
out_str += data.population + "\t"
out_str += data.date_mod
console.log (out_str)
}
// ---------------------------------------------------------------
console.error ("*** 開始 ***")
const client = await connect({ hostname: "127.0.0.1", port: 6379 })
const reply = await client.sendCommand("keys", "*")
const keys:string[] = reply.value()
for (var it in keys)
{
const key:string = keys[it].toString()
const reply = await client.get(key)
if (reply != null)
{
display_line_proc (key,reply)
}
}
console.error ("*** 終了 ***")
// ---------------------------------------------------------------
执行命令
deno run --allow-net redis_read.ts
确认过的版本
$ deno --version
deno 1.31.0 (release, x86_64-unknown-linux-gnu)
v8 11.0.226.13
typescript 4.9.4