@imqueue/rpc
Version:
RPC-like client-service implementation over messaging queue
114 lines (113 loc) • 3.72 kB
TypeScript
/*!
* RedisCache adapter implementation
*
* I'm Queue Software Project
* Copyright (C) 2025 imqueue.com <support@imqueue.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* If you want to use this code in a closed source (commercial) project, you can
* purchase a proprietary commercial license. Please contact us at
* <support@imqueue.com> to get commercial licensing options.
*/
import { ICache } from '.';
import { ILogger, IRedisClient, IMQOptions } from '@imqueue/core';
export interface IRedisCacheOptions extends Partial<IMQOptions> {
conn?: IRedisClient;
}
export declare const DEFAULT_REDIS_CACHE_OPTIONS: {
prefix: string;
cleanup: boolean;
cleanupFilter: string;
vendor?: string;
logger?: ILogger;
watcherCheckDelay?: number;
useGzip?: boolean;
safeDelivery?: boolean;
safeDeliveryTtl?: number;
cluster?: import("@imqueue/core").IMessageQueueConnection[];
clusterManagers?: import("@imqueue/core/src/ClusterManager").ClusterManager[];
id?: string | undefined;
host?: string | undefined;
port?: number | undefined;
username?: string | undefined;
password?: string | undefined;
};
export declare const REDIS_CLIENT_INIT_ERROR = "Redis client is not initialized!";
/**
* Class RedisCache. Implements cache engine over redis.
*/
export declare class RedisCache implements ICache {
private static redis?;
private logger;
options: IRedisCacheOptions;
name: string;
ready: boolean;
/**
* Initializes cache instance
*
* @param {IRedisCacheOptions} [options]
* @returns {Promise<RedisCache>}
*/
init(options?: IRedisCacheOptions): Promise<RedisCache>;
/**
* Returns fully qualified key name for a given generic key
*
* @access private
* @param {string} key
* @returns {string}
*/
private key;
/**
* Returns value stored in cache by a given key
*
* @param {string} key
* @returns {Promise<any>}
*/
get(key: string): Promise<any>;
/**
* Stores in cache given value under given key. If TTL is specified,
* cached value will expire in a given number of milliseconds. If NX
* argument set to true will create key:value in cache only if it does
* not exist yet. Given value could be any JSON-compatible object and
* will be serialized automatically.
*
* @param {string} key
* @param {any} value
* @param {number} ttl
* @param {boolean} nx
* @returns {Promise<boolean>}
*/
set(key: string, value: any, ttl?: number, nx?: boolean): Promise<boolean>;
/**
* Removes stored in cache value under given key
*
* @param {string} key
* @returns {Promise<boolean>}
*/
del(key: string): Promise<boolean>;
/**
* Purges all keys from cache by a given wildcard mask
*
* @param {string} keyMask
* @return {boolean}
*/
purge(keyMask: string): Promise<boolean>;
/**
* Safely destroys redis connection
*
* @returns {Promise<void>}
*/
static destroy(): Promise<void>;
}