Giter VIP home page Giter VIP logo

redis-simple-connect's Introduction

redis-simple-connect

(ANOTHER) simple Node.js module to connect and send commands to Redis using promises with configurable environment variables, build on top of Node Redis.

Features

  • Connect easily to Redis using promises and async/await
  • Use environment variables or an options object to set connection parameters
  • Call async commands like GET and SET using getAsync and setAsync methods

How to use

$ npm i -s redis-simple-connect
const connectRedis = require('redis-simple-connect');

const client = await connectRedis();

Reference

Connecting to Redis

When calling the main exported method from module, you may use environment variables or an options object.

The method returns a RedisClient object from Node Redis, so you can call this class methods and commands.

With environment variables

const client = await connectRedis();

This way the module will try to obtain the main connection parameters (host, port, password and database number) from the following variables: REDIS_HOST, REDIS_PORT, REDIS_PASSWORD and REDIS_DB.

  • Note that port, password and database number are not required options.

If you want to add a prefix to the variables, you may use the envPrefix parameter:

const client = await connectRedis(_, 'MYAPP_');

// This way the method will look for `MYAPP_REDIS_HOST`, `MYAPP_REDIS_PORT`, etc.

With an options object

const client = await connectRedis({
  host: 'redis.domain.com',
  port: 8654,
  db: 7,
  password: 'abd132be1323115bd51afbfaba'
});

getAsync and setAsync

This module injects two methods to the RedisClient class: getAsync and setAsync.

Both are promisifed versions of the respective methods get and set.

const value = await client.getAsync('key');

await client.setAsync('key', value);

redis-simple-connect's People

Contributors

ggondim avatar

Watchers

 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.