npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@rnw-community/nestjs-rxjs-redis

v3.0.5

Published

NestJS RxJS redis

Readme

NestJS RxJS Redis

NestJS redis wrapper for using with RxJS streams.

npm version coverage npm downloads

NestJSRxJSRedisModule

Global NestJS module that registers the redis connection (via @nestjs-modules/ioredis) and provides NestJSRxJSRedisService. Register it once with forRootAsync, which accepts the RedisModuleAsyncOptions of @nestjs-modules/ioredis (useFactory / useClass / useExisting, inject, imports):

import { Module } from '@nestjs/common';

import { NestJSRxJSRedisModule } from '@rnw-community/nestjs-rxjs-redis';

@Module({
    imports: [
        NestJSRxJSRedisModule.forRootAsync({
            useFactory: () => ({ type: 'single', url: 'redis://localhost:6379' }),
        }),
    ],
})
export class AppModule {}

NestJSRxJSRedisService

Injectable service exposing redis commands as RxJS observables and pipeable operators. Every command maps a redis failure to an Error carrying the optional custom message argument:

import { Injectable } from '@nestjs/common';

import { NestJSRxJSRedisService } from '@rnw-community/nestjs-rxjs-redis';

@Injectable()
export class MyService {
    constructor(private readonly redis: NestJSRxJSRedisService) {}
}

Basic operations

  • set$(key, value, ttlInSeconds, error?) - sets a string value with an expiry, emits true
  • get$(key, error?) - emits the stored string, errors when the key is missing
  • del$(key, error?) - deletes a key, emits the number of removed keys
  • ttl$(key, error?) - emits the remaining time to live of a key in seconds
  • expire$(key, seconds, error?) - sets a timeout on a key, emits 1 when set and 0 otherwise
  • incr$(key, error?) - increments a numeric key, emits the new value
  • mget$(keys) - emits a record mapping every requested key to its value (or null)
import { Injectable } from '@nestjs/common';

import { NestJSRxJSRedisService } from '@rnw-community/nestjs-rxjs-redis';

import type { Observable } from 'rxjs';

@Injectable()
export class MyService {
    constructor(private readonly redis: NestJSRxJSRedisService) {}

    setExample$(): Observable<boolean> {
        return this.redis.set$('my-redis-key', 'value', 60, 'Cannot save value');
    }

    getExample$(): Observable<string> {
        return this.redis.get$('my-redis-key', 'Cannot get key');
    }

    delExample$(): Observable<number> {
        return this.redis.del$('my-redis-key', 'Cannot delete key');
    }

    ttlExample$(): Observable<number> {
        return this.redis.ttl$('my-redis-key', 'Cannot get key ttl');
    }

    expireExample$(): Observable<number> {
        return this.redis.expire$('my-redis-key', 120, 'Cannot set key timeout');
    }

    incrExample$(): Observable<number> {
        return this.redis.incr$('my-redis-counter', 'Cannot increment counter');
    }

    multipleGetExample$(): Observable<Record<'my-redis-key-1' | 'my-redis-key-2', string | null>> {
        return this.redis.mget$(['my-redis-key-1', 'my-redis-key-2']);
    }
}

save

save(keyFn, ttlInSeconds, errorFn?, toValueFn?) receives a value from the RxJS stream, passes it to keyFn to generate a data-related redis key, converts the data to a string using toValueFn (JSON.stringify by default), saves it to redis and re-emits the original value.

export class MyService {
    saveExample$(): Observable<number> {
        return of(9999).pipe(
            this.redis.save(
                data => `redis-key-${data}`,
                60,
                data => `Cannot save ${data} to redis`
            )
        );
    }
}

load

load(keyFn?, errorFn?, fromValueFn?) receives a key from the RxJS stream, passes it to keyFn to generate the redis key, retrieves the value from redis and converts it using fromValueFn (JSON.parse by default).

export class MyService {
    loadExample$(): Observable<MyType> {
        return of('my-redis-key').pipe(
            this.redis.load<MyType>(
                key => `${key}-modified`,
                key => `Cannot load ${key} from redis`
            )
        );
    }
}

remove

remove(keyFn?, errorFn?) receives a key from the RxJS stream, passes it to keyFn to generate the redis key, deletes that key in redis and re-emits the original value.

export class MyService {
    removeExample$(): Observable<string> {
        return of('my-redis-key').pipe(
            this.redis.remove(
                key => `${key}-modified`,
                key => `Cannot remove ${key} from redis`
            )
        );
    }
}

cache

cache(ttlInSeconds, prepareFn$, keyFn?, fromValueFn?, toValueFn?) loads data from redis by the key produced by keyFn; if it is not available, executes prepareFn$ with that key, saves the returned data to redis for ttlInSeconds and emits it.

export class MyService {
    cacheExample$(): Observable<MyType> {
        return of('my-redis-key').pipe(
            this.redis.cache<MyType>(
                60,
                key => this.repository.findByKey$(key),
                input => `${input}-modified`
            )
        );
    }
}

License

This library is licensed under The MIT License.