1.0.2 • Published 5 years ago

sein-redis v1.0.2

Weekly downloads
6
License
MIT
Repository
github
Last release
5 years ago

sein-redis

Secondary indexing with Redis

Quick Start

Install

$ npm install sein-redis

Usage Example

const Redis = require('ioredis');
const seinRedis = require('sein-redis');

const redis = new Redis();

seinRedis.setClient(redis);
seinRedis.setPrefix('example');
  
class UserModel extends seinRedis.Model {
  constructor() {
    super();
    this.modelName = 'User';

    this.setDefinitions([
      {
        name: 'id',
        primaryKey: true,
      },
      {
        name: 'email',
        uniqueIndex: true,
      },
      {
        name: 'typeId',
        index: true,
      },
    ]);
  }

  getByEmail(email) {
    return this.getByUniqueIndex({ email }, true);
  }

  getByType(typeId) {
    return this.getByIndex({ typeId }, true);
  }
}

const isSet = await userModel.set({
                      id: 'd982398j2398u',
                      name: 'Test User',
                      email: 'testuser@tests.com',
                      typeId: 1,
                    });

let user = await userModel.get('d982398j2398u');

user = await userModel.getByEmail('testuser@tests.com');

const users = await userModel.getByType(1);

Licence

MIT

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago