UNPKG

node-cache-redis

Version:

Simplistic node redis cache ready can scale with generic-pool support

111 lines (110 loc) 3.93 kB
import { Options as PoolOptions } from 'generic-pool'; import { ClientOpts as RedisOptions } from 'redis'; import RedisStore from './RedisStore'; import { Logger } from './helpers'; import { RedisPoolStatus } from './RedisConnectionPool'; /** * @param options * @param options.name - Name your cache store * @param options.redisOptions - opts from [node_redis#options-object-properties]{@link https://github.com/NodeRedis/node_redis#options-object-properties} * @param options.poolOptions - opts from [node-pool#createpool]{@link https://github.com/coopernurse/node-pool#createpool} * @param options.logger - Inject your custom logger * @param options.defaultTtlInS - Number of seconds to store by default */ export declare const init: (options: { /** Name your cache store */ name?: string | undefined; /** opts from [node_redis#options-object-properties]{@link https://github.com/NodeRedis/node_redis#options-object-properties} */ redisOptions: RedisOptions; /** opts from [node-pool#createpool]{@link https://github.com/coopernurse/node-pool#createpool} */ poolOptions?: PoolOptions | undefined; /** Inject your custom logger */ logger?: Logger | undefined; /** Number of seconds to store by default */ defaultTtlInS?: number | undefined; }) => void; /** * Returns cache store */ export declare const getStore: () => RedisStore; /** * Returns name of this pool */ export declare const getName: () => string; /** * Returns redisOptions of this pool */ export declare const getRedisOptions: () => RedisOptions; /** * Returns poolOptions of this pool */ export declare const getPoolOptions: () => PoolOptions; /** * Returns pool status and stats */ export declare const getStatus: () => RedisPoolStatus; /** * Return the defaultTtlInS */ export declare const getDefaultTtlInS: () => number | undefined; /** * Sets the defaultTtlInS * @param ttl - new default ttl in seconds */ export declare const setDefaultTtlInS: (ttl: number) => number | undefined; /** * Unsets the defaultTtlInS */ export declare const unsetDefaultTtlInS: () => boolean; /** * 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 */ export declare const set: (key: string, value: any, ttlInSeconds?: number | undefined) => Promise<string>; /** * 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 */ export declare const getset: (key: string, value: any, ttlInSeconds?: number | undefined) => Promise<any>; /** * Returns value or null when the key is missing * @param key - key for the value stored * @returns value or null when the key is missing */ export declare const get: (key: string) => Promise<any>; /** * Returns all keys matching pattern * @param pattern - glob-style patterns/default '*' * @returns all keys matching pattern */ export declare const keys: (pattern?: string) => Promise<string[]>; /** * Delete keys * @param keys - keys for the value stored * @returns The number of keys that were removed. */ export declare const del: (_keys?: string[]) => Promise<number>; /** * Deletes all keys matching pattern * @param pattern - glob-style patterns/default '*' * @returns The number of keys that were removed. */ export declare const deleteAll: (pattern?: string) => Promise<number>; /** * Wraps promise to set its value if not exists. * @async * @param key - key for the value stored * @param fn - function to call if not cache found * @param opts - options for wrap * @param opts.ttlInSeconds - time to live in seconds * @returns 'OK' if successful */ export declare const wrap: (key: string, fn: Function, opts?: { ttlInSeconds?: number; }) => Promise<any>;