redis-backed-object
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

redis-backed-object

a simple library which allows to create an object which is backed by redis.

Potential usecases:

  • caching state between multiple runs of the same process
  • caching state between lambda function runs or even between

Usage

import { RedisBackedObject } from 'redis-backed-object'

const state = new RedisBackedObject(
  {
    redis: redisClient,
    key: 'rbo:test',
    saveInterval: 2
  },
  {
    a: 1
  }
)
const proxy = state.getProxy()
proxy.a = 2

await sleep(2)
const data = await redisClient.get('rbo:test')
expect(data).toBe('{"a":2}')

state.reset()
expect(proxy.a).toBe(1)
await sleep(2)
const dataAfterReset = await redisClient.get('rbo:test')
expect(dataAfterReset).toBe('{"a":1}')

check out all the features in RedisBackedObject.spec.ts

Readme

Keywords

none

Package Sidebar

Install

npm i redis-backed-object

Weekly Downloads

5

Version

0.2.0

License

MIT

Unpacked Size

20.2 kB

Total Files

8

Last publish

Collaborators

  • capaj