node-cache-redis
Version:
Simplistic node redis cache ready can scale with generic-pool support
128 lines (127 loc) • 4.33 kB
TypeScript
import { Options as PoolOptions } from 'generic-pool';
import { ClientOpts as RedisOptions } from 'redis';
import RedisPool from './RedisConnectionPool';
import { Logger } from './helpers';
/**
* RedisStore
*/
declare class RedisStore extends RedisPool {
defaultTtlInS: number | undefined;
deleteScriptPromise: Promise<any> | null;
/**
* @constructor
* @param options
* @param options.name - Name your store
* @param
* @param
* @param options.logger - Inject your custom logger
* @param options.defaultTtlInS - Number of seconds to store by default
*/
constructor({ name, redisOptions, poolOptions, logger, defaultTtlInS }: {
name?: string;
redisOptions: RedisOptions;
poolOptions?: PoolOptions;
logger?: Logger;
defaultTtlInS?: number;
});
/**
* Return the defaultTtlInS
* @returns defaultTtlInS
*/
getDefaultTtlInS(): number | undefined;
/**
* Sets the defaultTtlInS
* @param ttl
* @returns defaultTtlInS
*/
setDefaultTtlInS(ttl: number): number | undefined;
/**
* Unsets the defaultTtlInS
* @param ttl
* @returns true
*/
unsetDefaultTtlInS(): boolean;
/**
* Returns 'PONG'
*
* @param str - string passed
* @returns 'PONG'/string passed
*/
ping(str?: string): Promise<string>;
/**
* Returns value or null when the key is missing - See [redis get]{@link https://redis.io/commands/get}
* @async
* @param key - key for the value stored
* @returns value or null when the key is missing
*/
get(key: string): Promise<any>;
/**
* Returns 'OK' if successful
*
* @param key - key for the value stored
* @param value - value to stored
* @param ttlInSeconds - time to live in seconds
* @returns 'OK' if successful
*/
set(key: string, value: any, ttlInSeconds?: number): Promise<any>;
/**
* Returns 'OK' if successful
* @async
* @param key - key for the value stored
* @param value - value to stored
* @param ttlInSeconds - time to live in seconds
* @returns
*/
getset(key: string, value: any, ttlInSeconds: number | undefined): Promise<any>;
/**
* Returns the number of keys that were removed - See [redis del]{@link https://redis.io/commands/del}
*
* @param keys - list of keys to delete
* @returns The number of keys that were removed.
*/
del(keys?: string[]): Promise<number>;
/**
* Returns 1 if the timeout was set/ 0 if key does not exist or the timeout could not be set - See [redis expire]{@link https://redis.io/commands/expire}
*
* @param {string} key - key to set expire
* @param {number} ttlInSeconds - time to live in seconds
* @returns 1 if the timeout was set successfully; if not 0
*/
expire(key: string, ttlInSeconds: number): Promise<number>;
/**
* Returns TTL in seconds, or a negative value in order to signal an error - See [redis ttl]{@link https://redis.io/commands/ttl}
*
* @param key - list of keys to delete
* @returns TTL in seconds, or a negative value in order to signal an error
*/
getTtl(key: string): Promise<number>;
/**
* Returns all keys matching pattern - See [redis keys]{@link https://redis.io/commands/keys}
*
* @param pattern - glob-style patterns/default '*'
* @returns all keys matching pattern
*/
keys(pattern?: string): Promise<string[]>;
/**
* Deletes all keys matching pattern
*
* @param pattern - glob-style patterns/default '*'
* @returns The number of keys that were removed.
*/
deleteAll(pattern?: string): Promise<number>;
/**
* Preloads delete all scripts into redis script cache (this script requires redis >= 4.0.0)
* @returns sha1 hash of preloaded function
* @private
*/
_loadDeleteAllScript(): Promise<any> | null;
/**
* Preloads and execute delete all script
* @async
* @param pattern - glob-style patterns/default '*'
* @returns The number of keys that were removed.
* @private
*/
_executeDeleteAll(pattern: string): Promise<number>;
}
export default RedisStore;