Deno.js Redis Library to Implement Client Side Caching in App Using TypeScript Full Project For Beginners

 

 

deno-redis

Build Status https://img.shields.io/github/tag/denodrivers/redis.svg license deno doc Discord

An experimental implementation of redis client for deno

Usage

needs --allow-net privilege

 

 

Stateless Commands

 

 

import { connect } from "https://deno.land/x/redis/mod.ts";
const redis = await connect({
  hostname: "127.0.0.1",
  port: 6379,
});
const ok = await redis.set("hoge", "fuga");
const fuga = await redis.get("hoge");

 

Streams

 

 

await redis.xadd(
  "somestream",
  "*", // let redis assign message ID
  { yes: "please", no: "thankyou" },
  { elements: 10 },
);

const [stream] = await redis.xread(
  [{ key: "somestream", xid: 0 }], // read from beginning
  { block: 5000 },
);

const msgFV = stream.messages[0].fieldValues;
const plz = msgFV["yes"];
const thx = msgFV["no"];

 

See also  Deno.js Tutorial to Take Input From User on Command Line and Adds Two Numbers in TypeScript Full Project For Beginners

 

Client side caching

 

 

const mainClient = await connect({ hostname: "127.0.0.1" });
const cacheClient = await connect({ hostname: "127.0.0.1" });

const cacheClientID = await cacheClient.clientID();
await mainClient.clientTracking({
  mode: "ON",
  redirect: cacheClientID,
});
const sub = await cacheClient.subscribe<string[]>("__redis__:invalidate");

(async () => {
  for await (const { channel, message } of sub.receive()) {
    // Handle invalidation messages...
  }
})();

Leave a Reply