Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

redisk

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redisk

TypeScript ORM for Redis.

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
127
increased by18.69%
Maintainers
1
Weekly downloads
 
Created
Source

Redisk

npm version

Redisk is a TypeScript ORM library for Redis.

Features:

  • Store entities.
  • Single relation support.
  • Unique keys support.
  • Retrieve entities by his primary keys or his unique keys.
  • Indexes support.
  • List entities with common filters, like limit, count and sort by.
  • Find entities with multiple conditions.
  • Search (Similar to LIKE in SQL)
  • And much more.

Getting started

npm install redisk --save

Examples with a User model

Model definition

@Entity('user', { canBeListed: true })
export class User {

  @Primary()
  @Property()
  public readonly id: string;

  @Property({sortable: false, searchable: true})
  public readonly name: string;

  @Unique()
  @Property()
  public readonly email: string;

  @Index()
  @Property()
  public readonly color: string;

  @Property({sortable: true, searchable: false})
  public readonly created: Date;

  constructor(
      id: string,
      name: string,
      email: string,
      color: string,
      created: Date,
    ) {
      this.id = id;
      this.name = name;
      this.email = email;
      this.color = color;
      this.created = created;
  }
}

Init Redisk

import * as redis from 'redis';

const redisk = new Redisk(new Metadata(), redis.createClient({url: 'redis://127.0.0.1:6379/0'}));

Store one user

await redisk.commit<User>(new User(id, name, email, color, created));

Get one user by his primary key

await redisk.getOne<User>(User, id);

Get one user by his email unique key

await redisk.getOne<User>(User, 'john@doe.com', 'email');

Count all users

await redisk.count<User>(User);

List all users

await redisk.list<User>(User); // Returns an array of entities

const limit = 10;
const offset = 0;
await redis.list<User>(User, limit, offset); // Returns 10 user entities

await redisk.list<User>(User, undefined, undefined, {
    field: 'created',
    strategy: 'DESC',
}); // Returns an array of entities sorted by his creation date in descending order

Find all users by one index

const conditions = [
    {
        key: 'color',
        value: 'red',
    },
];
await redisk.find<User>(User, conditions, limit, offset); // Returns an array of entites that match the conditions

Search users by his name

const condition = {
    key: 'name',
    value: 'John',
};
const maxNumberOfResults = 10;
await redisk.search<User>(User, condition, maxNumberOfResults);

Delete one user

await redisk.delete<User>(User, id);

Keywords

FAQs

Package last updated on 25 Jan 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc