https://github.com/taoyuan/kvs-simple
A kvs simple storage adapter that supports input and output
https://github.com/taoyuan/kvs-simple
adapter file io kvs load memory read save write
Last synced: 10 months ago
JSON representation
A kvs simple storage adapter that supports input and output
- Host: GitHub
- URL: https://github.com/taoyuan/kvs-simple
- Owner: taoyuan
- License: mit
- Created: 2020-09-29T13:49:20.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-05-12T12:37:08.000Z (almost 5 years ago)
- Last Synced: 2025-02-13T15:49:53.476Z (12 months ago)
- Topics: adapter, file, io, kvs, load, memory, read, save, write
- Language: TypeScript
- Homepage:
- Size: 392 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# kvs-simple
> A [kvs](https://github.com/taoyuan/kvs) simple storage adapter that supports
> input and output
## Install
```shell
npm i kvs kvs-simple
```
## Usage
### Using default FileIO
```js
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
```js
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