github
DocsBlog
fontcolor_theme
package

API @deepkit/broker-redis

npm install @deepkit/broker-redis

Provides a Redis-based implementation of the Deepkit Broker. This uses ioredis under the hood.

This adapter does not implement the queue adapter of Deepkit Broker.

import { BrokerKeyValue, BrokerBus } from '@deepkit/broker';
import { BrokerRedisAdapter } from '@deepkit/broker-redis';
import { ConsoleLogger } from '@deepkit/logger';

const adapter = new RedisBrokerAdapter({
    preifx: 'myapp:',
    host: 'localhost',
    port: 6379,
    // password: 'your-password', // Optional, if your Redis server requires authentication
    // db: 0, // Optional, to specify a different Redis database
}, new ConsoleLogger());

const keyValye = new BrokerKeyValue(adapter);
const bus = new BrokerBus(adapter);
// ...

Classes

RedisBrokerAdapter [source]
export class RedisBrokerAdapter implements BrokerAdapterBus, BrokerAdapterKeyValue, BrokerAdapterCache, BrokerAdapterLock {
    constructor(private config: RedisBrokerAdapterOptions, public logger: Logger);
    async isLocked(id: string): Promise<boolean>;
    async lock(id: string, options: BrokerTimeOptionsResolved): Promise<Release | undefined>;
    async tryLock(id: string, options: BrokerTimeOptionsResolved): Promise<Release | undefined>;
    async disconnect(): Promise<void>;
    async publish(name: string, message: any, type: Type): Promise<void>;
    async subscribe(name: string, callback: (message: any) => void, type: Type): Promise<Release>;
    async get(key: string, type: Type): Promise<any>;
    async increment(key: string, value: number): Promise<number>;
    async remove(key: string): Promise<any>;
    async set(key: string, value: any, options: BrokerKeyValueOptionsResolved, type: Type): Promise<any>;
    async getCache(key: string, type: Type): Promise<{
        value: any;
        ttl: number;
    } | undefined>;
    async setCache(key: string, value: any, options: BrokerCacheItemOptionsResolved, type: Type): Promise<void>;
    async getCacheMeta(key: string): Promise<{
        ttl: number;
    } | undefined>;
    async invalidateCache(key: string): Promise<void>;
    onInvalidateCache(callback: (key: string) => void): void;
}

Types

RedisBrokerAdapterOptions [source]
type RedisBrokerAdapterOptions = RedisOptions & {
    prefix?: string; // optional prefix for all keys
}