GithubHelp home page GithubHelp logo

taoyuan / kvs-simple Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 0.0 401 KB

A kvs simple storage adapter that supports input and output

License: MIT License

JavaScript 2.56% TypeScript 97.44%
kvs file io read write load save memory adapter

kvs-simple's Introduction

kvs-simple

A kvs simple storage adapter that supports input and output

Install

npm i kvs kvs-simple

Usage

Using default FileIO

import {Store} from 'kvs';
// import Simple from 'kvs-simple';

(async () => {
  const store = Store.create('simple' /* Simple */, {
    file: 'data.json',
    expiresCheckInterval: 24 * 3600 * 1000, // ms, check and remove expired data in each ms
    writeDelay: 100, // ms, batch write to disk in a specific duration, enhance write performance.
    codec: {
      encode: JSON.stringify, // serialize function
      decode: JSON.parse, // deserialize function
    },
  });

  const bucket = await store.bucket('namespace');

  bucket.set('key', 'value');
  const value = await bucket.get('key');
})();

Using custom IO

import fs from 'fs';
import {Store} from 'kvs';
// import Simple from 'kvs-simple';

(async () => {
  const store = Store.create('simple' /* Simple */, {
    expiresCheckInterval: 24 * 3600 * 1000, // ms, check and remove expired data in each ms
    writeDelay: 100, // ms, batch write to disk in a specific duration, enhance write performance.
    io: {
      read: async () => fs.readFileSync('data.json', 'utf8'),
      write: async data => fs.outputFile('data.json', data, 'utf8'),
    },
  });

  const bucket = await store.bucket('namespace');

  bucket.set('key', 'value');
  const value = await bucket.get('key');
})();

License

MIT

kvs-simple's People

Contributors

taoyuan avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.