The Search module provides methods for reading and writing data to a workflow record. The instance methods exposed by this class are available for use from within a running workflow. The following example uses search to set a name field and increment a counter field. The workflow returns the incremented value.

//searchWorkflow.ts
import { MeshFlow } from '@hotmeshio/hotmesh';

export async function searchExample(name: string): Promise<{counter: number}> {
const search = await MeshFlow.workflow.search();
await search.set('name', name);
const newCounterValue = await search.incr('counter', 1);
return { counter: newCounterValue };
}

Methods

  • Deletes the fields provided as args. Returns the count of fields that were deleted.

    Parameters

    • Rest...args: string[]

    Returns Promise<number | void>

    const search = new Search();
    const count = await search.del('field1', 'field2', 'field3');
  • Returns the value of the field in the HASH stored at key.

    Parameters

    • key: string

    Returns Promise<string>

    const search = new Search();
    const value = await search.get('field1');
  • Increments the value of a float field by the given amount. Returns the new value of the field after the increment. Pass a negative number to decrement the value.

    Parameters

    • key: string

      the key to increment

    • val: number

      the value to increment by

    Returns Promise<number>

    • the new value
    const search = new Search();
    const count = await search.incr('field1', 1.5);
  • Returns the values of all specified fields in the HASH stored at key.

    Parameters

    • Rest...args: string[]

    Returns Promise<string[]>

  • Multiplies the value of a field by the given amount. Returns the new value of the field after the multiplication. NOTE: this is exponential multiplication.

    Parameters

    • key: string

      the key to multiply

    • val: number

      the value to multiply by

    Returns Promise<number>

    • the new product of the multiplication
    const search = new Search();
    const product = await search.mult('field1', 1.5);
  • Sets the fields listed in args. Returns the count of new fields that were set (does not count fields that were updated)

    Parameters

    • Rest...args: string[]

    Returns Promise<number>

    const search = new Search();
    const count = await search.set('field1', 'value1', 'field2', 'value2');
  • For those deployments with a redis stack backend (with the FT module), this method will list all search indexes.

    Parameters

    • hotMeshClient: HotMesh

      the hotmesh client

    Returns Promise<string[]>

    • the list of search indexes
    const searchIndexes = await Search.listSearchIndexes(hotMeshClient);