underflag-redis
TypeScript icon, indicating that this package has built-in type declarations

1.3.0 • Public • Published

Redis Provider

This is a Redis provider for underflag (feature flag/feature toggle)

Install

Using npm:

npm install underflag underflag-redis

Using yarn:

yarn add underflag underflag-redis

How to use

Example using data from json, but you can get data from anywhere.

import { Underflag, JsonDataProvider } from "underflag";
import { RedisCacheProvider } from "underflag-redis";

const dataProvider = new JsonDataProvider({ 
    data: { feature: true }}
);
const cacheProvider = new RedisCacheProvider();
const underflag = new Underflag({ dataProvider, cacheProvider });
if (await underflag.isOn("feature")) {
    // ...
}

Prefix keys

Add a prefix to all keys, frequently used to group keys or isolate environment, a good example is when have only one database to multiple environment.

// ...
const cacheProvider = new RedisCacheProvider({
    prefix: 'staging:', // can be process.env.NODE_ENV + ':'
    lifetime: 300, // limit cache to 5min
});
// ...
/**
    Find feature staging:feature on redis
    if not found, find key feature on data and set staging:feature on redis to return later
*/
await underflag.isOn("feature"); 

Know more on underflag npm page

License

MIT

Package Sidebar

Install

npm i underflag-redis

Weekly Downloads

11

Version

1.3.0

License

MIT

Unpacked Size

8.8 kB

Total Files

12

Last publish

Collaborators

  • diego.souza