Injectable service that provides methods for interacting with a Redis database. This class implements the Instance and Connector interfaces and offers CRUD operations as well as connection management for Redis.

Type Parameters

  • T extends { key: string; value: string }

    The type of data objects handled by the connector, which must have key and value properties.

Implements

Constructors

  • Constructs a new instance of the class with the specified collection name and initializes a connection.

    Type Parameters

    • T extends { key: string; value: string }

    Parameters

    • collectionName: string

      The name of the collection to be used.

    Returns RedisConnector<T>

Properties

client: RedisClientType<
    {
        bf: {
            add: __module;
            ADD: __module;
            card: __module;
            CARD: __module;
            exists: __module;
            EXISTS: __module;
            info: __module;
            INFO: __module;
            insert: __module;
            INSERT: __module;
            loadChunk: __module;
            LOADCHUNK: __module;
            mAdd: __module;
            MADD: __module;
            mExists: __module;
            MEXISTS: __module;
            reserve: __module;
            RESERVE: __module;
            scanDump: __module;
            SCANDUMP: __module;
        };
        cf: {
            add: __module;
            ADD: __module;
            addNX: __module;
            ADDNX: __module;
            count: __module;
            COUNT: __module;
            del: __module;
            DEL: __module;
            exists: __module;
            EXISTS: __module;
            info: __module;
            INFO: __module;
            insert: __module;
            INSERT: __module;
            insertNX: __module;
            INSERTNX: __module;
            loadChunk: __module;
            LOADCHUNK: __module;
            reserve: __module;
            RESERVE: __module;
            scanDump: __module;
            SCANDUMP: __module;
        };
        cms: {
            incrBy: __module;
            INCRBY: __module;
            info: __module;
            INFO: __module;
            initByDim: __module;
            INITBYDIM: __module;
            initByProb: __module;
            INITBYPROB: __module;
            merge: __module;
            MERGE: __module;
            query: __module;
            QUERY: __module;
        };
        ft: {
            _list: __module;
            _LIST: __module;
            aggregate: __module;
            AGGREGATE: __module;
            AGGREGATE_WITHCURSOR: __module;
            aggregateWithCursor: __module;
            aliasAdd: __module;
            ALIASADD: __module;
            aliasDel: __module;
            ALIASDEL: __module;
            aliasUpdate: __module;
            ALIASUPDATE: __module;
            alter: __module;
            ALTER: __module;
            CONFIG_GET: __module;
            CONFIG_SET: __module;
            configGet: __module;
            configSet: __module;
            create: __module;
            CREATE: __module;
            CURSOR_DEL: __module;
            CURSOR_READ: __module;
            cursorDel: __module;
            cursorRead: __module;
            dictAdd: __module;
            DICTADD: __module;
            dictDel: __module;
            DICTDEL: __module;
            dictDump: __module;
            DICTDUMP: __module;
            dropIndex: __module;
            DROPINDEX: __module;
            explain: __module;
            EXPLAIN: __module;
            explainCli: __module;
            EXPLAINCLI: __module;
            info: __module;
            INFO: __module;
            profileAggregate: __module;
            PROFILEAGGREGATE: __module;
            profileSearch: __module;
            PROFILESEARCH: __module;
            search: __module;
            SEARCH: __module;
            SEARCH_NOCONTENT: __module;
            searchNoContent: __module;
            spellCheck: __module;
            SPELLCHECK: __module;
            sugAdd: __module;
            SUGADD: __module;
            sugDel: __module;
            SUGDEL: __module;
            sugGet: __module;
            SUGGET: __module;
            SUGGET_WITHPAYLOADS: __module;
            SUGGET_WITHSCORES: __module;
            SUGGET_WITHSCORES_WITHPAYLOADS: __module;
            sugGetWithPayloads: __module;
            sugGetWithScores: __module;
            sugGetWithScoresWithPayloads: __module;
            sugLen: __module;
            SUGLEN: __module;
            synDump: __module;
            SYNDUMP: __module;
            synUpdate: __module;
            SYNUPDATE: __module;
            tagVals: __module;
            TAGVALS: __module;
        };
        graph: {
            CONFIG_GET: __module;
            CONFIG_SET: __module;
            configGet: __module;
            configSet: __module;
            delete: __module;
            DELETE: __module;
            explain: __module;
            EXPLAIN: __module;
            list: __module;
            LIST: __module;
            profile: __module;
            PROFILE: __module;
            query: __module;
            QUERY: __module;
            RO_QUERY: __module;
            roQuery: __module;
            slowLog: __module;
            SLOWLOG: __module;
        };
        json: {
            arrAppend: __module;
            ARRAPPEND: __module;
            arrIndex: __module;
            ARRINDEX: __module;
            arrInsert: __module;
            ARRINSERT: __module;
            arrLen: __module;
            ARRLEN: __module;
            arrPop: __module;
            ARRPOP: __module;
            arrTrim: __module;
            ARRTRIM: __module;
            DEBUG_MEMORY: __module;
            debugMemory: __module;
            del: __module;
            DEL: __module;
            forget: __module;
            FORGET: __module;
            get: __module;
            GET: __module;
            merge: __module;
            MERGE: __module;
            mGet: __module;
            MGET: __module;
            mSet: __module;
            MSET: __module;
            numIncrBy: __module;
            NUMINCRBY: __module;
            numMultBy: __module;
            NUMMULTBY: __module;
            objKeys: __module;
            OBJKEYS: __module;
            objLen: __module;
            OBJLEN: __module;
            resp: __module;
            RESP: __module;
            set: __module;
            SET: __module;
            strAppend: __module;
            STRAPPEND: __module;
            strLen: __module;
            STRLEN: __module;
            type: __module;
            TYPE: __module;
        };
        tDigest: {
            add: __module;
            ADD: __module;
            byRank: __module;
            BYRANK: __module;
            byRevRank: __module;
            BYREVRANK: __module;
            cdf: __module;
            CDF: __module;
            create: __module;
            CREATE: __module;
            info: __module;
            INFO: __module;
            max: __module;
            MAX: __module;
            merge: __module;
            MERGE: __module;
            min: __module;
            MIN: __module;
            quantile: __module;
            QUANTILE: __module;
            rank: __module;
            RANK: __module;
            reset: __module;
            RESET: __module;
            revRank: __module;
            REVRANK: __module;
            TRIMMED_MEAN: __module;
            trimmedMean: __module;
        };
        topK: {
            add: __module;
            ADD: __module;
            count: __module;
            COUNT: __module;
            incrBy: __module;
            INCRBY: __module;
            info: __module;
            INFO: __module;
            list: __module;
            LIST: __module;
            LIST_WITHCOUNT: __module;
            listWithCount: __module;
            query: __module;
            QUERY: __module;
            reserve: __module;
            RESERVE: __module;
        };
        ts: {
            add: __module;
            ADD: __module;
            alter: __module;
            ALTER: __module;
            create: __module;
            CREATE: __module;
            createRule: __module;
            CREATERULE: __module;
            decrBy: __module;
            DECRBY: __module;
            del: __module;
            DEL: __module;
            deleteRule: __module;
            DELETERULE: __module;
            get: __module;
            GET: __module;
            incrBy: __module;
            INCRBY: __module;
            info: __module;
            INFO: __module;
            INFO_DEBUG: __module;
            infoDebug: __module;
            mAdd: __module;
            MADD: __module;
            mGet: __module;
            MGET: __module;
            MGET_WITHLABELS: __module;
            mGetWithLabels: __module;
            mRange: __module;
            MRANGE: __module;
            MRANGE_WITHLABELS: __module;
            mRangeWithLabels: __module;
            mRevRange: __module;
            MREVRANGE: __module;
            MREVRANGE_WITHLABELS: __module;
            mRevRangeWithLabels: __module;
            queryIndex: __module;
            QUERYINDEX: __module;
            range: __module;
            RANGE: __module;
            revRange: __module;
            REVRANGE: __module;
        };
    } & RedisModules,
    RedisFunctions,
    RedisScripts,
>

Represents a client instance for interacting with a Redis database.

This client variable is an instance of the RedisClientType class, which provides the ability to execute operations on the Redis server. It supports default Redis commands, custom modules, user-defined functions, and scripts.

Type Parameters:

  • RedisDefaultModules & RedisModules: Includes the default Redis modules and any additional modules provided.
  • RedisFunctions: Represents user-defined functions for extending Redis functionality.
  • RedisScripts: Represents user-defined Lua scripts for execution in Redis.

The client can be used for performing various Redis operations like getting, setting, or modifying data. It also allows the execution of custom functions and scripts, providing a flexible and powerful interface to work with Redis.

Methods

  • Establishes a connection to the Redis database. If a connection already exists and is open, it resolves the existing client instance. Otherwise, it initializes and connects a new Redis client.

    Parameters

    • Optionalfirst: boolean = false

      Optional flag indicating whether it is the first connection attempt.

    Returns Promise<
        RedisClientType<
            {
                bf: {
                    add: __module;
                    ADD: __module;
                    card: __module;
                    CARD: __module;
                    exists: __module;
                    EXISTS: __module;
                    info: __module;
                    INFO: __module;
                    insert: __module;
                    INSERT: __module;
                    loadChunk: __module;
                    LOADCHUNK: __module;
                    mAdd: __module;
                    MADD: __module;
                    mExists: __module;
                    MEXISTS: __module;
                    reserve: __module;
                    RESERVE: __module;
                    scanDump: __module;
                    SCANDUMP: __module;
                };
                cf: {
                    add: __module;
                    ADD: __module;
                    addNX: __module;
                    ADDNX: __module;
                    count: __module;
                    COUNT: __module;
                    del: __module;
                    DEL: __module;
                    exists: __module;
                    EXISTS: __module;
                    info: __module;
                    INFO: __module;
                    insert: __module;
                    INSERT: __module;
                    insertNX: __module;
                    INSERTNX: __module;
                    loadChunk: __module;
                    LOADCHUNK: __module;
                    reserve: __module;
                    RESERVE: __module;
                    scanDump: __module;
                    SCANDUMP: __module;
                };
                cms: {
                    incrBy: __module;
                    INCRBY: __module;
                    info: __module;
                    INFO: __module;
                    initByDim: __module;
                    INITBYDIM: __module;
                    initByProb: __module;
                    INITBYPROB: __module;
                    merge: __module;
                    MERGE: __module;
                    query: __module;
                    QUERY: __module;
                };
                ft: {
                    _list: __module;
                    _LIST: __module;
                    aggregate: __module;
                    AGGREGATE: __module;
                    AGGREGATE_WITHCURSOR: __module;
                    aggregateWithCursor: __module;
                    aliasAdd: __module;
                    ALIASADD: __module;
                    aliasDel: __module;
                    ALIASDEL: __module;
                    aliasUpdate: __module;
                    ALIASUPDATE: __module;
                    alter: __module;
                    ALTER: __module;
                    CONFIG_GET: __module;
                    CONFIG_SET: __module;
                    configGet: __module;
                    configSet: __module;
                    create: __module;
                    CREATE: __module;
                    CURSOR_DEL: __module;
                    CURSOR_READ: __module;
                    cursorDel: __module;
                    cursorRead: __module;
                    dictAdd: __module;
                    DICTADD: __module;
                    dictDel: __module;
                    DICTDEL: __module;
                    dictDump: __module;
                    DICTDUMP: __module;
                    dropIndex: __module;
                    DROPINDEX: __module;
                    explain: __module;
                    EXPLAIN: __module;
                    explainCli: __module;
                    EXPLAINCLI: __module;
                    info: __module;
                    INFO: __module;
                    profileAggregate: __module;
                    PROFILEAGGREGATE: __module;
                    profileSearch: __module;
                    PROFILESEARCH: __module;
                    search: __module;
                    SEARCH: __module;
                    SEARCH_NOCONTENT: __module;
                    searchNoContent: __module;
                    spellCheck: __module;
                    SPELLCHECK: __module;
                    sugAdd: __module;
                    SUGADD: __module;
                    sugDel: __module;
                    SUGDEL: __module;
                    sugGet: __module;
                    SUGGET: __module;
                    SUGGET_WITHPAYLOADS: __module;
                    SUGGET_WITHSCORES: __module;
                    SUGGET_WITHSCORES_WITHPAYLOADS: __module;
                    sugGetWithPayloads: __module;
                    sugGetWithScores: __module;
                    sugGetWithScoresWithPayloads: __module;
                    sugLen: __module;
                    SUGLEN: __module;
                    synDump: __module;
                    SYNDUMP: __module;
                    synUpdate: __module;
                    SYNUPDATE: __module;
                    tagVals: __module;
                    TAGVALS: __module;
                };
                graph: {
                    CONFIG_GET: __module;
                    CONFIG_SET: __module;
                    configGet: __module;
                    configSet: __module;
                    delete: __module;
                    DELETE: __module;
                    explain: __module;
                    EXPLAIN: __module;
                    list: __module;
                    LIST: __module;
                    profile: __module;
                    PROFILE: __module;
                    query: __module;
                    QUERY: __module;
                    RO_QUERY: __module;
                    roQuery: __module;
                    slowLog: __module;
                    SLOWLOG: __module;
                };
                json: {
                    arrAppend: __module;
                    ARRAPPEND: __module;
                    arrIndex: __module;
                    ARRINDEX: __module;
                    arrInsert: __module;
                    ARRINSERT: __module;
                    arrLen: __module;
                    ARRLEN: __module;
                    arrPop: __module;
                    ARRPOP: __module;
                    arrTrim: __module;
                    ARRTRIM: __module;
                    DEBUG_MEMORY: __module;
                    debugMemory: __module;
                    del: __module;
                    DEL: __module;
                    forget: __module;
                    FORGET: __module;
                    get: __module;
                    GET: __module;
                    merge: __module;
                    MERGE: __module;
                    mGet: __module;
                    MGET: __module;
                    mSet: __module;
                    MSET: __module;
                    numIncrBy: __module;
                    NUMINCRBY: __module;
                    numMultBy: __module;
                    NUMMULTBY: __module;
                    objKeys: __module;
                    OBJKEYS: __module;
                    objLen: __module;
                    OBJLEN: __module;
                    resp: __module;
                    RESP: __module;
                    set: __module;
                    SET: __module;
                    strAppend: __module;
                    STRAPPEND: __module;
                    strLen: __module;
                    STRLEN: __module;
                    type: __module;
                    TYPE: __module;
                };
                tDigest: {
                    add: __module;
                    ADD: __module;
                    byRank: __module;
                    BYRANK: __module;
                    byRevRank: __module;
                    BYREVRANK: __module;
                    cdf: __module;
                    CDF: __module;
                    create: __module;
                    CREATE: __module;
                    info: __module;
                    INFO: __module;
                    max: __module;
                    MAX: __module;
                    merge: __module;
                    MERGE: __module;
                    min: __module;
                    MIN: __module;
                    quantile: __module;
                    QUANTILE: __module;
                    rank: __module;
                    RANK: __module;
                    reset: __module;
                    RESET: __module;
                    revRank: __module;
                    REVRANK: __module;
                    TRIMMED_MEAN: __module;
                    trimmedMean: __module;
                };
                topK: {
                    add: __module;
                    ADD: __module;
                    count: __module;
                    COUNT: __module;
                    incrBy: __module;
                    INCRBY: __module;
                    info: __module;
                    INFO: __module;
                    list: __module;
                    LIST: __module;
                    LIST_WITHCOUNT: __module;
                    listWithCount: __module;
                    query: __module;
                    QUERY: __module;
                    reserve: __module;
                    RESERVE: __module;
                };
                ts: {
                    add: __module;
                    ADD: __module;
                    alter: __module;
                    ALTER: __module;
                    create: __module;
                    CREATE: __module;
                    createRule: __module;
                    CREATERULE: __module;
                    decrBy: __module;
                    DECRBY: __module;
                    del: __module;
                    DEL: __module;
                    deleteRule: __module;
                    DELETERULE: __module;
                    get: __module;
                    GET: __module;
                    incrBy: __module;
                    INCRBY: __module;
                    info: __module;
                    INFO: __module;
                    INFO_DEBUG: __module;
                    infoDebug: __module;
                    mAdd: __module;
                    MADD: __module;
                    mGet: __module;
                    MGET: __module;
                    MGET_WITHLABELS: __module;
                    mGetWithLabels: __module;
                    mRange: __module;
                    MRANGE: __module;
                    MRANGE_WITHLABELS: __module;
                    mRangeWithLabels: __module;
                    mRevRange: __module;
                    MREVRANGE: __module;
                    MREVRANGE_WITHLABELS: __module;
                    mRevRangeWithLabels: __module;
                    queryIndex: __module;
                    QUERYINDEX: __module;
                    range: __module;
                    RANGE: __module;
                    revRange: __module;
                    REVRANGE: __module;
                };
            } & RedisModules,
            RedisFunctions,
            RedisScripts,
        >,
    >

    A promise that resolves with the active Redis client instance.

  • Creates a new entry in the specified collection in the database.

    Parameters

    • collectionName: string

      The name of the collection where the data should be inserted.

    • data: T

      The data object to be stored, containing a key and value.

    Returns Promise<T>

    A promise that resolves to the inserted data object if successful, or null if an error occurs.

  • Deletes a specific key from the specified collection in the database.

    Parameters

    • collectionName: string

      The name of the collection from which the key needs to be deleted.

    • key: string

      The key to be deleted from the collection.

    Returns Promise<boolean>

    A promise that resolves to true if the key was deleted successfully, or false if an error occurred.

  • Disconnects the client if it is currently connected. This method ensures that the client is safely disconnected and sets the client instance to null.

    Returns void

    Does not return any value.

  • Retrieves all matching documents from the specified collection based on the provided query and bindings.

    Parameters

    • collectionName: string

      The name of the collection to query.

    • query: string

      The query string used to filter the results.

    • bindings: any[]

      Optional parameters to bind within the query for dynamic filtering.

    Returns Promise<T[]>

    A promise that resolves to an array of objects of type T matching the query criteria.

  • Fetches a single record from the specified collection that matches the given query and binding values.

    Parameters

    • collectionName: string

      The name of the collection to search.

    • query: string

      The query string used to find the record.

    • bindings: any[]

      Optional parameters to be bound to the query placeholders.

    Returns Promise<T>

    A promise that resolves with the found record or rejects if no record matches.

  • Retrieves all documents from the specified collection.

    Parameters

    • collectionName: string

      The name of the collection to retrieve documents from.

    Returns Promise<T[]>

    A promise that resolves to an array of documents of type T.

  • Retrieves a value from the Redis database by its key.

    Parameters

    • collectionName: string

      The name of the collection or namespace in the Redis database.

    • key: string

      The key of the item to retrieve from the specified collection.

    Returns Promise<T>

    A promise that resolves to the retrieved value and its key, or null if an error occurs during retrieval.

  • Performs necessary cleanup when the component or object is destroyed. This includes disconnecting any active connections or listeners to prevent memory leaks and ensure proper resource management.

    Returns void

    Does not return a value.

  • Updates a specific record in the given collection with the provided data.

    Parameters

    • collectionName: string

      The name of the collection where the update will be performed.

    • data: T

      The data object that will be used to update the record in the collection.

    Returns Promise<T>

    A promise that resolves to the updated record.