@toa.io/extensions.stash
TypeScript icon, indicating that this package has built-in type declarations

0.24.0-alpha.0 • Public • Published

Toa Stash

Shared cache and distributed lock manager on top of ioredis and redlock.

Shared cache

stash aspect exposes ioredis methods.

async function computation (input, context) {
  await context.stash.set('key', 'value')
  await context.stash.get('key')
}

Keys are component-scoped, meaning that the underlying Redis keys are namespace:name:key.

Storing objects

async store (key: string, value: object, ...args: Array<string | number>)

async fetch (key: string): object

...args are the arguments of set starting from third.

Values are encoded using msgpack.

Distributed lock manager

async lock<T>(id: string | string[], routine: async? () => T): T

Executes routine once a lock is successfully acquired. Lock ID is component-scoped.

async function computation (input, context) {
  await context.stash.lock('lock id', () => console.log('Lock acquired'))
}

Manifest

To enable extension for a component, add null definition to its manifest:

stash: ~

Deployment

stash context annotation is a Pointer with ID stash.

stash: # shortcut is available
  .: redis://redis.example.com
  dummies.dummy: redis://dummies.redis.example.com

Neither password authentication nor TLS are implemented. #367

Readme

Keywords

none

Package Sidebar

Install

npm i @toa.io/extensions.stash

Weekly Downloads

408

Version

0.24.0-alpha.0

License

none

Unpacked Size

66.9 kB

Total Files

21

Last publish

Collaborators

  • agurtovoi