@travetto/model-redis

4.0.7 • Public • Published

Redis Model Support

Redis backing for the travetto model module.

Install: @travetto/model-redis

npm install @travetto/model-redis

# or

yarn add @travetto/model-redis

This module provides an redis-based implementation for the Data Modeling Support. This source allows the Data Modeling Support module to read, write and query against redis.

Supported features:

  • CRUD
  • Expiry
  • Indexed Out of the box, by installing the module, everything should be wired up by default.If you need to customize any aspect of the source or config, you can override and register it with the Dependency Injection module.

Code: Wiring up a custom Model Source

import { InjectableFactory } from '@travetto/di';
import { RedisModelConfig, RedisModelService } from '@travetto/model-redis';

export class Init {
  @InjectableFactory({
    primary: true
  })
  static getModelSource(conf: RedisModelConfig) {
    return new RedisModelService(conf);
  }
}

where the RedisModelConfig is defined by:

Code: Structure of RedisModelConfig

import type redis from 'redis';

import { Config } from '@travetto/config';
import { Field } from '@travetto/schema';

@Config('model.redis')
export class RedisModelConfig {

  @Field(Object)
  client: redis.RedisClientOptions = {};
  namespace?: string;
  autoCreate?: boolean;

  postConstruct(): void {

  }
}

Additionally, you can see that the class is registered with the @Config annotation, and so these values can be overridden using the standard Configuration resolution paths.

Package Sidebar

Install

npm i @travetto/model-redis

Homepage

travetto.io

Weekly Downloads

20

Version

4.0.7

License

MIT

Unpacked Size

16.6 kB

Total Files

7

Last publish

Collaborators

  • arcsine