@soluble/cache-redis
TypeScript icon, indicating that this package has built-in type declarations

0.12.11 • Public • Published

Codecov Downloads Codecov Codefactor CodeClimate TechDebt Typings Licence

About | Documentation

Cache adapter for node redis client.

Install

$ yarn add @soluble/cache-redis redis
$ yarn add @types/redis --dev

Usage

import { RedisCacheAdapter } from "@soluble/cache-redis";

const cache = new RedisCacheAdapter({
  connection: "redis://:pass@localhost:6379/8",
});

const { data, error } = await cache.getOrSet("key", asyncPromise, {
  ttl: 30,
});

if (await cache.has("key")) {
  await cache.delete("key");
}

Constructor

Connection

RedisAdapter connection param can be a DSN, a RedisConnection, the native ClientOpts or an existing RedisClient connection.

You can use the getRedisOptionsFromDsn function to initiate a connection with native parameters.

import {
  RedisCacheAdapter,
  getRedisOptionsFromDsn,
} from "@soluble/cache-redis";

const dsn = "redis://localhost:6379/db2";

const cache = new RedisCacheAdapter({
  connection: getRedisOptionsFromDsn(dsn, {
    // here all node-redis client options
    enable_offline_queue: false,
  }),
});

Sponsors ❤️

If you are enjoying some of my OSS guides or libs for your company, I'd really appreciate a sponsorship, a coffee or a dropped star. That gives me a tasty morning boost and help me to make some of my ideas come true 🙏

Special thanks

Jetbrains logo Jetbrains logo
JetBrains Embie.be

Package Sidebar

Install

npm i @soluble/cache-redis

Weekly Downloads

4

Version

0.12.11

License

MIT

Unpacked Size

58.6 kB

Total Files

9

Last publish

Collaborators

  • s.vanvelthem