1.0.7 • Published 7 months ago

nncache v1.0.7

Weekly downloads
-
License
ISC
Repository
-
Last release
7 months ago

NNCache

使用 node.js 实现的 key-value 缓存服务器,仿 Redis 的主要功能

包括服务端与客户端,能持久化到文件

主要接口:

  1. set
  2. get
  3. del
  4. sub
  5. unsub
  6. saveToFile
  7. getConnectStatus

server demo

const { createServer } = require("nncache");
createServer({
  port: 90, //监听端口
  autoSaveToFile: true, //是否持久化
  saveToFileInterval: 5000, //自动保存间隙
  debug: true, //输出调试信息
  subEnable: false, //是否开启订阅
  dbFilePath: "./db.json", //数据库文件
});

client demo

const { createClient } = require("nncache");

async function main() {
  let cache = createClient({
    url: "ws://localhost:90",
  });
  cache.set("cbf", 123);
  let d = await cache.get("cbf");
  console.log(d);
  setInterval(function () {
    cache.set("cbf2", new Date().valueOf());
  }, 1000);

  let i = 0;
  cache.sub("cbf2", function (json) {
    // i++;
    // if (i == 20) {
    //     cache.unsub('cbf2');
    //   return console.log("取消订阅");
    // }
    console.log("收到订阅:", json);
    // console.log(json);
  });
}

main();
1.0.7

7 months ago

1.0.6

9 months ago

1.0.5

9 months ago

1.0.4

9 months ago

1.0.3

9 months ago

1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago