UNPKG

ucc-utils

Version:
59 lines (56 loc) 1.44 kB
import { RedisClientType, RedisClientOptions } from 'redis'; interface RedisOptions extends RedisClientOptions { host: string; port: number; } interface RedisToTryCatchResult<T = any> { status: boolean; result?: T; error?: Error | any; } declare class Redis { host: string; port: number; client: RedisClientType; constructor(opts: RedisOptions); /** * 初始化 */ _init(): void; /** * 设置键值对 * @param key 键,支持字符串和对象 * @param value 值,当 key 为字符串时,value 为值,当 key 为对象时,value 必须为空 */ set(key: string | { [key: string]: any; }, value?: any): Promise<RedisToTryCatchResult | RedisToTryCatchResult[] | undefined>; /** * 设置配置项 * @param opts 配置项 */ setOptions({ host, port }: RedisOptions): Redis; /** * 连接 */ connect(): Promise<RedisToTryCatchResult>; /** * 断开连接 */ disconnect(): Promise<RedisToTryCatchResult>; /** * 重新创建客户端实例 * @param opts 配置项 */ recreate(opts: RedisOptions): Redis; /** * 退出 */ quit(): Promise<RedisToTryCatchResult>; /** * 异常捕获 * @param fn 执行函数 */ _toTryCatch<T = any>(fn: Function, ...args: any[]): Promise<RedisToTryCatchResult<T>>; } export { Redis };