https://github.com/shanev/tempdb
Redis-backed ephemeral key-value store for Node
https://github.com/shanev/tempdb
async-await es6 javascript key-value node nodejs redis
Last synced: 15 days ago
JSON representation
Redis-backed ephemeral key-value store for Node
- Host: GitHub
- URL: https://github.com/shanev/tempdb
- Owner: shanev
- License: mit
- Created: 2017-03-09T22:56:37.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-11-06T06:57:36.000Z (over 7 years ago)
- Last Synced: 2024-04-23T23:15:28.022Z (12 months ago)
- Topics: async-await, es6, javascript, key-value, node, nodejs, redis
- Language: JavaScript
- Homepage:
- Size: 52.7 KB
- Stars: 29
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# TempDB
[](https://badge.fury.io/js/tempdb)
[](https://travis-ci.org/shanev/tempdb)
[](https://codecov.io/gh/shanev/tempdb)
[](https://codebeat.co/projects/github-com-shanev-tempdb-master)
[](https://david-dm.org/shanev/tempdb)TempDB is Redis-backed temporary key-value store for Node. It's useful for storing temporary data such as login codes, authentication tokens, and temporary passwords.
## Installation
```sh
npm install tempdb
```### Run Redis server
Check out [Redis quickstart](https://redis.io/topics/quickstart) to install for your platform, or use one of the many cloud providers. Depending on your Redis provider, you may need to enable keyspace events for ephemeral keys to work.
A convenience script is provided for macOS default Homebrew Redis installs:
```sh
npm run redis
```## Usage
Require TempDB:
```js
const TempDB = require('tempdb');
```Initialize TempDB, connecting to a [Redis client](https://github.com/NodeRedis/node_redis):
```js
const tempDB = new TempDB(redisClient);
```Add a key/value pair. Value is anything that can be serialized to JSON. Expires (in seconds) is optional.
```js
tempDB.add('key', value, expires);
```Find by key:
```js
const value = await tempDB.find('key');
```Find and delete by key:
```js
const value = await tempDB.findAndDelete('key');
```## Tests
```sh
npm install
npm test
```## Ports to other languages
* Go: [https://github.com/rafaeljesus/tempdb](https://github.com/rafaeljesus/tempdb)