Giter Club home page Giter Club logo

redis_wrapper's Introduction

Redis Wrapper

This is a simple Promise based wrapper around some redis methods found in ioredis. Check lib/**/*.test.js files to see how each function works. I created this so that I can have a consistent api no matter what happens to any of the core engines I use for redis.

Initialize

const Redis = require('redis_wrapper')

const redis = new Redis(opts)

opts

See index.js Redis JSDOC params for all options.

Before you continue

All api is prefixed with r e.g set->rset, zadd->rzadd You can access the default redis client provided by io-redis using redis.client. You can use this in other places e.g. session middleware or to call methods that are not yet supported. Check io-redis for more details.

Makes use of ioredis library in the background.

Perks

Consistent return values e.g.

  • (a) What happens when I hmget using a hash_name that does not exist and keys a and b and c?
  • (b) What happens when I hmget using a hash_name that exists and keys a and b and c where a and b exists but not c?

In both these cases, this library api will always return an object of form:

Case (a) {a: null, b: null, c: null}

Case (b) {a: value, b: value, c: null}

Expiring hash fields

You can set an expiration on any hash field (not supported by normal redis api).

e.g.

redis.rhset({
  hash_name: 'hash_name',
  key_name : 'field_name',
  data     : 'data_string',
  max_life_seconds: 'seconds to last'
})

Expiring hash keys is not automatic You will need to call redis.removeExpiredHashKeys() to remove any hash keys that have expired. You can do this by attaching this to a setInterval function or even better, make this part of your background tasks/crons e.t.c. The consistency is accurate to this interval. You can call the function as many times as you like.

#Testing npm test

redis_wrapper's People

Stargazers

Jovin Mwilanga avatar

Watchers

James Cloos avatar Jovin Mwilanga avatar  avatar

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.