Coder Social home page Coder Social logo

redis-wrapper's Introduction

Redis wrapper

Redis wrapper using bluebird promises. It is extendable by modules.

Requirements

Redis server should be running and a client should be already created.

Usage

npm i @sentisis/redis-wrapper
const redis = require('redis');
const Promise = require('bluebird');

const redisWrapper = require('@sentisis/redis-wrapper');
// enable promises for redis https://github.com/NodeRedis/node_redis#promises
Promise.promisifyAll(redis.RedisClient.prototype);
Promise.promisifyAll(redis.Multi.prototype);

const client = redis.createClient();
const key = 'a';
const value = 'b';
client.set(key, value);

redisWrapper.getter(client, key)
.then((res) => {
  // res = { value: 'b'}
});

Current Modules

All Module operations are atomic, using transactions when needed.

[Keys] COUNTER

Increments a given key, for a INCR_BY parameter (or 1 if not defined)

Params:

  • client: created redis client.
  • data: {'key': <key>, 'incr_by': <value>}, 'ttl': <ttl>}

Where:

  • key: must be defined
  • ttl: if not supplied, the key is persisted forever
  • incr_by [optional]: If it is not defined, it defaults to 1 (so it sums 1 to the current value, or puts 1 if the key does not exist)

Sample response:

{'new_value': <new_value>}

Where:

  • new_value: is the actual value AFTER being updated

[Keys] GETTER

Gets the value of a given key.

Params:

  • client: created redis client.
  • key

Where:

  • key: must be defined

Response:

{'value':<value>}

Where:

  • value is an empty string ('' if the key does not exist) or the value

[Keys] REMEMBER

Remembers a given key, for a specified ttl and value into redis

Params:

  • client: created redis client.
  • data: {'key': <key>, 'ttl': <ttl>, 'value': <value>}

Where:

  • ttl [optional]: Time to leave (expiration from now in seconds). If the value is not given, 0 or -1, it does persist forever.
  • value [optional]: Value for the key. If not given, it is set to true.

Response

{'new': <true|false>}

That indicates if the just inserted key is new to the system or not.

[Keys] REMOVE

Deletes a given key.

Params:

  • client: created redis client.
  • key

Where:

  • key: must be defined

Response:

{'deleted':<true|false>}

Where:

  • deleted is true if the key has been deleted, false otherwise (the key did not exist).

HEALTHCHECKER

Checks if the system is running correctly, or not.

Params:

  • client: created redis client.

Response:

{'status': 'ok'}

FLUSHER

Flush the DB.

Params:

  • client: created redis client.

Where:

  • client: must be a redis client.

Response:

{'flushed': <true|false>}

redis-wrapper's People

Contributors

milingo avatar popigg avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

milingo

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.