Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/damirka/redis-type
Redis type wrapper. Promises inside
https://github.com/damirka/redis-type
node-redis nodejs nodejs-redis promise redis
Last synced: 3 months ago
JSON representation
Redis type wrapper. Promises inside
- Host: GitHub
- URL: https://github.com/damirka/redis-type
- Owner: damirka
- Created: 2018-06-29T11:52:57.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-10T20:22:39.000Z (about 2 years ago)
- Last Synced: 2024-10-11T02:09:04.218Z (3 months ago)
- Topics: node-redis, nodejs, nodejs-redis, promise, redis
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/redis-type
- Size: 698 KB
- Stars: 6
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# redis-type - redis type wrapper
[Full API Reference](https://damirka.github.io/redis-type/)
This small library gives you Promises and (!) JS-like wrappers for Redis types.
```
Redis HASH -> JS Map // have you ever thought they are so similar?
Redis LIST -> JS Array // this one is a bit obvious
Redis SET -> JS Set // and this one even more!
```## Install and use
As all the npm packages, this one is installed like this:
```sh
$ npm install --save redis-type
```To use this library, you have to include redis-type in your JS code and initialize it with Redis client.
```JavaScript
// The first one
const redis = require('redis');
const client = redis.createClient();// Initialize library with a client (!)
const types = require('redis-type')(client);// Choose the types you are going to use: Hash, List or Set
const Hash = types.Hash;
const Set = types.Set; // this assignment will rewrite global.Set - be careful
const List = types.List;const users = new Hash('users', true); // second argument is for JSON processing
(async () => {
const allUsers = await users.getAll();
await users.set('sam', { name: 'Sam', age: '19' });
const sam = await users.get('sam');
})();
```