@storehouse/redis - v0.1.0
    Preparing search index...

    Class Repository<TSchema>

    Represents a repository for JSON Documents stored in Redis. Provides methods to save, fetch, and remove JSON Documents, as well as create the index.

    Type Parameters

    • TSchema extends StandardSchemaV1
    Index
    • Creates the index for the JSON Documents in Redis.

      Returns Promise<"OK">

      a promise that resolves when the index has been created successfully

    • Drops the index for the JSON Documents in Redis.

      Parameters

      • Optionaloptions: FtDropIndexOptions

        optional FT.DROPINDEX command options

      Returns Promise<number>

      the number of indexes that were dropped

    • Sets the expiration time for a given JSON Document in Redis.

      Parameters

      • id: RedisArgument

        the id of the JSON Document to set expiration on

      • seconds: number

        Number of seconds until key expiration

      • Optionalmode: "NX" | "XX" | "GT" | "LT"

        Expiration mode: NX (only if key has no expiry), XX (only if key has existing expiry), GT (only if new expiry is greater than current), LT (only if new expiry is less than current)

      Returns Promise<number>

    • Fetches a JSON Document, or part of it, from Redis by its id.

      The shape of the result depends on options.path:

      • no path or .: the whole JSON Document, validated against the schema.
      • $: the whole JSON Document wrapped in an array (RedisJSON 2.x JSONPath reply). The document is validated against the schema.
      • any other JSONPath (starting with $): an array of the matches, exactly as returned by Redis (empty if nothing matches). It is not validated.
      • any other path (legacy syntax, such as .artist or artist): the value at that path, as returned by Redis. It is not validated.

      Type Parameters

      • P extends RedisVariadicArgument | undefined = undefined

      Parameters

      • id: RedisArgument

        the id of the JSON Document to fetch

      • Optionaloptions: JsonGetOptions & { path?: P }

        optional JSON.GET command options

      Returns Promise<GetPathType<JsonDocument<TSchema>, P> | null>

      the result described above, or null if the JSON Document does not exist

      ValidationError if the JSON Document is validated and does not conform to the schema

    • Computes the full Redis key for a JSON Document based on its id.

      Parameters

      • id: RedisArgument

        the id of the JSON Document

      Returns RedisArgument

      the full Redis key for the JSON Document

    • Returns Promise<
          | {
              attributes: { [key: string]: string }[];
              bytes_per_record_avg: number;
              cleaning: number;
              cursor_stats: {
                  global_idle: number;
                  global_total: number;
                  index_capacity: number;
                  index_total: number;
              };
              dialect_stats?: { [key: string]: number };
              doc_table_size_mb: number;
              gc_stats: {
                  average_cycle_time_ms: number;
                  bytes_collected: number;
                  gc_blocks_denied: number;
                  gc_numeric_trees_missed: number;
                  last_run_time_ms: number;
                  total_cycles: number;
                  total_ms_run: number;
              };
              geoshapes_sz_mb: number;
              hash_indexing_failures: number;
              "Index Errors"?: {
                  "background indexing status": string;
                  "indexing failures": number;
                  "last indexing error": string;
                  "last indexing error key": string;
              };
              index_definition: { [key: string]: string };
              index_name: string;
              index_options: string[];
              indexing: number;
              inverted_sz_mb: number;
              key_table_size_mb: number;
              max_doc_id: number;
              num_docs: number;
              num_records: number;
              num_terms: number;
              number_of_uses: number;
              offset_bits_per_record_avg: number;
              offset_vectors_sz_mb: number;
              offsets_per_term_avg: number;
              percent_indexed: number;
              records_per_doc_avg: number;
              sortable_values_size_mb: number;
              stopwords_list?: string[] | null[];
              tag_overhead_sz_mb: number;
              text_overhead_sz_mb: number;
              total_index_memory_sz_mb: number;
              total_indexing_time: number;
              total_inverted_index_blocks: number;
              vector_index_sz_mb: number;
          }
          | null,
      >

      information about the index if it exists, or null if the index does not exist

    • Removes a JSON Document from Redis.

      Parameters

      • id: RedisArgument

        the id of the JSON Document to remove

      • Optionaloptions: JsonDelOptions

        optional JSON.DEL command options

      Returns Promise<number>

      the number of keys that were removed

    • Saves a JSON Document to Redis.

      Parameters

      • id: RedisArgument

        the id of the JSON Document to save

      • value: JsonDocument<TSchema>

        the JSON Document to save

      • Optionaloptions: JsonSetOptions

        optional JSON.SET command options

      Returns Promise<"OK" | null>

      the result of the Redis JSON.SET command

      ValidationError if the JSON Document does not conform to the schema

    • Searches for JSON Documents in Redis using the specified query and options.

      Parameters

      • query: RedisArgument

        the search query to execute

      • Optionaloptions: FtSearchOptions

        optional search options

      Returns Promise<
          {
              documents: {
                  id: string;
                  payload?: string
                  | Buffer<ArrayBufferLike>;
                  score?: number;
                  scoreExplain?:
                      | string
                      | Buffer<ArrayBufferLike>
                      | (
                          | string
                          | Buffer<ArrayBufferLike>
                          | (
                              | string
                              | Buffer<ArrayBufferLike>
                              | (
                                  (string | Buffer<ArrayBufferLike> | (string | Buffer<ArrayBufferLike> | (string | Buffer<ArrayBufferLike> | (string | ... 1 more ... | (string | ... 1 more ... | (string | ... 1 more ... | (string | ... 1 more ... | (string | ... 1 more ... | (string | ... 1 more ... | (string | ... 1 more ... | (string | ... 1 more...
                              )
                          )[]
                      )[];
                  sortKey?: string
                  | Buffer<ArrayBufferLike>;
                  value: {
                      [key: string]:
                          | string
                          | number
                          | ({ [x: string]: string | number | ... | ...[] | null; })
                          | ({ [x: string]: string | number | ... | ...[] | null; })[]
                          | null;
                  };
              }[];
              total: number;
              warnings: string[];
          },
      >

      the result of the Redis FT.SEARCH command

    • Sets the whole JSON Document (root path $), like Repository.save. The value is validated against the schema before being written.

      Parameters

      • id: RedisArgument

        the id of the JSON Document to set

      • value: JsonDocument<TSchema>

        the JSON Document to set

      • Optionaloptions: JsonSetOptions

        optional JSON.SET command options

      Returns Promise<"OK" | null>

      the result of the Redis JSON.SET command

      ValidationError if the JSON Document does not conform to the schema

    • Sets the value at a given path of a JSON Document. Validation against the schema is only performed when path is the root ($); values written to any other path are sent to Redis as is.

      Parameters

      • id: RedisArgument

        the id of the JSON Document to modify

      • path: RedisArgument

        the JSONPath where to set the value

      • value: JsonDocument<TSchema>

        the value to set at path

      • Optionaloptions: JsonSetOptions

        optional JSON.SET command options

      Returns Promise<"OK" | null>

      the result of the Redis JSON.SET command

      ValidationError if path is the root and the JSON Document does not conform to the schema