This package has been deprecated

Author message:

Deprecated

resolve-readmodel-redis

0.4.0 • Public • Published

resolve-readmodel-redis npm version

This package is a resolve-query adapter for storing a read model in Redis store. The adapter is based on the Redis client.

The store interface is implemented using the resolve-readmodel-redis adapter and provides segregated read and write access:

  • Read access is used to retrieve data from a store (for example, by a graphql resolver). The package provides the hget(key, field) asynchronous method to get the value associated with the field from the hash stored at the key.
  • Projection functions use Write access to update data. The following asynchronous methods are available:
    • hset(key, field, value) - sets the value associated with the field in the hash stored at key;
    • del(key) - deletes the hash stored at the key. Does nothing if the key does not exist.

Usage

import createRedisAdapter from 'resolve-readmodel-redis';
import { createReadModel } from 'resolve-query';
 
const adapter = createRedisAdapter();
 
const testEventStore = {
    subscribeByEventType: (_, handler) => Promise.resolve(
        handler({ type: 'TestEvent', text: 'One' }),
        handler({ type: 'TestEvent', text: 'Two' })
    )
};
 
const executeReadModel = createReadModel(
    eventStore: testEventStore,
    adapter,
    projection: {
        Init: async (store) => {
            await store.hset('Test', 'myField', { changeCount: 0, text: 'Initial' })
        },
        TestEvent: async (store, event) => {
            const value = await store.hget('Test', 'myField');
 
            const newValue = { 
                changeCount: value.changeCount + 1,
                text: event.text
            };
            await store.hset('Test', 'myField', newValue);
        }
    }
)
 
const store = await executeReadModel();
const value = store.hget('Test', 'myField');
console.log(value)

Package Sidebar

Install

npm i resolve-readmodel-redis

Weekly Downloads

2

Version

0.4.0

License

MIT

Last publish

Collaborators

  • resolve-admin
  • reimagined-admin
  • vladihost
  • lykoi18