UNPKG

mwoffliner

Version:
40 lines (39 loc) 1.79 kB
import type { RedisClientType } from 'redis'; export default class RedisKvs<T> implements RKVS<T> { private redisClient; private readonly dbName; private readonly dehydratedKeys?; private readonly hydratedKeys?; constructor(redisClient: RedisClientType, dbName: string, keyMapping?: KVS<string>); get(prop: string): Promise<T>; getMany(prop: string[]): Promise<KVS<T>>; exists(prop: string): Promise<boolean>; existsMany(prop: string[], blocking?: boolean): Promise<KVS<boolean>>; set(prop: string, val: T): Promise<number>; setMany(val: KVS<T>): Promise<number>; delete(prop: string): Promise<number>; deleteMany(prop: string[]): Promise<number>; keys(): Promise<string[]>; len(): Promise<number>; /** * Iteratively call function passed with batches of items from the underlying KVS hash, with a given number of workers * working in parallel. * * This function scans the underlying KVS hash for items to batch. Batch size is "around" 10 items (Redis does * not garantee exact batch size for SCAN operation). For every batch retrieved, passed "func" is called with the * "items" retrieved. * * "numWorkers" are started in parallel, each processing a batch of items. Number of "runningWorkers" is passed to * "func" called, mostly useful for logging / debugging purposes. * * This function returns when all items have been batched and passed to processing function. */ iterateItems(numWorkers: number, func: (items: KVS<T>, runningWorkers: number) => Promise<void>): Promise<void>; scan(scanCursor: number): Promise<{ cursor: number; items: KVS<T>; }>; flush(): Promise<number>; private hydrateObject; private dehydrateObject; }